|
@@ -1,106 +1,94 @@
|
|
|
-import path from 'node:path'
|
|
|
|
|
-import process from 'node:process'
|
|
|
|
|
-import vueLegacy from '@vitejs/plugin-legacy'
|
|
|
|
|
-import vue from '@vitejs/plugin-vue'
|
|
|
|
|
-import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
|
|
|
-import boxen from 'boxen'
|
|
|
|
|
-import picocolors from 'picocolors'
|
|
|
|
|
-import Unocss from 'unocss/vite'
|
|
|
|
|
-import autoImport from 'unplugin-auto-import/vite'
|
|
|
|
|
-import TurboConsole from 'unplugin-turbo-console/vite'
|
|
|
|
|
-import components from 'unplugin-vue-components/vite'
|
|
|
|
|
-import { loadEnv, type PluginOption } from 'vite'
|
|
|
|
|
-import AppLoading from 'vite-plugin-app-loading'
|
|
|
|
|
-import Archiver from 'vite-plugin-archiver'
|
|
|
|
|
-import banner from 'vite-plugin-banner'
|
|
|
|
|
-import { compression } from 'vite-plugin-compression2'
|
|
|
|
|
-import { vitePluginFakeServer } from 'vite-plugin-fake-server'
|
|
|
|
|
-import Pages from 'vite-plugin-pages'
|
|
|
|
|
-import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
|
|
|
|
-import VueDevTools from 'vite-plugin-vue-devtools'
|
|
|
|
|
-import Layouts from 'vite-plugin-vue-meta-layouts'
|
|
|
|
|
|
|
+import path from "node:path";
|
|
|
|
|
+import process from "node:process";
|
|
|
|
|
+import vueLegacy from "@vitejs/plugin-legacy";
|
|
|
|
|
+import vue from "@vitejs/plugin-vue";
|
|
|
|
|
+import vueJsx from "@vitejs/plugin-vue-jsx";
|
|
|
|
|
+import boxen from "boxen";
|
|
|
|
|
+import picocolors from "picocolors";
|
|
|
|
|
+import Unocss from "unocss/vite";
|
|
|
|
|
+import autoImport from "unplugin-auto-import/vite";
|
|
|
|
|
+import TurboConsole from "unplugin-turbo-console/vite";
|
|
|
|
|
+import components from "unplugin-vue-components/vite";
|
|
|
|
|
+import { loadEnv, type PluginOption } from "vite";
|
|
|
|
|
+import AppLoading from "vite-plugin-app-loading";
|
|
|
|
|
+import Archiver from "vite-plugin-archiver";
|
|
|
|
|
+import banner from "vite-plugin-banner";
|
|
|
|
|
+import { compression } from "vite-plugin-compression2";
|
|
|
|
|
+import { vitePluginFakeServer } from "vite-plugin-fake-server";
|
|
|
|
|
+import Pages from "vite-plugin-pages";
|
|
|
|
|
+import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
|
|
|
|
|
+import VueDevTools from "vite-plugin-vue-devtools";
|
|
|
|
|
+import Layouts from "vite-plugin-vue-meta-layouts";
|
|
|
|
|
|
|
|
export default function createVitePlugins(mode: string, isBuild = false) {
|
|
export default function createVitePlugins(mode: string, isBuild = false) {
|
|
|
- const viteEnv = loadEnv(mode, process.cwd())
|
|
|
|
|
|
|
+ const viteEnv = loadEnv(mode, process.cwd());
|
|
|
const vitePlugins: (PluginOption | PluginOption[])[] = [
|
|
const vitePlugins: (PluginOption | PluginOption[])[] = [
|
|
|
vue(),
|
|
vue(),
|
|
|
vueJsx(),
|
|
vueJsx(),
|
|
|
vueLegacy({
|
|
vueLegacy({
|
|
|
renderLegacyChunks: false,
|
|
renderLegacyChunks: false,
|
|
|
- modernPolyfills: [
|
|
|
|
|
- 'es.array.at',
|
|
|
|
|
- 'es.array.find-last',
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ modernPolyfills: ["es.array.at", "es.array.find-last"],
|
|
|
}),
|
|
}),
|
|
|
|
|
|
|
|
// https://github.com/vuejs/devtools-next
|
|
// https://github.com/vuejs/devtools-next
|
|
|
- viteEnv.VITE_OPEN_DEVTOOLS === 'true' && VueDevTools(),
|
|
|
|
|
|
|
+ viteEnv.VITE_OPEN_DEVTOOLS === "true" && VueDevTools(),
|
|
|
|
|
|
|
|
// https://github.com/unplugin/unplugin-auto-import
|
|
// https://github.com/unplugin/unplugin-auto-import
|
|
|
autoImport({
|
|
autoImport({
|
|
|
- imports: [
|
|
|
|
|
- 'vue',
|
|
|
|
|
- 'vue-router',
|
|
|
|
|
- 'pinia',
|
|
|
|
|
- ],
|
|
|
|
|
- dts: './src/types/auto-imports.d.ts',
|
|
|
|
|
- dirs: [
|
|
|
|
|
- './src/utils/composables/**',
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ imports: ["vue", "vue-router", "pinia"],
|
|
|
|
|
+ dts: "./src/types/auto-imports.d.ts",
|
|
|
|
|
+ dirs: ["./src/utils/composables/**"],
|
|
|
}),
|
|
}),
|
|
|
|
|
|
|
|
// https://github.com/unplugin/unplugin-vue-components
|
|
// https://github.com/unplugin/unplugin-vue-components
|
|
|
components({
|
|
components({
|
|
|
- dirs: [
|
|
|
|
|
- 'src/components',
|
|
|
|
|
- 'src/layouts/ui-kit',
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ dirs: ["src/components", "src/layouts/ui-kit"],
|
|
|
include: [/\.vue$/, /\.vue\?vue/, /\.tsx$/],
|
|
include: [/\.vue$/, /\.vue\?vue/, /\.tsx$/],
|
|
|
- dts: './src/types/components.d.ts',
|
|
|
|
|
|
|
+ dts: "./src/types/components.d.ts",
|
|
|
}),
|
|
}),
|
|
|
|
|
|
|
|
Unocss(),
|
|
Unocss(),
|
|
|
|
|
|
|
|
// https://github.com/vbenjs/vite-plugin-svg-icons
|
|
// https://github.com/vbenjs/vite-plugin-svg-icons
|
|
|
createSvgIconsPlugin({
|
|
createSvgIconsPlugin({
|
|
|
- iconDirs: [path.resolve(process.cwd(), 'src/assets/icons/')],
|
|
|
|
|
- symbolId: 'icon-[dir]-[name]',
|
|
|
|
|
|
|
+ iconDirs: [path.resolve(process.cwd(), "src/assets/icons/")],
|
|
|
|
|
+ symbolId: "icon-[dir]-[name]",
|
|
|
svgoOptions: isBuild,
|
|
svgoOptions: isBuild,
|
|
|
}),
|
|
}),
|
|
|
|
|
|
|
|
// https://github.com/condorheroblog/vite-plugin-fake-server
|
|
// https://github.com/condorheroblog/vite-plugin-fake-server
|
|
|
vitePluginFakeServer({
|
|
vitePluginFakeServer({
|
|
|
logger: !isBuild,
|
|
logger: !isBuild,
|
|
|
- include: 'src/mock',
|
|
|
|
|
|
|
+ include: "src/mock",
|
|
|
infixName: false,
|
|
infixName: false,
|
|
|
- enableProd: isBuild && viteEnv.VITE_BUILD_MOCK === 'true',
|
|
|
|
|
|
|
+ enableProd: isBuild && viteEnv.VITE_BUILD_MOCK === "true",
|
|
|
}),
|
|
}),
|
|
|
|
|
|
|
|
// https://github.com/dishait/vite-plugin-vue-meta-layouts
|
|
// https://github.com/dishait/vite-plugin-vue-meta-layouts
|
|
|
Layouts({
|
|
Layouts({
|
|
|
- defaultLayout: 'index',
|
|
|
|
|
|
|
+ defaultLayout: "index",
|
|
|
}),
|
|
}),
|
|
|
|
|
|
|
|
// https://github.com/hannoeru/vite-plugin-pages
|
|
// https://github.com/hannoeru/vite-plugin-pages
|
|
|
Pages({
|
|
Pages({
|
|
|
- dirs: 'src/views',
|
|
|
|
|
- exclude: [
|
|
|
|
|
- '**/components/**/*.vue',
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ dirs: "src/views",
|
|
|
|
|
+ exclude: ["**/components/**/*.vue"],
|
|
|
}),
|
|
}),
|
|
|
|
|
|
|
|
// https://github.com/nonzzz/vite-plugin-compression
|
|
// https://github.com/nonzzz/vite-plugin-compression
|
|
|
- viteEnv.VITE_BUILD_COMPRESS?.split(',').includes('gzip') && compression(),
|
|
|
|
|
- viteEnv.VITE_BUILD_COMPRESS?.split(',').includes('brotli') && compression({
|
|
|
|
|
- exclude: [/\.(br)$/, /\.(gz)$/],
|
|
|
|
|
- algorithm: 'brotliCompress',
|
|
|
|
|
- }),
|
|
|
|
|
-
|
|
|
|
|
- viteEnv.VITE_BUILD_ARCHIVE && Archiver({
|
|
|
|
|
- archiveType: viteEnv.VITE_BUILD_ARCHIVE,
|
|
|
|
|
- }),
|
|
|
|
|
-
|
|
|
|
|
- AppLoading('loading.html'),
|
|
|
|
|
|
|
+ viteEnv.VITE_BUILD_COMPRESS?.split(",").includes("gzip") && compression(),
|
|
|
|
|
+ viteEnv.VITE_BUILD_COMPRESS?.split(",").includes("brotli") &&
|
|
|
|
|
+ compression({
|
|
|
|
|
+ exclude: [/\.(br)$/, /\.(gz)$/],
|
|
|
|
|
+ algorithm: "brotliCompress",
|
|
|
|
|
+ }),
|
|
|
|
|
+
|
|
|
|
|
+ viteEnv.VITE_BUILD_ARCHIVE &&
|
|
|
|
|
+ Archiver({
|
|
|
|
|
+ archiveType: viteEnv.VITE_BUILD_ARCHIVE,
|
|
|
|
|
+ }),
|
|
|
|
|
+
|
|
|
|
|
+ AppLoading("loading.html"),
|
|
|
|
|
|
|
|
// https://github.com/unplugin/unplugin-turbo-console
|
|
// https://github.com/unplugin/unplugin-turbo-console
|
|
|
TurboConsole(),
|
|
TurboConsole(),
|
|
@@ -115,68 +103,71 @@ export default function createVitePlugins(mode: string, isBuild = false) {
|
|
|
`),
|
|
`),
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
- name: 'vite-plugin-debug-plugin',
|
|
|
|
|
- enforce: 'pre',
|
|
|
|
|
|
|
+ name: "vite-plugin-debug-plugin",
|
|
|
|
|
+ enforce: "pre",
|
|
|
transform: (code, id) => {
|
|
transform: (code, id) => {
|
|
|
if (/src\/main.ts$/.test(id)) {
|
|
if (/src\/main.ts$/.test(id)) {
|
|
|
- if (viteEnv.VITE_APP_DEBUG_TOOL === 'eruda') {
|
|
|
|
|
|
|
+ if (viteEnv.VITE_APP_DEBUG_TOOL === "eruda") {
|
|
|
code = code.concat(`
|
|
code = code.concat(`
|
|
|
import eruda from 'eruda'
|
|
import eruda from 'eruda'
|
|
|
eruda.init()
|
|
eruda.init()
|
|
|
- `)
|
|
|
|
|
- }
|
|
|
|
|
- else if (viteEnv.VITE_APP_DEBUG_TOOL === 'vconsole') {
|
|
|
|
|
|
|
+ `);
|
|
|
|
|
+ } else if (viteEnv.VITE_APP_DEBUG_TOOL === "vconsole") {
|
|
|
code = code.concat(`
|
|
code = code.concat(`
|
|
|
import VConsole from 'vconsole'
|
|
import VConsole from 'vconsole'
|
|
|
new VConsole()
|
|
new VConsole()
|
|
|
- `)
|
|
|
|
|
|
|
+ `);
|
|
|
}
|
|
}
|
|
|
return {
|
|
return {
|
|
|
code,
|
|
code,
|
|
|
map: null,
|
|
map: null,
|
|
|
- }
|
|
|
|
|
|
|
+ };
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
- name: 'vite-plugin-disable-devtool',
|
|
|
|
|
- enforce: 'pre',
|
|
|
|
|
|
|
+ name: "vite-plugin-disable-devtool",
|
|
|
|
|
+ enforce: "pre",
|
|
|
transform: (code, id) => {
|
|
transform: (code, id) => {
|
|
|
if (/src\/main.ts$/.test(id)) {
|
|
if (/src\/main.ts$/.test(id)) {
|
|
|
- if (viteEnv.VITE_APP_DISABLE_DEVTOOL === 'true') {
|
|
|
|
|
|
|
+ if (viteEnv.VITE_APP_DISABLE_DEVTOOL === "true") {
|
|
|
code = code.concat(`
|
|
code = code.concat(`
|
|
|
import DisableDevtool from 'disable-devtool'
|
|
import DisableDevtool from 'disable-devtool'
|
|
|
DisableDevtool()
|
|
DisableDevtool()
|
|
|
- `)
|
|
|
|
|
|
|
+ `);
|
|
|
}
|
|
}
|
|
|
return {
|
|
return {
|
|
|
code,
|
|
code,
|
|
|
map: null,
|
|
map: null,
|
|
|
- }
|
|
|
|
|
|
|
+ };
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
- name: 'vite-plugin-terminal-info',
|
|
|
|
|
- apply: 'serve',
|
|
|
|
|
|
|
+ name: "vite-plugin-terminal-info",
|
|
|
|
|
+ apply: "serve",
|
|
|
async buildStart() {
|
|
async buildStart() {
|
|
|
- const { bold, green, cyan, bgGreen, underline } = picocolors
|
|
|
|
|
|
|
+ const { bold, green, cyan, bgGreen, underline } = picocolors;
|
|
|
// eslint-disable-next-line no-console
|
|
// eslint-disable-next-line no-console
|
|
|
console.log(
|
|
console.log(
|
|
|
boxen(
|
|
boxen(
|
|
|
- `${bold(green(`由 ${bgGreen('Fantastic-admin')} 驱动`))}\n\n${underline('https://fantastic-admin.hurui.me')}\n\n当前使用:${cyan('基础版')}`,
|
|
|
|
|
|
|
+ `${bold(
|
|
|
|
|
+ green(`由 ${bgGreen("Fantastic-admin")} 驱动`)
|
|
|
|
|
+ )}\n\n${underline(
|
|
|
|
|
+ "https://fantastic-admin.hurui.me"
|
|
|
|
|
+ )}\n\n当前使用:${cyan("基础版")}`,
|
|
|
{
|
|
{
|
|
|
padding: 1,
|
|
padding: 1,
|
|
|
margin: 1,
|
|
margin: 1,
|
|
|
- borderStyle: 'double',
|
|
|
|
|
- textAlignment: 'center',
|
|
|
|
|
- },
|
|
|
|
|
- ),
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ borderStyle: "double",
|
|
|
|
|
+ textAlignment: "center",
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ );
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
- ]
|
|
|
|
|
- return vitePlugins
|
|
|
|
|
|
|
+ ];
|
|
|
|
|
+ return vitePlugins;
|
|
|
}
|
|
}
|