加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vite.config.ts 2.75 KB
一键复制 编辑 原始数据 按行查看 历史
Joker 提交于 2024-03-24 18:17 . first commit
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import alias from '@rollup/plugin-alias'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { resolve } from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
// mock server
import { viteMockServe } from 'vite-plugin-mock'
import Icons from 'unplugin-icons/vite'
const rootPath = resolve(__dirname)
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), '')
return {
plugins: [
vue({
script: {
defineModel: true
}
}),
vueJsx(),
alias({
entries: [
{
find: '@',
replacement: resolve(rootPath, 'src')
}
]
}),
viteMockServe({
mockPath: './mock',
// localEnabled: env.NODE_ENV === 'development',
localEnabled: command === 'serve',
watchFiles: true // 监视文件夹中的文件更改。 并实时同步到请求结果
}),
AutoImport({
imports: ['vue', 'vue-router', 'pinia', '@vueuse/core']
// resolvers: [ ElementPlusResolver({importStyle: 'sass'}) ]
}),
Components({
dirs: ['src/components/', 'src/layout/'],
extensions: ['vue'],
// directoryAsNamespace: true,
deep: true,
dts: true,
include: [/\.vue$/, /\.vue\?vue/],
exclude: [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/]
// resolvers: [ ElementPlusResolver({ importStyle: 'sass'}) ]
}),
Icons({
compiler: 'vue3',
autoInstall: true
})
],
publicDir: './public',
define: {
BASE_URL: env.BASE_URL
},
preprocessorOptions: {
scss: {
// additionalData: `@use "@/public/assets/styles/element.scss" as *;`,
}
},
server: {
host: '127.0.0.1',
port: 8001,
open: true, // 自动打开浏览器
cors: true, // 允许跨域
strictPort: true // 端口占用直接退出
},
build: {
chunkSizeWarningLimit: 2000,
minify: 'terser',
terserOptions: {
compress: {
drop_console: false,
pure_funcs: ['console.log', 'console.info'],
drop_debugger: true
}
},
// outDir: '../public/admin',
assetsDir: 'assets',
rollupOptions: {
input: './index.html',
output: {
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]'
}
}
}
}
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化