diff --git a/tdm-fe/package-lock.json b/tdm-fe/package-lock.json index 081248c..64a2c54 100644 --- a/tdm-fe/package-lock.json +++ b/tdm-fe/package-lock.json @@ -33,6 +33,7 @@ "@vitejs/plugin-react": "^4.2.1", "eslint": "^8.57.0", "md5": "^2.3.0", + "rollup-plugin-gzip": "^3.1.2", "sass": "^1.75.0", "stylelint": "^16.3.1", "stylelint-config-standard-scss": "^13.1.0", @@ -6161,6 +6162,18 @@ "fsevents": "~2.3.2" } }, + "node_modules/rollup-plugin-gzip": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/rollup-plugin-gzip/-/rollup-plugin-gzip-3.1.2.tgz", + "integrity": "sha512-9xemMyvCjkklgNpu6jCYqQAbvCLJzA2nilkiOGzFuXTUX3cXEFMwIhsIBRF7kTKD/SnZ1tNPcxFm4m4zJ3VfNQ==", + "dev": true, + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "rollup": ">=2.0.0" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", diff --git a/tdm-fe/package.json b/tdm-fe/package.json index c9f4442..4fe63e6 100644 --- a/tdm-fe/package.json +++ b/tdm-fe/package.json @@ -42,6 +42,7 @@ "@vitejs/plugin-react": "^4.2.1", "eslint": "^8.57.0", "md5": "^2.3.0", + "rollup-plugin-gzip": "^3.1.2", "sass": "^1.75.0", "stylelint": "^16.3.1", "stylelint-config-standard-scss": "^13.1.0", diff --git a/tdm-fe/vite.config.ts b/tdm-fe/vite.config.ts index ab16373..0c8d3c5 100644 --- a/tdm-fe/vite.config.ts +++ b/tdm-fe/vite.config.ts @@ -1,11 +1,17 @@ import react from '@vitejs/plugin-react'; import md5 from 'md5'; +import gzipPlugin from 'rollup-plugin-gzip'; import { defineConfig } from 'vite'; import eslint from 'vite-plugin-eslint'; import stylelint from 'vite-plugin-stylelint'; import tsconfigPaths from 'vite-tsconfig-paths'; -const regex = /(.*node_modules\/)([^\/]+)(.*)/; +import { promisify } from 'node:util'; +import { brotliCompress } from 'node:zlib'; + +const brotliPromise = promisify(brotliCompress); + +const regex = /(.*node_modules\/)([^/]+)(.*)/; const linter = process.env.VITE_ENV === 'prod' @@ -18,12 +24,27 @@ const linter = ]; export default defineConfig({ - plugins: [react(), tsconfigPaths(), ...linter], - css: { - devSourcemap: process.env.VITE_SOURCE_MAP === 'true', - }, + plugins: [ + react(), + tsconfigPaths(), + gzipPlugin({ + customCompression: (content) => brotliPromise(Buffer.from(content)), + fileName: '.br', + minSize: 1000, + gzipOptions: { + level: 9, + }, + }), + gzipPlugin({ + minSize: 1000, + gzipOptions: { + level: 9, + }, + }), + ...linter, + ], build: { - sourcemap: process.env.VITE_SOURCE_MAP === 'true', + sourcemap: true, rollupOptions: { output: { manualChunks: (id, meta) => { @@ -36,13 +57,13 @@ export default defineConfig({ }, minify: 'terser', terserOptions: { - sourceMap: process.env.VITE_SOURCE_MAP === 'true', - ecma: 2018, + sourceMap: true, + ecma: 2020, compress: { - ecma: 2018, + ecma: 2020, }, format: { - ecma: 2018, + ecma: 2020, }, }, },