Skip to content

Commit

Permalink
feat: add gzip and brotli to create static files
Browse files Browse the repository at this point in the history
  • Loading branch information
AlasDiablo committed May 30, 2024
1 parent 00dc126 commit 96ebcc6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
13 changes: 13 additions & 0 deletions tdm-fe/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tdm-fe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 31 additions & 10 deletions tdm-fe/vite.config.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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) => {
Expand All @@ -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,
},
},
},
Expand Down

0 comments on commit 96ebcc6

Please sign in to comment.