| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import { defineConfig, loadEnv } from 'vite'
- import vue from '@vitejs/plugin-vue'
- import path from 'path'
- // 引入@vitejs/plugin-legacy
- import legacy from '@vitejs/plugin-legacy'
- // https://vite.dev/config/
- export default defineConfig(({ mode }) => {
- // 加载对应模式的环境变量
- const env = loadEnv(mode, process.cwd())
- return {
- plugins: [
- legacy({
- targets: ['defaults', 'not IE 11']
- }),
- vue({
- template: {
- compilerOptions: {
- // 告诉Vue这些是原生自定义元素,不需要解析为Vue组件
- isCustomElement: (tag) => {
- // Blockly工具箱中使用的标签
- return ['block', 'category', 'field', 'shadow', 'value', 'sep', 'label'].includes(tag)
- }
- }
- }
- }),
- ],
- base: './',
- resolve: {
- // 路径别名配置
- alias: {
- '@': path.resolve(__dirname, './src')
- }
- },
- server: {
- host: '0.0.0.0',
- proxy: {
- '/admin-api': {
- // 使用加载的环境变量
- target: env.VITE_BASE_URL,
- changeOrigin: true
- }
- }
- },
- build: {
- outDir: 'aiWeb',
- rollupOptions: {
- output: {
- entryFileNames: `assets/[name]-[hash].js`,
- chunkFileNames: `assets/[name]-[hash].js`,
- // 保留原始目录结构
- assetFileNames: ({ name }) => {
- const extType = name.split('.').pop();
- if (/png|jpe?g|gif|svg|webp/i.test(extType)) {
- return `assets/images/[name]-[hash].[ext]`;
- }
- if (/woff2?|ttf|otf|eot/i.test(extType)) {
- return `assets/typeface/[name]-[hash].[ext]`;
- }
- if (/mp4/i.test(extType)) {
- return `assets/02video/[name]-[hash].[ext]`;
- }
- return `assets/[name]-[hash].[ext]`;
- }
- }
- }
- }
- }
- })
|