lisonge / vite-plugin-monkey

A vite plugin server and build your.user.js for userscript engine like Tampermonkey, Violentmonkey, Greasemonkey, ScriptCat
MIT License
1.33k stars 70 forks source link

conflict to vue with vue-router when building #4

Closed bzy-nya closed 2 years ago

bzy-nya commented 2 years ago
~/project/luogu/luogu-ex-backstage $ vite build
vite v2.9.13 building for production...
✓ 26 modules transformed.
Invalid value "iife" for option "output.format" - UMD and IIFE output formats are not supported for code-splitting builds.
error during build:
Error: Invalid value "iife" for option "output.format" - UMD and IIFE output formats are not supported for code-splitting builds.
    at error (/usr/local/lib/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:198:30)
    at validateOptionsForMultiChunkOutput (/usr/local/lib/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:16265:16)
    at Bundle.generate (/usr/local/lib/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:16099:17)
    at async /usr/local/lib/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:23732:27
    at async catchUnfinishedHookActions (/usr/local/lib/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:23174:20)
    at async doBuild (/usr/local/lib/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:41696:26)
    at async build (/usr/local/lib/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:41527:16)
    at async CAC.<anonymous> (/usr/local/lib/node_modules/vite/dist/node/cli.js:738:9)
lisonge commented 2 years ago

ok, I have a look

lisonge commented 2 years ago

@bzy-nya hello, can you show your code by https://stackblitz.com/ or other way?

lisonge commented 2 years ago

ok, I see,

UMD and IIFE output formats are not supported for code-splitting builds

your final code just one file named xxx.user.js, code-splitting builds is not working

so you can not use Dynamic import in your code

bzy-nya commented 2 years ago

ok, I see,

UMD and IIFE output formats are not supported for code-splitting builds

your final code just one file named xxx.user.js, code-splitting builds is not working

so you can not use Dynamic import in your code

ok, fixed, thank you.

lisonge commented 2 years ago

just use

import AppVue from '@/App.vue'
createRouter({
    history:createMemoryHistory('./'),
    routes:[
        {
            path: '/app',
            name: 'App',
            component: AppVue,
        },
    ]
})

instead of

createRouter({
    history:createMemoryHistory('./'),
    routes:[
        {
            path: '/app',
            name: 'App',
            component: () => import('@/App.vue'),
        },
    ]
})