const config = { base: './', // index.html文件所在位置 root: './', // js导入的资源路径,src resolve: { alias, }, define: { 'process.env': {} }, server: { // 如果使用docker-compose开发模式,设置为false open: true, port: process.env.VITE_CLI_PORT, proxy: { // 把key的路径代理到target位置 // detail: https://cli.vuejs.org/config/#devserver-proxy [process.env.VITE_BASE_API]: { // 需要代理的路径 例如 '/api' target: `${process.env.VITE_BASE_PATH}/`, // 代理到 目标路径 changeOrigin: true, rewrite: path => path.replace(new RegExp('^' + process.env.VITE_BASE_API), ''), }, [process.env.VITE_BASE_EXPORT_API]: { // 需要代理的路径 例如 '/api' target: `${process.env.VITE_BASE_REPORTAPI}/`, // 代理到 目标路径 changeOrigin: true, rewrite: path => path.replace(new RegExp('^' + process.env.VITE_BASE_EXPORT_API), ''), }, }, }, build: { target: 'es2017', minify: 'terser', // 是否进行压缩,boolean | 'terser' | 'esbuild',默认使用terser manifest: false, // 是否产出manifest.json sourcemap: false, // 是否产出sourcemap.json outDir: 'dist', // 产出目录 // rollupOptions, }, esbuild, optimizeDeps, plugins: [ GvaPositionServer(), GvaPosition(), legacyPlugin({ targets: ['Android > 39', 'Chrome >= 60', 'Safari >= 10.1', 'iOS >= 10.3', 'Firefox >= 54', 'Edge >= 15'], }), vuePlugin(), [Banner(\n Build based on gin-vue-admin \n Time : ${timestamp})] ], css: { preprocessorOptions: { scss: { additionalData: @use "@/style/element/index.scss" as *;, } } }, } ENV = 'production' VITE_PUBLIC_PATH = '/devOnlineStatus/' VITE_CLI_PORT = 8080 VITE_SERVER_PORT = 8888 VITE_BASE_API = /api #下方修改为你的线上ip VITE_BASE_PATH = https://demo.gin-vue-admin.com # router 模式 VITE_APP_USE_HASH = true 请帮我修改以上代码,当build打包时,前端页面url新增VITE_PUBLIC_PATH前缀
时间: 2024-04-21 07:24:10 浏览: 315
const config = {
base: './', // index.html文件所在位置
root: './', // js导入的资源路径,src
resolve: {
alias,
},
define: {
'process.env': {}
},
server: {
// 如果使用docker-compose开发模式,设置为false
open: true,
port: process.env.VITE_CLI_PORT,
proxy: {
// 把key的路径代理到target位置
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VITE_BASE_API]: { // 需要代理的路径 例如 '/api'
target: `${process.env.VITE_BASE_PATH}/`, // 代理到 目标路径
changeOrigin: true,
rewrite: path => path.replace(new RegExp('^' + process.env.VITE_BASE_API), ''),
},
[process.env.VITE_BASE_EXPORT_API]: { // 需要代理的路径 例如 '/api'
target: `${process.env.VITE_BASE_REPORTAPI}/`, // 代理到 目标路径
changeOrigin: true,
rewrite: path => path.replace(new RegExp('^' + process.env.VITE_BASE_EXPORT_API), ''),
},
},
},
build: {
target: 'es2017',
minify: 'terser', // 是否进行压缩,boolean | 'terser' | 'esbuild',默认使用terser
manifest: false, // 是否产出manifest.json
sourcemap: false, // 是否产出sourcemap.json
outDir: 'dist', // 产出目录
// rollupOptions,
},
esbuild,
optimizeDeps,
plugins: [
GvaPositionServer(),
GvaPosition(),
legacyPlugin({
targets: ['Android > 39', 'Chrome >= 60', 'Safari >= 10.1', 'iOS >= 10.3', 'Firefox >= 54', 'Edge >= 15'],
}),
vuePlugin(),
[Banner(`\n Build based on gin-vue-admin \n Time : ${timestamp}`)]
],
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "@/style/element/index.scss" as *;`,
}
}
},
}
// Add VITE_PUBLIC_PATH to the define object when building
if (command === 'build') {
config.define['process.env.VITE_PUBLIC_PATH'] = JSON.stringify(process.env.VITE_PUBLIC_PATH)
}
return config
阅读全文