build(vite): refine vite.config.ts
This commit is contained in:
parent
a1f2bef5d1
commit
e3648ad1a0
@ -13,6 +13,7 @@ import vueSetupExtend from 'vite-plugin-vue-setup-extend'
|
|||||||
import UnoCSS from 'unocss/vite'
|
import UnoCSS from 'unocss/vite'
|
||||||
import autoprefixer from 'autoprefixer'
|
import autoprefixer from 'autoprefixer'
|
||||||
|
|
||||||
|
/** 这个修改只对web生效,小程序没有index.html这个文件 */
|
||||||
const htmlPlugin = (title: string) => {
|
const htmlPlugin = (title: string) => {
|
||||||
return {
|
return {
|
||||||
name: 'html-transform',
|
name: 'html-transform',
|
||||||
@ -25,8 +26,14 @@ const htmlPlugin = (title: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default ({ mode }) => {
|
export default ({ command, mode }) => {
|
||||||
// mode: 区分生产环境还是开发环境
|
// mode: 区分生产环境还是开发环境
|
||||||
|
console.log(command, mode)
|
||||||
|
// pnpm dev:h5 时得到 => serve development
|
||||||
|
// pnpm build:h5 时得到 => build development
|
||||||
|
// pnpm dev:mp-weixin 时得到 => build development (注意区别,command为build)
|
||||||
|
// pnpm build:mp-weixin 时得到 => build production
|
||||||
|
|
||||||
// process.cwd(): 获取当前文件的目录跟地址
|
// process.cwd(): 获取当前文件的目录跟地址
|
||||||
// loadEnv(): 返回当前环境env文件中额外定义的变量
|
// loadEnv(): 返回当前环境env文件中额外定义的变量
|
||||||
const env = loadEnv(mode, path.resolve(process.cwd(), 'env'))
|
const env = loadEnv(mode, path.resolve(process.cwd(), 'env'))
|
||||||
@ -38,6 +45,7 @@ export default ({ mode }) => {
|
|||||||
htmlPlugin(env.VITE_APP_TITLE),
|
htmlPlugin(env.VITE_APP_TITLE),
|
||||||
svgLoader(),
|
svgLoader(),
|
||||||
// 打包分析插件
|
// 打包分析插件
|
||||||
|
mode === 'production' &&
|
||||||
visualizer({
|
visualizer({
|
||||||
filename: './node_modules/.cache/visualizer/stats.html',
|
filename: './node_modules/.cache/visualizer/stats.html',
|
||||||
open: true,
|
open: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user