@kengic/vue 0.21.4 → 0.21.5-beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. package/dist/kengic-vue.js +8 -3
  2. package/dist/project/build/config/themeConfig.ts +67 -0
  3. package/dist/project/build/constant.ts +6 -0
  4. package/dist/project/build/generate/generateModifyVars.ts +39 -0
  5. package/dist/project/build/generate/icon/index.ts +66 -0
  6. package/dist/project/build/getConfigFileName.ts +7 -0
  7. package/dist/project/build/index.ts +9 -0
  8. package/dist/project/build/script/buildConf.ts +45 -0
  9. package/dist/project/build/script/postBuild.ts +21 -0
  10. package/dist/project/build/utils.ts +92 -0
  11. package/dist/project/build/vite/plugin/compress.ts +32 -0
  12. package/dist/project/build/vite/plugin/html.ts +39 -0
  13. package/dist/project/build/vite/plugin/imagemin.ts +34 -0
  14. package/dist/project/build/vite/plugin/index.ts +80 -0
  15. package/dist/project/build/vite/plugin/mock.ts +19 -0
  16. package/dist/project/build/vite/plugin/pwa.ts +33 -0
  17. package/dist/project/build/vite/plugin/styleImport.ts +81 -0
  18. package/dist/project/build/vite/plugin/svgSprite.ts +17 -0
  19. package/dist/project/build/vite/plugin/theme.ts +100 -0
  20. package/dist/project/build/vite/plugin/visualizer.ts +17 -0
  21. package/dist/project/build/vite/proxy.ts +34 -0
  22. package/dist/project/index.ts +1 -0
  23. package/dist/project/src/api/sys/model/menuModel.ts +17 -0
  24. package/dist/project/src/api/sys/model/uploadModel.ts +5 -0
  25. package/dist/project/src/api/sys/model/userModel.ts +57 -0
  26. package/dist/project/src/enums/CompTypeEnum.ts +32 -0
  27. package/dist/project/src/enums/DateTypeEnum.ts +8 -0
  28. package/dist/project/src/enums/appEnum.ts +58 -0
  29. package/dist/project/src/enums/breakpointEnum.ts +28 -0
  30. package/dist/project/src/enums/cacheEnum.ts +39 -0
  31. package/dist/project/src/enums/exceptionEnum.ts +27 -0
  32. package/dist/project/src/enums/httpEnum.ts +50 -0
  33. package/dist/project/src/enums/jeecgEnum.ts +23 -0
  34. package/dist/project/src/enums/menuEnum.ts +50 -0
  35. package/dist/project/src/enums/pageEnum.ts +19 -0
  36. package/dist/project/src/enums/roleEnum.ts +7 -0
  37. package/dist/project/src/enums/sizeEnum.ts +27 -0
  38. package/dist/project/types/axios.d.ts +57 -0
  39. package/dist/project/types/config.d.ts +178 -0
  40. package/dist/project/types/global.d.ts +92 -0
  41. package/dist/project/types/index.d.ts +27 -0
  42. package/dist/project/types/module.d.ts +18 -0
  43. package/dist/project/types/store.d.ts +59 -0
  44. package/dist/project/types/utils.d.ts +5 -0
  45. package/dist/project/types/vue-router.d.ts +47 -0
  46. package/package.json +25 -2
@@ -2462,7 +2462,7 @@ const emptyIcon = {
2462
2462
  ...t.data
2463
2463
  }, r);
2464
2464
  }
2465
- }), version = "0.21.4";
2465
+ }), version = "0.21.5-beta.1";
2466
2466
  var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
2467
2467
  const freeGlobal$1 = freeGlobal;
2468
2468
  var freeSelf = typeof self == "object" && self && self.Object === Object && self, root = freeGlobal$1 || freeSelf || Function("return this")();
@@ -19498,11 +19498,16 @@ function httpClient() {
19498
19498
  [KG_HTTP_HEADERS.KG_QUERY_ORDER_BY_SQL]: _
19499
19499
  };
19500
19500
  }
