加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vite.config.js 2.50 KB
一键复制 编辑 原始数据 按行查看 历史
XCHLX 提交于 2023-11-13 14:20 . docs: 增加sass文件
// node
import { fileURLToPath, URL } from 'node:url'
// vite 基础配置
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
// eslint 插件
import eslintPlugin from 'vite-plugin-eslint'
// vite 服务配置
import { viteservice } from './config/viteSettings'
// 自动导入
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
// 打包分析
import { visualizer } from 'rollup-plugin-visualizer'
// https://vitejs.dev/config/
export default defineConfig(({ command, mode, ssrBuild }) => {
console.log(`🚀 command:${command}, mode:${mode}, ssrBuild:${ssrBuild}`)
process.env.BROWSER = 'chrome' // 指定浏览器打开
return {
define: {
__APP_ENV__: JSON.stringify(loadEnv(mode, process.cwd(), ''))
},
server: viteservice,
plugins: [
vue(),
vueJsx(),
Components({
dirs: ['src/components'],
resolvers: [AntDesignVueResolver({ importStyle: false, resolveIcons: true })],
dts: 'config/plugins/auto-components.d.ts'
}),
AutoImport({
// 自动导入vue
include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/],
dts: 'config/plugins/auto-imports.d.ts',
imports: ['vue', 'vue-router', 'pinia']
}),
eslintPlugin({
include: ['src/**/*.js', 'src/**/*.vue', 'src/**/*.ts', 'src/*.js', 'src/*.vue', 'src/*.ts']
}),
visualizer({ filename: './dist/stats.html', open: false })
],
esbuild: {
pure: mode === 'production' ? ['console.log'] : [], // 删除 console.log
drop: mode === 'production' ? ['debugger'] : [] // 删除 debugger
},
build: {
sourcemap: true,
outDir: 'dist',
assetsDir: 'assets',
rollupOptions: {
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
manualChunks(chunkAlias) {
if (chunkAlias.includes('node_modules')) {
return 'vendor'
}
}
}
}
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'*': __dirname,
components: fileURLToPath(new URL('./src/components', import.meta.url)),
assets: fileURLToPath(new URL('./src/assets', import.meta.url))
}
}
}
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化