我有一个带有 Webpack 的 Vue2 项目,我正在尝试从 Webpack 切换到 Vite。
In webpack.common.js
,我有多个入口点:
module.exports = {
entry: {
appSchool: './resources/school/app.js',
appStudent: './resources/student/app.js',
appAuth: './resources/auth/app.js'
},
...
}
我该如何写这个vite.config.js
?
Vite 在底层使用 Rollup,您可以通过以下方式配置 Rollupbuild.rollupOptions https://vitejs.dev/config/#build-rollupoptions, 进而汇总的input option https://rollupjs.org/guide/en/#input:
// vite.config.js
import { fileURLToPath } from 'url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
build: {
rollupOptions: {
input: {
appSchoool: fileURLToPath(new URL('./resources/school/index.html', import.meta.url)),
appStudent: fileURLToPath(new URL('./resources/student/index.html', import.meta.url)),
appAuth: fileURLToPath(new URL('./resources/auth/index.html', import.meta.url)),
},
},
},
})
请注意入口点参考index.html
文件,它们本身链接到app.js
在其相应的目录中(例如,./resources/student/index.html
包含<script src="./app.js">
). The input
配置还接受app.js
直接文件,但不会生成 HTML。
demo https://stackblitz.com/edit/vue3-vite-multiple-entry-points?file=vite.config.js
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)