File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,23 @@ const nodeModulesPolyfillPlugin = nodeModulesPolyfillPluginCjs.default
1313const __filename = fileURLToPath ( import . meta. url )
1414const __dirname = path . dirname ( __filename )
1515
16+ const addViteIgnorePlugin = ( ) => {
17+ return {
18+ name : 'add-vite-ignore' ,
19+ transform ( code , id ) {
20+ const regexp = / n e w U R L \( " d a t a : t e x t \/ j a v a s c r i p t ; b a s e 6 4 , / g
21+ // 往 new URL 后面添加 /* @vite-ignore */,避免 vite 打包时,输出超长的 base64 字符串
22+ if ( id . endsWith ( '.js' ) && regexp . test ( code ) ) {
23+ const modified = code . replace ( regexp , 'new URL(/* @vite-ignore */"data:text/javascript;base64,' )
24+ return {
25+ code : modified ,
26+ map : null
27+ }
28+ }
29+ }
30+ }
31+ }
32+
1633export default defineConfig ( {
1734 plugins : [ vue ( ) , vueJsx ( ) ] ,
1835 publicDir : false ,
@@ -54,7 +71,7 @@ export default defineConfig({
5471 formats : [ 'es' ]
5572 } ,
5673 rollupOptions : {
57- plugins : [ nodePolyfill ( { include : null } ) ] ,
74+ plugins : [ nodePolyfill ( { include : null } ) , addViteIgnorePlugin ( ) ] ,
5875 output : {
5976 banner : ( chunk ) => {
6077 if ( chunk . name === 'index' ) {
You can’t perform that action at this time.
0 commit comments