初始提交
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import autoImport from 'unplugin-auto-import/vite'
|
||||
|
||||
export default function createAutoImport() {
|
||||
return autoImport({
|
||||
imports: [
|
||||
'vue',
|
||||
'vue-router',
|
||||
'pinia'
|
||||
],
|
||||
dts: false
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import compression from 'vite-plugin-compression'
|
||||
|
||||
export default function createCompression(env) {
|
||||
const { VITE_BUILD_COMPRESS } = env
|
||||
const plugin = []
|
||||
if (VITE_BUILD_COMPRESS) {
|
||||
const compressList = VITE_BUILD_COMPRESS.split(',')
|
||||
if (compressList.includes('gzip')) {
|
||||
// 开启 gzip 后,部署环境需同步启用静态文件解压支持。
|
||||
plugin.push(
|
||||
compression({
|
||||
ext: '.gz',
|
||||
deleteOriginFile: false
|
||||
})
|
||||
)
|
||||
}
|
||||
if (compressList.includes('brotli')) {
|
||||
plugin.push(
|
||||
compression({
|
||||
ext: '.br',
|
||||
algorithm: 'brotliCompress',
|
||||
deleteOriginFile: false
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
return plugin
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import monacoEditorEsmPlugin from 'vite-plugin-monaco-editor-esm'
|
||||
|
||||
import createAutoImport from './auto-import'
|
||||
import createSvgIcon from './svg-icon'
|
||||
import createCompression from './compression'
|
||||
import createSetupExtend from './setup-extend'
|
||||
|
||||
const monacoWorkers = [
|
||||
{
|
||||
label: 'editorWorkerService',
|
||||
entry: 'monaco-editor/esm/vs/editor/editor.worker.js'
|
||||
},
|
||||
{
|
||||
label: 'css',
|
||||
entry: 'monaco-editor/esm/vs/language/css/css.worker.js'
|
||||
},
|
||||
{
|
||||
label: 'html',
|
||||
entry: 'monaco-editor/esm/vs/language/html/html.worker.js'
|
||||
},
|
||||
{
|
||||
label: 'json',
|
||||
entry: 'monaco-editor/esm/vs/language/json/json.worker.js'
|
||||
},
|
||||
{
|
||||
label: 'typescript',
|
||||
entry: 'monaco-editor/esm/vs/language/typescript/ts.worker.js'
|
||||
}
|
||||
]
|
||||
|
||||
export default function createVitePlugins(viteEnv, isBuild = false) {
|
||||
const vitePlugins = [vue()]
|
||||
vitePlugins.push(createAutoImport())
|
||||
vitePlugins.push(createSetupExtend())
|
||||
vitePlugins.push(monacoEditorEsmPlugin({
|
||||
languageWorkers: [],
|
||||
customWorkers: monacoWorkers
|
||||
}))
|
||||
vitePlugins.push(createSvgIcon(isBuild))
|
||||
isBuild && vitePlugins.push(...createCompression(viteEnv))
|
||||
return vitePlugins
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import setupExtend from 'unplugin-vue-setup-extend-plus/vite'
|
||||
|
||||
export default function createSetupExtend() {
|
||||
return setupExtend({})
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
||||
import path from 'path'
|
||||
|
||||
export default function createSvgIcon(isBuild) {
|
||||
return createSvgIconsPlugin({
|
||||
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons/svg')],
|
||||
symbolId: 'icon-[dir]-[name]',
|
||||
svgoOptions: isBuild
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user