From 2c24b17aefc7e7f452b77847ff542dad7dfc416c Mon Sep 17 00:00:00 2001 From: Kseninia Mikhaylova Date: Fri, 21 Jun 2024 15:58:41 +0300 Subject: [PATCH] test imagemin --- Dockerfile | 1 + nuxt.config.ts | 52 +++++++++++++++++++++++++------------------------- package.json | 2 ++ 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index e26a1bc..a451a89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM debian:bookworm-slim RUN apt update RUN apt -y install nodejs npm +RUN apt -y install libpng-dev libimagequant-dev RUN mkdir -p /src COPY package.json src/package.json diff --git a/nuxt.config.ts b/nuxt.config.ts index 5eecd95..e6824eb 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -6,32 +6,32 @@ import imageminPngquant from 'imagemin-pngquant'; export default defineNuxtConfig({ hooks: { - // 'nitro:build:public-assets': async (nitro) => { - // console.log(`😈 custom hook imagemin in ${nitro.options.output.publicDir}`) - // const output_path = nitro.options.output.publicDir - // const filelist = await fs.readdir(output_path, { recursive: true }); - // for (let index = 0; index < filelist.length; index++) { - // const element = filelist[index]; - // const elementFile = await fs.lstat(`${output_path}/${element}`) - // if (element.startsWith('_nuxt')) continue - // if (elementFile.isFile()) { - // if (element.endsWith('.png')) { - // const dest = `${output_path}/${element.split('/').slice(0, -1).join('/')}` - // const res = await imagemin([`${output_path}/${element}`], { - // destination: dest, - // plugins: [ - // imageminPngquant({ - // quality: [0.6, 0.8] - // }) - // ] - // }) - // if (res.length) { - // console.log(chalk.gray(` compress PNG ${output_path}/${element}`)) - // } - // } - // } - // } - // } + 'nitro:build:public-assets': async (nitro) => { + console.log(`😈 custom hook imagemin in ${nitro.options.output.publicDir}`) + const output_path = nitro.options.output.publicDir + const filelist = await fs.readdir(output_path, { recursive: true }); + for (let index = 0; index < filelist.length; index++) { + const element = filelist[index]; + const elementFile = await fs.lstat(`${output_path}/${element}`) + if (element.startsWith('_nuxt')) continue + if (elementFile.isFile()) { + if (element.endsWith('.png')) { + const dest = `${output_path}/${element.split('/').slice(0, -1).join('/')}` + const res = await imagemin([`${output_path}/${element}`], { + destination: dest, + plugins: [ + imageminPngquant({ + quality: [0.6, 0.8] + }) + ] + }) + if (res.length) { + console.log(chalk.gray(` compress PNG ${output_path}/${element}`)) + } + } + } + } + } }, app: { pageTransition: { name: 'page', mode: 'out-in' }, diff --git a/package.json b/package.json index 274fcb7..b2feb83 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,8 @@ "@tresjs/cientos": "^3.9.0", "@tresjs/core": "^4.0.2", "@tresjs/nuxt": "^2.1.2", + "imagemin": "^9.0.0", + "imagemin-pngquant": "^10.0.0", "marked": "^12.0.2", "nuxt": "^3.11.2", "nuxt-anchorscroll": "^1.0.3",