代码拉取完成,页面将自动刷新
同步操作将从 Hooray/Fantastic-startkit 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import html from 'vite-plugin-html'
import svgIcon from 'vite-plugin-svg-icons'
import spritesmith from 'vite-plugin-spritesmith'
import compression from 'vite-plugin-compression'
import { viteMockServe as mock } from 'vite-plugin-mock'
const fs = require('fs')
const path = require('path')
// https://vitejs.dev/config/
export default ({ mode, command }) => {
// 全局 scss 资源
const scssResources = []
fs.readdirSync('src/assets/styles/resources').map(dirname => {
if (fs.statSync(`src/assets/styles/resources/${dirname}`).isFile()) {
scssResources.push(`@import "src/assets/styles/resources/${dirname}";`)
}
})
// css 精灵图相关
const spriteDirnames = []
fs.readdirSync('src/assets/sprites').map(dirname => {
if (fs.statSync(`src/assets/sprites/${dirname}`).isDirectory()) {
spriteDirnames.push(dirname)
// css 精灵图生成的 scss 文件也需要放入全局 scss 资源
scssResources.push(`@import "src/assets/sprites/_${dirname}.scss";`)
}
})
const spritesmithTasks = []
spriteDirnames.map(item => {
spritesmithTasks.push(
spritesmith({
watch: command === 'serve',
src: {
cwd: `./src/assets/sprites/${item}`,
glob: '*.png'
},
target: {
image: `./src/assets/sprites/${item}.png`,
css: [
[
`./src/assets/sprites/_${item}.scss`,
{
format: 'handlebars_based_template'
}
]
]
},
apiOptions: {
cssImageRef: `@/assets/sprites/${item}.png`,
spritesheet_info: {
name: item,
format: 'handlebars_based_template'
}
},
customTemplates: {
handlebars_based_template: './scss.template.hbs'
},
spritesmithOptions: {
algorithm: 'binary-tree',
padding: 10
}
})
)
})
const compressionTasks = []
if (loadEnv(mode, process.cwd()).VITE_BUILD_COMPRESS != undefined) {
loadEnv(mode, process.cwd()).VITE_BUILD_COMPRESS.split(',').map(v => {
if (v == 'gzip') {
compressionTasks.push(compression())
}
if (v == 'brotli') {
compressionTasks.push(
compression({
algorithm: 'brotliCompress'
})
)
}
})
}
return defineConfig({
// 开发服务器选项 https://cn.vitejs.dev/config/#server-options
server: {
open: true,
proxy: {
'/proxy': {
target: loadEnv(mode, process.cwd()).VITE_APP_API_BASEURL,
changeOrigin: command === 'serve' && loadEnv(mode, process.cwd()).VITE_OPEN_PROXY == 'true',
rewrite: path => path.replace(/\/proxy/, '')
}
}
},
// 构建选项 https://cn.vitejs.dev/config/#server-fsserve-root
build: {
outDir: mode == 'production' ? 'dist' : `dist-${mode}`,
sourcemap: loadEnv(mode, process.cwd()).VITE_BUILD_SOURCEMAP == 'true',
terserOptions: {
compress: {
drop_console: loadEnv(mode, process.cwd()).VITE_BUILD_DROP_CONSOLE == 'true'
}
}
},
plugins: [
vue(),
html({
inject: {
injectData: {
title: loadEnv(mode, process.cwd()).VITE_APP_TITLE,
debugTool: loadEnv(mode, process.cwd()).VITE_APP_DEBUG_TOOL
}
},
minify: true
}),
svgIcon({
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons/')],
symbolId: 'icon-[dir]-[name]'
}),
...compressionTasks,
mock({
mockPath: 'src/mock',
injectCode: `
import { setupProdMockServer } from './mockProdServer';
setupProdMockServer();
`
}),
...spritesmithTasks
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src')
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: scssResources.join('')
}
}
}
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。