19501
- return (o = n.headers) != null && o[KG_HTTP_HEADERS.KG_QUERY_SQL] && (n.headers[KG_HTTP_HEADERS.KG_QUERY_SQL] = encodeURIComponent(decodeURIComponent(String(n.headers[KG_HTTP_HEADERS.KG_QUERY_SQL])))), (l = n.headers) != null && l[KG_HTTP_HEADERS.KG_QUERY_WHERE_SQL] && (n.headers[KG_HTTP_HEADERS.KG_QUERY_WHERE_SQL] = encodeURIComponent(
19501
+ if ((o = n.headers) != null && o[KG_HTTP_HEADERS.KG_QUERY_SQL] && (n.headers[KG_HTTP_HEADERS.KG_QUERY_SQL] = encodeURIComponent(decodeURIComponent(String(n.headers[KG_HTTP_HEADERS.KG_QUERY_SQL])))), (l = n.headers) != null && l[KG_HTTP_HEADERS.KG_QUERY_WHERE_SQL] && (n.headers[KG_HTTP_HEADERS.KG_QUERY_WHERE_SQL] = encodeURIComponent(
19502
19502
  decodeURIComponent(String(n.headers[KG_HTTP_HEADERS.KG_QUERY_WHERE_SQL]))
19503
19503
  )), (c = n.headers) != null && c[KG_HTTP_HEADERS.KG_QUERY_ORDER_BY_SQL] && (n.headers[KG_HTTP_HEADERS.KG_QUERY_ORDER_BY_SQL] = encodeURIComponent(
19504
19504
  decodeURIComponent(String(n.headers[KG_HTTP_HEADERS.KG_QUERY_ORDER_BY_SQL]))
19505
- )), ((u = a.option.value.KgWarehouse) == null ? void 0 : u.on) !== !1 && (n.headers || (n.headers = {}), n.headers[KG_HTTP_HEADERS.KG_WAREHOUSE] = (b = (d = useKgWarehouse().warehouse.value) == null ? void 0 : d.whId) != null ? b : ""), e.apply(t, [n, s]);
19505
+ )), ((u = a.option.value.KgWarehouse) == null ? void 0 : u.on) !== !1) {
19506
+ n.headers || (n.headers = {});
19507
+ const y = (b = (d = useKgWarehouse().warehouse.value) == null ? void 0 : d.whId) != null ? b : "";
19508
+ n.headers[KG_HTTP_HEADERS.KG_WAREHOUSE] = encodeURIComponent(y);
19509
+ }
19510
+ return e.apply(t, [n, s]);
19506
19511
  }
19507
19512
  }), _httpClient;
19508
19513
  }
