加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vite.config.ts 4.37 KB
一键复制 编辑 原始数据 按行查看 历史
蔡华谦 提交于 2023-06-19 20:43 . feat: support delta save
/*
* @Author: fisher
* @Date: 2022-12-16 22:45:48
* @LastEditTime: 2023-05-09 16:17:12
* @LastEditors: your name
* @Description:
* @FilePath: /vite-vue-ts-pc/vite.config.ts
* 可以输入预定的版权声明、个性签名、空行等
*/
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import eslintPlugin from 'vite-plugin-eslint'
import DefineOptions from 'unplugin-vue-define-options/dist/vite'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { createHtmlPlugin } from 'vite-plugin-html'
import AutoImport from 'unplugin-auto-import/vite'
// import { visualizer } from 'rollup-plugin-visualizer'
// import vueI18n from '@intlify/vite-plugin-vue-i18n'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
console.log(mode)
return {
base:
mode === 'production' ? loadEnv(mode, process.cwd()).VITE_CDN_URL : './',
resolve: {
alias: [
{ find: /^~/, replacement: '' },
{ find: '@', replacement: resolve(__dirname, './src') }
]
},
plugins: [
vue(),
vueJsx(),
DefineOptions(),
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/, // .vue
/\.md$/ // .md
],
imports: [
'vue',
'vue-router',
'vue-i18n',
{
'naive-ui': [
'useDialog',
'useMessage',
'useNotification',
'useLoadingBar'
]
}
],
dts: './auto-imports.d.ts',
eslintrc: {
enabled: false, // Default `false`
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
}
}),
Components({
resolvers: [NaiveUiResolver()]
}),
eslintPlugin({
include: ['src/**/*.ts', 'src/**/*.vue', 'src/*.ts', 'src/*.vue'],
cache: false
}),
createHtmlPlugin({
minify: true,
pages: [
{
entry: 'src/main.ts',
filename: 'index.html',
template: 'index.html',
injectOptions: {
data: {
title: 'DOBrowser'
}
}
},
{
entry: 'src/login/login.ts',
filename: 'login.html',
template: 'login.html',
injectOptions: {
data: {
title: '登录'
}
}
}
]
})
// visualizer({
// open: true,
// gzipSize: true
// })
// vueI18n({
// include: resolve(__dirname, './src/i18n/**')
// })
],
build: {
sourcemap: false,
cssCodeSplit: true,
assetsInlineLimit: 10240, // 静态资源少于10kb转base64
minify: 'terser',
terserOptions: {
compress: {
warnings: false,
drop_debugger: true, // console
drop_console: true, // 注释console
pure_funcs: ['console.log'] // 移除console
}
},
rollupOptions: {
input: {
main: resolve(__dirname, 'src/main.ts'),
login: resolve(__dirname, 'src/login/main.ts')
},
plugins: [
// rollup plugin
],
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return id.includes('naive') ? 'naive' : 'vendor'
}
}
}
}
},
server: {
port: 3334,
hmr: true
// proxy: {
// '/api': {
// // 要访问的跨域的域名
// target: loadEnv(mode, process.cwd()).VITE_PROXY,
// // ws: true, // 是否启用websockets
// rewrite: (path) => path.replace(/^\/api/, ''),
// secure: false, // 使用的是http协议则设置为false,https协议则设置为true
// changOrigin: true
// }
// }
},
// 修复 vue-i18n composition api warning
define: {
__VUE_I18N_FULL_INSTALL__: true,
__VUE_I18N_LEGACY_API__: false,
__INTLIFY_PROD_DEVTOOLS__: false
}
}
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化