go-view/vite.config.ts

84 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-12-10 14:11:49 +08:00
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
2022-02-28 20:26:41 +08:00
import { resolve } from 'path'
2022-03-01 16:46:48 +08:00
import { OUTPUT_DIR, brotliSize, chunkSizeWarningLimit, terserOptions, rollupOptions } from './build/constant'
2022-02-28 20:26:41 +08:00
import viteCompression from 'vite-plugin-compression'
2022-07-06 14:13:27 +08:00
import { viteMockServe } from 'vite-plugin-mock'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'
2021-12-10 14:11:49 +08:00
function pathResolve(dir: string) {
2022-02-28 20:26:41 +08:00
return resolve(process.cwd(), '.', dir)
2021-12-10 14:11:49 +08:00
}
export default defineConfig({
base: '/',
2022-03-24 09:19:14 +08:00
// 路径重定向
2021-12-10 14:11:49 +08:00
resolve: {
alias: [
{
find: /\/#\//,
replacement: pathResolve('types')
2021-12-10 14:11:49 +08:00
},
{
find: '@',
replacement: pathResolve('src')
},
{
find: 'vue-i18n',
2023-12-17 00:12:50 +08:00
replacement: 'vue-i18n/dist/vue-i18n.cjs.js' //解决i8n警告
2021-12-10 14:11:49 +08:00
}
],
2022-02-28 20:26:41 +08:00
dedupe: ['vue']
2021-12-10 14:11:49 +08:00
},
2022-03-24 09:19:14 +08:00
// 全局 css 注册
2021-12-10 14:11:49 +08:00
css: {
preprocessorOptions: {
scss: {
javascriptEnabled: true,
2022-02-28 20:26:41 +08:00
additionalData: `@import "src/styles/common/style.scss";`
}
}
2021-12-10 14:11:49 +08:00
},
plugins: [
2023-12-17 00:12:50 +08:00
vue({
template: {
compilerOptions: {
// 排除 iconify 图标影子组件编译报错
isCustomElement: tag => tag.startsWith('iconify-icon')
}
}
}),
2022-07-06 14:13:27 +08:00
monacoEditorPlugin({
2022-07-15 00:11:42 +08:00
languageWorkers: ['editorWorkerService', 'typescript', 'json', 'html']
2022-07-06 14:13:27 +08:00
}),
2022-03-24 09:19:14 +08:00
viteMockServe({
2022-07-06 14:13:27 +08:00
mockPath: '/src/api/mock',
2022-03-24 09:19:14 +08:00
// 开发打包开关
2022-07-06 14:13:27 +08:00
localEnabled: true,
2022-03-24 09:19:14 +08:00
// 生产打包开关
prodEnabled: true,
// 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件
supportTs: true,
// 监视文件更改
2022-07-06 14:13:27 +08:00
watchFiles: true
}),
2022-03-24 09:19:14 +08:00
// 压缩
2022-02-28 20:26:41 +08:00
viteCompression({
verbose: true,
disable: false,
threshold: 10240,
algorithm: 'gzip',
ext: '.gz'
})
2021-12-10 14:11:49 +08:00
],
build: {
target: 'es2015',
outDir: OUTPUT_DIR,
// minify: 'terser', // 如果需要用terser混淆可打开这两行
// terserOptions: terserOptions,
2022-03-01 16:46:48 +08:00
rollupOptions: rollupOptions,
brotliSize: brotliSize,
chunkSizeWarningLimit: chunkSizeWarningLimit
2022-02-28 20:26:41 +08:00
}
})