有没有可能从vite构建中排除一个完整的(延迟加载的)文件夹?如果有,怎么做?
import { defineConfig } from 'vite'
import { resolve as resolver } from 'path'
import vue from '@vitejs/plugin-vue'
import ViteComponents from 'vite-plugin-components'
const resolve = {
alias: {
'vue': 'vue/dist/vue.esm-bundler.js',
'@': resolver(__dirname, './src')
}
}
const plugins = [
vue(),
ViteComponents({
dirs: ['src/shared/components'],
extensions: ['vue'],
deep: true,
})
]
const build = {
outDir: 'dist',
assetsDir: 'assets',
assetsInlineLimit: '4096',
cssCodeSplit: false, // single CSS
sourcemap: false,
manifest: false,
chunkSizeWarningLimit: 1000,
}
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
if (command === 'serve') {
return {
// serve specific config
plugins,
resolve,
}
} else {
return {
// build specific config
plugins,
resolve,
build
}
}
})
npm run build
正在构建我的示例。但是我不需要它们。
...
dist/assets/ExampleListGroup.58bffc95.js 0.70 KiB / gzip: 0.43 KiB
dist/assets/ExampleMainTitle.4841825d.js 0.66 KiB / gzip: 0.39 KiB
dist/assets/ExampleMarkdownEditor.05ed02a3.js 0.67 KiB / gzip: 0.39 KiB
dist/assets/ExampleMenuStructure.36b10505.js 0.68 KiB / gzip: 0.41 KiB
dist/assets/ExampleMarkDown.ef4418d4.js 0.68 KiB / gzip: 0.40 KiB
dist/assets/ExamplePopupMenu.9c9d49e2.js 0.60 KiB / gzip: 0.38 KiB
dist/assets/ExampleObjectSelect.bc2a5189.js 4.86 KiB / gzip: 1.36 KiB
...
我希望在构建之前排除它们,而不是在构建之后删除它们。
谢谢。
2条答案
按热度按时间kq0g1dla1#
最后创建了2个路由器
router.js
和router-dev.js
以及包含其中一个路由器的别名vite.config.js
:main.js
:huwehgph2#
我也遇到过类似的问题。我检查了一下环境,然后用惰性导入来解决它。类似下面这样的方法对你来说也是可行的: