Skip to content

Commit 7fc6e4e

Browse files
build: modify config to reduce size
1 parent 7446ea7 commit 7fc6e4e

File tree

2 files changed

+10
-33
lines changed

2 files changed

+10
-33
lines changed

src/utils/plugins/bundle-worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function vitePluginBundleWorker(): Plugin {
3434
} = result;
3535

3636
// Emit the bundled worker as an asset in the "assets/" folder
37-
const fileName = `assets/${basename(workerPath)}`;
37+
const fileName = `src/vendor/${basename(workerPath)}`;
3838
const url = this.emitFile({
3939
fileName,
4040
source: bundledCode,

vite.config.ts

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import react from "@vitejs/plugin-react-swc";
22
import { config } from "dotenv";
3-
import path, { resolve } from "path";
3+
import { resolve } from "path";
44
import { defineConfig } from "vite";
55

66
import checkLocalesForMissingKeys from "./src/utils/checkLocalesForMissingKeys";
@@ -37,37 +37,14 @@ export default function build() {
3737
popup: resolve(pagesDir, "popup", "index.html")
3838
},
3939
output: {
40-
assetFileNames: (chunk) => {
41-
return `assets/${chunk.name}`;
42-
},
43-
chunkFileNames: (chunk) => {
44-
return `assets/${chunk.name}.js`;
45-
},
46-
entryFileNames: (chunk) => {
47-
return `src/pages/${chunk.name}/index.js`;
48-
},
40+
assetFileNames: (chunk) => `src/${chunk.name}`,
41+
chunkFileNames: (chunk) => `src/${chunk.name}.js`,
42+
entryFileNames: (chunk) => `src/pages/${chunk.name}/index.js`,
4943
manualChunks: (id) => {
50-
if (id.includes("node_modules/monaco-editor")) {
51-
const parts = id.split(path.posix.sep || path.sep);
52-
const vsIndex = parts.findIndex((part) => part === "vs");
53-
if (vsIndex >= 0 && parts.length > vsIndex + 1) {
54-
const { [vsIndex + 2]: folder } = parts;
55-
switch (folder) {
56-
case "browser":
57-
return "monaco-editor-browser";
58-
case "common":
59-
return "monaco-editor-common";
60-
case "contrib":
61-
return "monaco-editor-contrib";
62-
case "standalone":
63-
return "monaco-editor-standalone";
64-
default:
65-
return "monaco-editor-other";
66-
}
67-
}
68-
return "monaco-editor-other";
44+
if (id.includes("node_modules")) {
45+
const [module] = id.split("node_modules/")[1].split("/");
46+
return `vendor/${module.split("/")[0]}`;
6947
}
70-
if (id.includes("node_modules")) return "vendor";
7148
}
7249
},
7350
treeshake: {
@@ -81,8 +58,8 @@ export default function build() {
8158
},
8259
esbuild: {
8360
keepNames: true,
84-
minifyIdentifiers: false,
85-
minifySyntax: false,
61+
minifyIdentifiers: true,
62+
minifySyntax: true,
8663
minifyWhitespace: true
8764
},
8865
plugins: [replaceDevModeConst(), bundleWorker(), react(), makeManifest(), buildContentScript(), copyPublic(), copyBuild(), makeReleaseZips()],

0 commit comments

Comments
 (0)