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.
63 lines
2.0 KiB
63 lines
2.0 KiB
import type { Plugin, PluginOption } from 'vite';
|
|
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
|
|
import AutoImport from 'unplugin-auto-import/vite';
|
|
import Components from 'unplugin-vue-components/vite';
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
|
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
|
|
import { configHtmlPlugin } from './html';
|
|
import { configMockPlugin } from './mock';
|
|
import { configCompressPlugin } from './compress';
|
|
|
|
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean, prodMock) {
|
|
const { VITE_USE_MOCK, VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv;
|
|
|
|
const vitePlugins: (Plugin | Plugin[] | PluginOption[])[] = [
|
|
// have to
|
|
vue(),
|
|
// have to
|
|
vueJsx(),
|
|
|
|
AutoImport({
|
|
// 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
|
|
imports: [
|
|
'vue',
|
|
'@vueuse/core',
|
|
{
|
|
'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar'],
|
|
},
|
|
],
|
|
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')
|
|
},
|
|
resolvers: [NaiveUiResolver(), ElementPlusResolver()],
|
|
vueTemplate: true, // 是否在 vue 模板中自动导入
|
|
dts: true,
|
|
}),
|
|
|
|
// 按需引入NaiveUi且自动创建组件声明
|
|
Components({
|
|
dts: true,
|
|
resolvers: [NaiveUiResolver(), ElementPlusResolver()],
|
|
}),
|
|
];
|
|
|
|
// vite-plugin-html
|
|
vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
|
|
|
|
// vite-plugin-mock
|
|
VITE_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild, prodMock));
|
|
|
|
if (isBuild) {
|
|
// rollup-plugin-gzip
|
|
vitePlugins.push(
|
|
configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE)
|
|
);
|
|
}
|
|
|
|
return vitePlugins;
|
|
}
|
|
|