加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vite.config.js 2.44 KB
一键复制 编辑 原始数据 按行查看 历史
huisl 提交于 2024-07-02 17:04 . 环境变量
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { PrimeVueResolver } from 'unplugin-vue-components/resolvers';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import { resolve } from 'path';
export default ({ mode }) =>
defineConfig({
plugins: [
vue(),
AutoImport({
resolvers: [],
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/ // .vue
],
imports: ['vue', 'vue-router', '@vueuse/core', 'pinia'],
dts: 'typings/auto-imports.d.ts',
dirs: ['./src/request/**', './src/utils/**', './src/store/**'],
vueTemplate: true
}),
Components({
dirs: ['src/components'],
dts: true,
deep: true,
resolvers: [PrimeVueResolver()]
}),
createSvgIconsPlugin({
iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
symbolId: 'icon-[name]'
})
],
resolve: {
alias: [
// { find: '@vue-office', replacement: resolve(__dirname, 'node_modules/@vue-office') },
{ find: '@', replacement: resolve(__dirname, 'src') }
]
},
server: {
port: 8990,
proxy: {
'/api': {
target: loadEnv(mode, process.cwd()).VITE_BASE_URL,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@import "./src/styles/colors.scss";'
}
}
},
// 配置打包文件输出
build: {
outDir: 'cloud',
// 压缩配置
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
},
rollupOptions: {
output: {
entryFileNames: 'js/[name].[hash].js',
chunkFileNames: 'js/[name].[hash].js',
assetFileNames(assetInfo) {
if (assetInfo.name.endsWith('.css')) {
return 'css/[name].[hash].css';
}
if (
['.png', '.jpg', '.jpeg', '.svg'].some((ext) =>
assetInfo.name.endsWith(ext)
)
) {
return 'imgs/[name].[hash].[ext]';
}
return 'assets/[name].[hash].[ext]';
}
}
}
}
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化