You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.6 KiB
103 lines
3.6 KiB
3 years ago
|
import { UserConfigExport, ConfigEnv } from 'vite';
|
||
|
import { resolve } from 'path';
|
||
|
|
||
|
import vue from '@vitejs/plugin-vue';
|
||
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
||
|
import AutoImport from 'unplugin-auto-import/vite';
|
||
|
import Components from 'unplugin-vue-components/vite';
|
||
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
|
||
|
import { createStyleImportPlugin, ElementPlusResolve as ElementPlusStyleResolve } from 'vite-plugin-style-import';
|
||
|
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
|
||
|
import globalStyle from '@originjs/vite-plugin-global-style';
|
||
|
import removeConsole from 'vite-plugin-remove-console';
|
||
|
import legacy from '@vitejs/plugin-legacy';
|
||
|
|
||
|
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
|
||
|
console.info('command', command);
|
||
|
console.info('mode', mode);
|
||
|
return {
|
||
|
server: {
|
||
|
host: '0.0.0.0',
|
||
|
port: 3000,
|
||
|
open: false,
|
||
|
proxy: {
|
||
|
'/api': {
|
||
|
target: 'https://gateway-test.mashibing.cn', // 测试地址
|
||
|
// target: 'https://gateway.mashibing.cn', // 预发地址
|
||
|
// target: 'https://gateway.mashibing.com', // 生产环境
|
||
|
changeOrigin: true,
|
||
|
rewrite: (path) => path.replace(/^\/api/, ''),
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
resolve: {
|
||
|
alias: [
|
||
|
{
|
||
|
find: '@',
|
||
|
replacement: resolve(process.cwd(), 'src'),
|
||
|
},
|
||
|
{
|
||
|
find: '~',
|
||
|
replacement: resolve(process.cwd(), 'src/assets'),
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
plugins: [
|
||
|
vue(),
|
||
|
vueJsx(),
|
||
|
createSvgIconsPlugin({
|
||
|
iconDirs: [resolve(process.cwd(), 'src/icons/svg')],
|
||
|
symbolId: 'icon-[dir]-[name]',
|
||
|
}),
|
||
|
createStyleImportPlugin({
|
||
|
include: ['**/*.js', '**/*.ts', '**/*.tsx', '**/*.jsx', '**/*.vue'],
|
||
|
resolves: [ElementPlusStyleResolve()],
|
||
|
}),
|
||
|
AutoImport({
|
||
|
include: [/\.[jt]sx?$/, /\.vue\??/],
|
||
|
imports: [
|
||
|
'vue',
|
||
|
'vuex',
|
||
|
'vue-router',
|
||
|
{
|
||
|
axios: [
|
||
|
['default', 'axios'], // import { default as axios } from 'axios',
|
||
|
],
|
||
|
},
|
||
|
{ lodash: [['*', '_']] },
|
||
|
{ dayjs: [['*', 'dayjs']] },
|
||
|
],
|
||
|
eslintrc: {
|
||
|
enabled: true,
|
||
|
filepath: './src/.eslintrc.json',
|
||
|
globalsPropValue: true,
|
||
|
},
|
||
|
dts: 'src/auto-imports.d.ts',
|
||
|
}),
|
||
|
Components({
|
||
|
dirs: ['src/components'],
|
||
|
extensions: ['vue', 'jsx', 'tsx', 'js', 'ts'],
|
||
|
deep: true,
|
||
|
resolvers: [ElementPlusResolver()],
|
||
|
dts: 'src/components.d.ts',
|
||
|
include: [/\.tsx$/, /\.jsx$/, /\.ts$/, /\.js$/, /\.vue$/, /\.vue\?vue/],
|
||
|
exclude: [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/],
|
||
|
}),
|
||
|
removeConsole(),
|
||
|
globalStyle({
|
||
|
sourcePath: 'src/styles',
|
||
|
}),
|
||
|
legacy({
|
||
|
targets: ['defaults', 'not IE 11'],
|
||
|
}),
|
||
|
],
|
||
|
css: {
|
||
|
preprocessorOptions: {
|
||
|
less: {
|
||
|
javascriptEnabled: true,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
};
|
||
|
};
|