feat: add web application
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import type { Plugin } from 'vite';
|
||||
import Components from 'unplugin-vue-components/vite';
|
||||
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
|
||||
import AutoImport from 'unplugin-auto-import/vite';
|
||||
import topLevelAwait from 'vite-plugin-top-level-await';
|
||||
import setupExtend from 'vite-plugin-vue-setup-extend';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx';
|
||||
import { configHtmlPlugin } from './html';
|
||||
import { configCompressPlugin } from './compress';
|
||||
|
||||
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
|
||||
const { VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv;
|
||||
|
||||
const vitePlugins: (Plugin | Plugin[])[] = [
|
||||
// have to
|
||||
vue(),
|
||||
// have to
|
||||
vueJsx(),
|
||||
|
||||
// 按需引入NaiveUi且自动创建组件声明
|
||||
Components({
|
||||
dts: true,
|
||||
resolvers: [NaiveUiResolver()],
|
||||
}),
|
||||
|
||||
// 自动引入API
|
||||
AutoImport({
|
||||
imports: [
|
||||
'vue',
|
||||
'vue-router',
|
||||
{
|
||||
'@/locale/index': ['t'],
|
||||
},
|
||||
],
|
||||
dts: 'auto-imports.d.ts',
|
||||
}),
|
||||
|
||||
// 支持顶级wait
|
||||
topLevelAwait({
|
||||
// The export name of top-level await promise for each chunk module
|
||||
promiseExportName: '__tla',
|
||||
// The function to generate import names of top-level await promise in each chunk module
|
||||
promiseImportName: (i) => `__tla_${i}`,
|
||||
}),
|
||||
];
|
||||
|
||||
// vite-plugin-html
|
||||
vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
|
||||
|
||||
if (isBuild) {
|
||||
// rollup-plugin-gzip
|
||||
vitePlugins.push(
|
||||
configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE)
|
||||
);
|
||||
}
|
||||
|
||||
vitePlugins.push(setupExtend());
|
||||
|
||||
return vitePlugins;
|
||||
}
|
||||
Reference in New Issue
Block a user