我有一個帶有 Webpack 的 Vue2 專案,我正在嘗試從 Webpack 切換到 Vite。
在 中webpack.common.js,我有多個入口點:
module.exports = {
entry: {
appSchool: './resources/school/app.js',
appStudent: './resources/student/app.js',
appAuth: './resources/auth/app.js'
},
...
}
我怎么寫這個vite.config.js?
uj5u.com熱心網友回復:
Vite 在幕后使用 Rollup,你可以通過配置 Rollup build.rollupOptions,然后使用Rollup 的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.htmlcontains <script src="./app.js">)。該input配置還接受app.js直接檔案,但將不會產生HTML。
演示
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/397811.html
上一篇:按id洗掉打字稿表
