11import { fileURLToPath , URL } from 'node:url' ;
22import { nodePolyfills } from 'vite-plugin-node-polyfills' ;
3- import { defineConfig } from 'vite' ;
3+ import { visualizer } from 'rollup-plugin-visualizer' ;
4+ import { defineConfig , type PluginOption } from 'vite' ;
45import vue from '@vitejs/plugin-vue' ;
56import { crx } from '@crxjs/vite-plugin' ;
67import chromeManifest from './src/manifest/manifest.chrome' ;
@@ -12,7 +13,13 @@ import transformCSInject from './configs/vite/transform-cs-inject';
1213import { version } from './package.json' ;
1314
1415const BROWSER = process . env . BROWSER ;
15-
16+ const firefoxChunking = ( id : string ) => {
17+ if ( id . includes ( 'node_modules' ) ) {
18+ const chunkName = id . match ( / n o d e _ m o d u l e s \/ ( .+ ?) \/ / ) ;
19+ if ( chunkName && chunkName . length > 1 ) return chunkName [ 1 ] . replace ( '@' , '' ) ;
20+ return 'vendor' ;
21+ }
22+ } ;
1623const getManifest = ( ) => {
1724 switch ( BROWSER ) {
1825 case 'firefox' :
@@ -49,6 +56,7 @@ export default defineConfig({
4956 : new Date ( ) . toLocaleString ( ) . replace ( / \D / g, '' ) ,
5057 } ,
5158 plugins : [
59+ visualizer ( ) as PluginOption ,
5260 nodePolyfills ( {
5361 include : [
5462 'crypto' ,
@@ -95,6 +103,9 @@ export default defineConfig({
95103 onboard : 'onboard.html' ,
96104 index : 'index.html' ,
97105 } ,
106+ output : {
107+ manualChunks : BROWSER === 'firefox' ? firefoxChunking : undefined ,
108+ } ,
98109 } ,
99110 } ,
100111 optimizeDeps : {
0 commit comments