@@ -0,0 +1,67 @@
1
+ import { generate } from '@ant-design/colors';
2
+
3
+ export const primaryColor = '#1890FF';
4
+
5
+ export const darkMode = 'light';
6
+
7
+ type Fn = (...arg: any) => any;
8
+
9
+ type GenerateTheme = 'default' | 'dark';
10
+
11
+ export interface GenerateColorsParams {
12
+ mixLighten: Fn;
13
+ mixDarken: Fn;
14
+ tinycolor: any;
15
+ color?: string;
16
+ }
17
+
18
+ export function generateAntColors(color: string, theme: GenerateTheme = 'default') {
19
+ return generate(color, {
20
+ theme,
21
+ });
22
+ }
23
+
24
+ export function getThemeColors(color?: string) {
25
+ const tc = color || primaryColor;
26
+ const lightColors = generateAntColors(tc);
27
+ const primary = lightColors[5];
28
+ const modeColors = generateAntColors(primary, 'dark');
29
+
30
+ return [...lightColors, ...modeColors];
31
+ }
32
+
33
+ export function generateColors({ color = primaryColor, mixLighten, mixDarken, tinycolor }: GenerateColorsParams) {
34
+ const arr = new Array(19).fill(0);
35
+ const lightens = arr.map((_t, i) => {
36
+ return mixLighten(color, i / 5);
37
+ });
38
+
39
+ const darkens = arr.map((_t, i) => {
40
+ return mixDarken(color, i / 5);
41
+ });
42
+
43
+ const alphaColors = arr.map((_t, i) => {
44
+ return tinycolor(color)
45
+ .setAlpha(i / 20)
46
+ .toRgbString();
47
+ });
48
+
49
+ const shortAlphaColors = alphaColors.map((item) => item.replace(/\s/g, '').replace(/0\./g, '.'));
50
+
51
+ const tinycolorLightens = arr
52
+ .map((_t, i) => {
53
+ return tinycolor(color)
54
+ .lighten(i * 5)
55
+ .toHexString();
56
+ })
57
+ .filter((item) => item !== '#ffffff');
58
+
59
+ const tinycolorDarkens = arr
60
+ .map((_t, i) => {
61
+ return tinycolor(color)
62
+ .darken(i * 5)
63
+ .toHexString();
64
+ })
65
+ .filter((item) => item !== '#000000');
66
+ return [...lightens, ...darkens, ...alphaColors, ...shortAlphaColors, ...tinycolorDarkens, ...tinycolorLightens].filter((item) => !item.includes('-'));
67
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The name of the configuration file entered in the production environment
3
+ */
4
+ export const GLOB_CONFIG_FILE_NAME = '_app.config.js';
5
+
6
+ export const OUTPUT_DIR = 'dist';
@@ -0,0 +1,39 @@
1
+ import { getThemeVariables } from 'ant-design-vue/dist/theme';
2
+ import { resolve } from 'path';
3
+ import { generateAntColors, primaryColor } from '../config/themeConfig';
4
+
5
+ /**
6
+ * less global variable
7
+ */
8
+ export function generateModifyVars(dark = false) {
9
+ const palettes = generateAntColors(primaryColor);
10
+ const primary = palettes[5];
11
+
12
+ const primaryColorObj: Record<string, string> = {};
13
+
14
+ for (let index = 0; index < 10; index++) {
15
+ primaryColorObj[`primary-${index + 1}`] = palettes[index];
16
+ }
17
+
18
+ const modifyVars = getThemeVariables({ dark });
19
+ return {
20
+ ...modifyVars,
21
+ // Used for global import to avoid the need to import each style file separately
22
+ // reference: Avoid repeated references
23
+ hack: `${modifyVars.hack} @import (reference) "${resolve('src/design/config.less')}";`,
24
+ 'primary-color': primary,
25
+ ...primaryColorObj,
26
+ 'info-color': primary,
27
+ 'processing-color': primary,
28
+ 'success-color': '#55D187', // Success color
29
+ 'error-color': '#ED6F6F', // False color
30
+ 'warning-color': '#EFBD47', // Warning color
31
+ //'border-color-base': '#EEEEEE',
32
+ 'font-size-base': '14px', // Main font size
33
+ 'border-radius-base': '3px', // Component/float fillet
34
+ 'link-color': primary, // Link color
35
+ 'app-content-background': '#fafafa', // Link color
36
+ 'table-padding-vertical': '12px',
37
+ 'table-padding-horizontal': '12px',
38
+ };
39
+ }
@@ -0,0 +1,66 @@
1
+ import fs from 'fs-extra';
2
+ import inquirer from 'inquirer';
3
+ import path from 'path';
4
+
5
+ async function generateIcon() {
6
+ const dir = path.resolve(process.cwd(), 'node_modules/@iconify/json');
7
+
8
+ const raw = await fs.readJSON(path.join(dir, 'collections.json'));
9
+
10
+ const collections = Object.entries(raw).map(([id, v]) => ({
11
+ ...(v as any),
12
+ id,
13
+ }));
14
+
15
+ const choices = collections.map((item) => ({ key: item.id, value: item.id, name: item.name }));
16
+
17
+ inquirer
18
+ .prompt([
19
+ {
20
+ type: 'list',
21
+ name: 'useType',
22
+ choices: [
23
+ { key: 'local', value: 'local', name: 'Local' },
24
+ { key: 'onLine', value: 'onLine', name: 'OnLine' },
25
+ ],
26
+ message: 'How to use icons?',
27
+ },
28
+ {
29
+ type: 'list',
30
+ name: 'iconSet',
31
+ choices: choices,
32
+ message: 'Select the icon set that needs to be generated?',
33
+ },
34
+ {
35
+ type: 'input',
36
+ name: 'output',
37
+ message: 'Select the icon set that needs to be generated?',
38
+ default: 'src/components/Icon/data',
39
+ },
40
+ ])
41
+ .then(async (answers) => {
42
+ const { iconSet, output, useType } = answers;
43
+ const outputDir = path.resolve(process.cwd(), output);
44
+ fs.ensureDir(outputDir);
45
+ const genCollections = collections.filter((item) => [iconSet].includes(item.id));
46
+ const prefixSet: string[] = [];
47
+ for (const info of genCollections) {
48
+ const data = await fs.readJSON(path.join(dir, 'json', `${info.id}.json`));
49
+ if (data) {
50
+ const { prefix } = data;
51
+ const isLocal = useType === 'local';
52
+ const icons = Object.keys(data.icons).map((item) => `${isLocal ? prefix + ':' : ''}${item}`);
53
+
54
+ await fs.writeFileSync(
55
+ path.join(output, `icons.data.ts`),
56
+ `export default ${isLocal ? JSON.stringify(icons) : JSON.stringify({ prefix, icons })}`,
57
+ );
58
+ prefixSet.push(prefix);
59
+ }
60
+ }
61
+ fs.emptyDir(path.join(process.cwd(), 'node_modules/.vite'));
62
+ console.log(`✨` + ' - Icon generated successfully:' + `[${prefixSet}]`);
63
+ });
64
+ }
65
+
66
+ generateIcon();
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Get the configuration file variable name
3
+ * @param env
4
+ */
5
+ export const getConfigFileName = (env: Record<string, any>) => {
6
+ return `__PRODUCTION__${env.VITE_GLOB_APP_SHORT_NAME || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, '');
7
+ };
@@ -0,0 +1,9 @@
1
+ export * from './config/themeConfig';
2
+ export * from './generate/generateModifyVars';
3
+ export * from './script/buildConf';
4
+ export * from './vite/plugin/index';
5
+ export * from './vite/plugin/index';
6
+ export * from './vite/proxy';
7
+ export * from './constant';
8
+ export * from './getConfigFileName';
9
+ export * from './utils';
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Generate additional configuration files when used for packaging. The file can be configured with some global variables, so that it can be changed directly externally without repackaging
3
+ */
4
+ import fs, { writeFileSync } from 'fs-extra';
5
+ import colors from 'picocolors';
6
+ import { GLOB_CONFIG_FILE_NAME, OUTPUT_DIR } from '../constant';
7
+ import { getConfigFileName } from '../getConfigFileName';
8
+
9
+ import { getEnvConfig, getRootPath } from '../utils';
10
+
11
+ interface CreateConfigParams {
12
+ configName: string;
13
+ config: any;
14
+ configFileName?: string;
15
+ }
16
+
17
+ function createConfig(params: CreateConfigParams) {
18
+ const { configName, config, configFileName } = params;
19
+ try {
20
+ const windowConf = `window.${configName}`;
21
+ // Ensure that the variable will not be modified
22
+ let configStr = `${windowConf}=${JSON.stringify(config)};`;
23
+ configStr += `
24
+ Object.freeze(${windowConf});
25
+ Object.defineProperty(window, "${configName}", {
26
+ configurable: false,
27
+ writable: false,
28
+ });
29
+ `.replace(/\s/g, '');
30
+
31
+ fs.mkdirp(getRootPath(OUTPUT_DIR));
32
+ writeFileSync(getRootPath(`${OUTPUT_DIR}/${configFileName}`), configStr);
33
+
34
+ console.log(colors.cyan(`✨`) + ` - configuration file is build successfully:`);
35
+ console.log(colors.gray(OUTPUT_DIR + '/' + colors.green(configFileName)) + '\n');
36
+ } catch (error) {
37
+ console.log(colors.red('configuration file configuration file failed to package:\n' + error));
38
+ }
39
+ }
40
+
41
+ export function runBuildConfig() {
42
+ const config = getEnvConfig();
43
+ const configFileName = getConfigFileName(config);
44
+ createConfig({ config, configName: configFileName, configFileName: GLOB_CONFIG_FILE_NAME });
45
+ }
@@ -0,0 +1,21 @@
1
+ // #!/usr/bin/env node
2
+
3
+ import colors from 'picocolors';
4
+ import { runBuildConfig } from './buildConf';
5
+
6
+ export const runBuild = async () => {
7
+ try {
8
+ const argvList = process.argv.splice(2);
9
+
10
+ // Generate configuration file
11
+ if (!argvList.includes('disabled-config')) {
12
+ runBuildConfig();
13
+ }
14
+
15
+ console.log(`✨` + ' - build successfully!');
16
+ } catch (error) {
17
+ console.log(colors.red('vite build error:\n' + error));
18
+ process.exit(1);
19
+ }
20
+ };
21
+ runBuild();
@@ -0,0 +1,92 @@
1
+ import dotenv from 'dotenv';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+
5
+ export function isDevFn(mode: string): boolean {
6
+ return mode === 'development';
7
+ }
8
+
9
+ export function isProdFn(mode: string): boolean {
10
+ return mode === 'production';
11
+ }
12
+
13
+ /**
14
+ * Whether to generate package preview
15
+ */
16
+ export function isReportMode(): boolean {
17
+ return process.env.REPORT === 'true';
18
+ }
19
+
20
+ // Read all environment variable configuration files to process.env
21
+ export function wrapperEnv(envConf: Recordable): ViteEnv {
22
+ const ret: any = {};
23
+
24
+ for (const envName of Object.keys(envConf)) {
25
+ let realName = envConf[envName].replace(/\\n/g, '\n');
26
+ realName = realName === 'true' ? true : realName === 'false' ? false : realName;
27
+
28
+ if (envName === 'VITE_PORT') {
29
+ realName = Number(realName);
30
+ }
31
+ if (envName === 'VITE_PROXY' && realName) {
32
+ try {
33
+ realName = JSON.parse(realName.replace(/'/g, '"'));
34
+ } catch (error) {
35
+ realName = '';
36
+ }
37
+ }
38
+ ret[envName] = realName;
39
+ if (typeof realName === 'string') {
40
+ process.env[envName] = realName;
41
+ } else if (typeof realName === 'object') {
42
+ process.env[envName] = JSON.stringify(realName);
43
+ }
44
+ }
45
+ return ret;
46
+ }
47
+
48
+ /**
49
+ * 获取当前环境下生效的配置文件名
50
+ */
51
+ function getConfFiles() {
52
+ const script = process.env.npm_lifecycle_script;
53
+ const reg = new RegExp('--mode ([a-z_\\d]+)');
54
+ const result = reg.exec(script as string) as any;
55
+ if (result) {
56
+ const mode = result[1] as string;
57
+ return ['.env', `.env.${mode}`];
58
+ }
59
+ return ['.env', '.env.production'];
60
+ }
61
+
62
+ /**
63
+ * Get the environment variables starting with the specified prefix
64
+ * @param match prefix
65
+ * @param confFiles ext
66
+ */
67
+ export function getEnvConfig(match = 'VITE_GLOB_', confFiles = getConfFiles()) {
68
+ let envConfig = {};
69
+ confFiles.forEach((item) => {
70
+ try {
71
+ const env = dotenv.parse(fs.readFileSync(path.resolve(process.cwd(), item)));
72
+ envConfig = { ...envConfig, ...env };
73
+ } catch (e) {
74
+ console.error(`Error in parsing ${item}`, e);
75
+ }
76
+ });
77
+ const reg = new RegExp(`^(${match})`);
78
+ Object.keys(envConfig).forEach((key) => {
79
+ if (!reg.test(key)) {
80
+ Reflect.deleteProperty(envConfig, key);
81
+ }
82
+ });
83
+ return envConfig;
84
+ }
85
+
86
+ /**
87
+ * Get user root directory
88
+ * @param dir file path
89
+ */
90
+ export function getRootPath(...dir: string[]) {
91
+ return path.resolve(process.cwd(), ...dir);
92
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
3
+ * https://github.com/anncwb/vite-plugin-compression
4
+ */
5
+ import type { PluginOption } from 'vite';
6
+ import compressPlugin from 'vite-plugin-compression';
7
+
8
+ export function configCompressPlugin(compress: 'gzip' | 'brotli' | 'none', deleteOriginFile = false): PluginOption | PluginOption[] {
9
+ const compressList = compress.split(',');
10
+
11
+ const plugins: PluginOption[] = [];
12
+
13
+ if (compressList.includes('gzip')) {
14
+ plugins.push(
15
+ compressPlugin({
16
+ ext: '.gz',
17
+ deleteOriginFile,
18
+ }),
19
+ );
20
+ }
21
+
22
+ if (compressList.includes('brotli')) {
23
+ plugins.push(
24
+ compressPlugin({
25
+ ext: '.br',
26
+ algorithm: 'brotliCompress',
27
+ deleteOriginFile,
28
+ }),
29
+ );
30
+ }
31
+ return plugins;
32
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Plugin to minimize and use ejs template syntax in index.html.
3
+ * https://github.com/anncwb/vite-plugin-html
4
+ */
5
+ import type { PluginOption } from 'vite';
6
+ import { createHtmlPlugin } from 'vite-plugin-html';
7
+ import { GLOB_CONFIG_FILE_NAME } from '../../constant';
8
+
9
+ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
10
+ const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env;
11
+
12
+ const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`;
13
+
14
+ const getAppConfigSrc = () => {
15
+ return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${new Date().getTime()}`;
16
+ };
17
+
18
+ const htmlPlugin: PluginOption[] = createHtmlPlugin({
19
+ minify: isBuild,
20
+ inject: {
21
+ // Inject data into ejs template
22
+ data: {
23
+ title: VITE_GLOB_APP_TITLE,
24
+ },
25
+ // Embed the generated app.config.js file
26
+ tags: isBuild
27
+ ? [
28
+ {
29
+ tag: 'script',
30
+ attrs: {
31
+ src: getAppConfigSrc(),
32
+ },
33
+ },
34
+ ]
35
+ : [],
36
+ },
37
+ });
38
+ return htmlPlugin;
39
+ }
@@ -0,0 +1,34 @@
1
+ // Image resource files used to compress the output of the production environment
2
+ // https://github.com/anncwb/vite-plugin-imagemin
3
+ import viteImagemin from 'vite-plugin-imagemin';
4
+
5
+ export function configImageminPlugin() {
6
+ const plugin = viteImagemin({
7
+ gifsicle: {
8
+ optimizationLevel: 7,
9
+ interlaced: false,
10
+ },
11
+ optipng: {
12
+ optimizationLevel: 7,
13
+ },
14
+ mozjpeg: {
15
+ quality: 20,
16
+ },
17
+ pngquant: {
18
+ quality: [0.8, 0.9],
19
+ speed: 4,
20
+ },
21
+ svgo: {
22
+ plugins: [
23
+ {
24
+ name: 'removeViewBox',
25
+ },
26
+ {
27
+ name: 'removeEmptyAttrs',
28
+ active: false,
29
+ },
30
+ ],
31
+ },
32
+ });
33
+ return plugin;
34
+ }
@@ -0,0 +1,80 @@
1
+ import legacy from '@vitejs/plugin-legacy';
2
+ import vue from '@vitejs/plugin-vue';
3
+ import vueJsx from '@vitejs/plugin-vue-jsx';
4
+ import { PluginOption } from 'vite';
5
+ import VitePluginCertificate from 'vite-plugin-mkcert';
6
+ import OptimizationPersist from 'vite-plugin-optimize-persist';
7
+ import PkgConfig from 'vite-plugin-package-config';
8
+ import purgeIcons from 'vite-plugin-purge-icons';
9
+ import vueSetupExtend from 'vite-plugin-vue-setup-extend';
10
+ import windiCSS from 'vite-plugin-windicss';
11
+ import { configCompressPlugin } from './compress';
12
+ import { configHtmlPlugin } from './html';
13
+ import { configImageminPlugin } from './imagemin';
14
+ import { configMockPlugin } from './mock';
15
+ import { configPwaConfig } from './pwa';
16
+ import { configStyleImportPlugin } from './styleImport';
17
+ import { configSvgIconsPlugin } from './svgSprite';
18
+ import { configThemePlugin } from './theme';
19
+ import { configVisualizerConfig } from './visualizer';
20
+
21
+ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
22
+ const { VITE_USE_IMAGEMIN, VITE_USE_MOCK, VITE_LEGACY, VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv;
23
+
24
+ const vitePlugins: (PluginOption | PluginOption[])[] = [
25
+ // have to
26
+ vue(),
27
+ // have to
28
+ vueJsx(),
29
+ // support name
30
+ vueSetupExtend(),
31
+ // @ts-ignore
32
+ VitePluginCertificate({
33
+ source: 'coding',
34
+ }),
35
+ ];
36
+
37
+ // vite-plugin-windicss
38
+ vitePlugins.push(windiCSS());
39
+
40
+ // @vitejs/plugin-legacy
41
+ VITE_LEGACY && isBuild && vitePlugins.push(legacy());
42
+
43
+ // vite-plugin-html
44
+ vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
45
+
46
+ // vite-plugin-svg-icons
47
+ vitePlugins.push(configSvgIconsPlugin(isBuild));
48
+
49
+ // vite-plugin-mock
50
+ VITE_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild));
51
+
52
+ // vite-plugin-purge-icons
53
+ vitePlugins.push(purgeIcons());
54
+
55
+ // vite-plugin-style-import
56
+ vitePlugins.push(configStyleImportPlugin(isBuild));
57
+
58
+ // rollup-plugin-visualizer
59
+ vitePlugins.push(configVisualizerConfig());
60
+
61
+ // vite-plugin-theme
62
+ vitePlugins.push(configThemePlugin(isBuild));
63
+
64
+ // The following plugins only work in the production environment
65
+ if (isBuild) {
66
+ // vite-plugin-imagemin
67
+ VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin());
68
+
69
+ // rollup-plugin-gzip
70
+ vitePlugins.push(configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE));
71
+
72
+ // vite-plugin-pwa
73
+ vitePlugins.push(configPwaConfig(viteEnv));
74
+ }
75
+
76
+ //vite-plugin-theme【解决vite首次打开界面加载慢问题】
77
+ vitePlugins.push(PkgConfig());
78
+ vitePlugins.push(OptimizationPersist());
79
+ return vitePlugins;
80
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Mock plugin for development and production.
3
+ * https://github.com/anncwb/vite-plugin-mock
4
+ */
5
+ import { viteMockServe } from 'vite-plugin-mock';
6
+
7
+ export function configMockPlugin(isBuild: boolean) {
8
+ return viteMockServe({
9
+ ignore: /^\_/,
10
+ mockPath: 'mock',
11
+ localEnabled: !isBuild,
12
+ prodEnabled: isBuild,
13
+ injectCode: `
14
+ import { setupProdMockServer } from '../mock/_createProductionServer';
15
+
16
+ setupProdMockServer();
17
+ `,
18
+ });
19
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Zero-config PWA for Vite
3
+ * https://github.com/antfu/vite-plugin-pwa
4
+ */
5
+ import { VitePWA } from 'vite-plugin-pwa';
6
+
7
+ export function configPwaConfig(env: ViteEnv) {
8
+ const { VITE_USE_PWA, VITE_GLOB_APP_TITLE, VITE_GLOB_APP_SHORT_NAME } = env;
9
+
10
+ if (VITE_USE_PWA) {
11
+ // vite-plugin-pwa
12
+ const pwaPlugin = VitePWA({
13
+ manifest: {
14
+ name: VITE_GLOB_APP_TITLE,
15
+ short_name: VITE_GLOB_APP_SHORT_NAME,
16
+ icons: [
17
+ {
18
+ src: './resource/img/pwa-192x192.png',
19
+ sizes: '192x192',
20
+ type: 'image/png',
21
+ },
22
+ {
23
+ src: './resource/img/pwa-512x512.png',
24
+ sizes: '512x512',
25
+ type: 'image/png',
26
+ },
27
+ ],
28
+ },
29
+ });
30
+ return pwaPlugin;
31
+ }
32
+ return [];
33
+ }