Vue3+Vite,build配置的问题
本帖最后由 cqwcns 于 2023-11-28 09:54 编辑Vue3+Vite,vite.config.js内容为:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { CRX_OUTDIR } from './viteBuildGlobalConfig'
export default defineConfig({
base: './',
plugins: ,
build: {
rollupOptions: {
input: {
popup: resolve(__dirname, `src/popup/popup.html`)
},
output: {
dir: 'dist',
assetFileNames: '/.',
chunkFileNames: 'js/.js',
entryFileNames: e => `${e.name}/.js`
}
}
}})
build后,css和js的输出路径为dist/popup,但popup.html的输出路径为dist/src/pupup
我希望html的输出路径也是dist/popup,应该怎么写? assetFileNames: 'popup/.',
试一下 yushuai033X 发表于 2023-12-1 09:40
assetFileNames: 'popup/.',
试一下
测速过,assetFileNames配置只能改变css文件的输出路径,无法改变html的。 那试一下插件
import { Plugin } from 'vite'
export function changeHtmlOutputPath(): Plugin {
return {
name: 'change-html-output-path',
transformIndexHtml(html) {
return html.replace('dist/', 'dist/popup/')
}
}
}
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { CRX_OUTDIR } from './viteBuildGlobalConfig'
import { changeHtmlOutputPath } from './changeHtmlOutputPath'
export default defineConfig({
base: './',
plugins: ,
build: {
rollupOptions: {
input: {
popup: resolve(__dirname, `src/popup/popup.html`)
},
output: {
dir: 'dist',
assetFileNames: '/.',
chunkFileNames: 'js/.js',
entryFileNames: e => `${e.name}/.js`
}
}
}
})
页:
[1]