98 lines
3.8 KiB
TypeScript
98 lines
3.8 KiB
TypeScript
import { ConfigEnv, UserConfig, defineConfig } from "vite";
|
|
import { createHtmlPlugin } from "vite-plugin-html";
|
|
import vue from "@vitejs/plugin-vue";
|
|
import path, { resolve } from "path";
|
|
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
|
|
import usePluginImport from "vite-plugin-importer";
|
|
// import { viteMockServe } from "vite-plugin-mock";
|
|
// export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => {
|
|
|
|
export default {
|
|
plugins: [
|
|
vue(),
|
|
createSvgIconsPlugin({
|
|
iconDirs: [resolve(process.cwd(), "src/assets/icons")],
|
|
symbolId: "icon-[dir]-[name]", // symbol的id
|
|
inject: "body-last", // 插入的位置
|
|
customDomId: "__svg__icons__dom__", // svg的id
|
|
}),
|
|
// usePluginImport({
|
|
// libraryName: "view-ui-plus",
|
|
// libraryDirectory: "src/components",
|
|
// }),
|
|
// viteMockServe({
|
|
// mockPath: "./src/assets/mock",
|
|
// }),
|
|
createHtmlPlugin({
|
|
minify: true,
|
|
pages: [
|
|
{
|
|
entry: "src/main.ts",
|
|
template: "index.html",
|
|
filename: "index.html",
|
|
injectOptions: {
|
|
data: {
|
|
title: "数字基座",
|
|
},
|
|
},
|
|
},
|
|
],
|
|
}),
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
"@": path.resolve(__dirname, "./src"),
|
|
},
|
|
},
|
|
server: {
|
|
host: "localhost",
|
|
port: 8130,
|
|
// proxy: {
|
|
// // //api是自行设置的请求前缀,任何请求路径以/api开头的请求将被代理到对应的target目标
|
|
// // "/api": {
|
|
// // target: "http://localhost:8064/",
|
|
// // // target: "http://debugold.hongyucloud.com/ChildOptCourse",
|
|
// // changeOrigin: true, //需要代理跨域
|
|
// // rewrite: (path: any) => path.replace(/^\/api/, "/api/"), //路径重写,把'/api'替换为''
|
|
// // },
|
|
// },
|
|
},
|
|
// css预处理器
|
|
css: {
|
|
// preprocessorOptions: {
|
|
// scss: {
|
|
// additionalData: '@import "./src/assets/styles/utils/_varible.scss";',
|
|
// },
|
|
// },
|
|
},
|
|
base: "./",
|
|
build: {
|
|
target: "modules", //设置最终构建的浏览器兼容目标 //es2015(编译成es5) | modules
|
|
outDir: "dist", // 构建得包名 默认:dist
|
|
assetsDir: "assets", // 静态资源得存放路径文件名 assets
|
|
sourcemap: false, //构建后是否生成 source map 文件
|
|
minify: "esbuild", // 项目压缩 :boolean | 'terser' | 'esbuild'
|
|
chunkSizeWarningLimit: 1000, //chunk 大小警告的限制(以 kbs 为单位)默认:500
|
|
cssTarget: "chrome61", //防止 vite 将 rgba() 颜色转化为 #RGBA 十六进制符号的形式 (要兼容的场景是安卓微信中的 webview 时,它不支持 CSS 中的 #RGBA 十六进制颜色符号)
|
|
rollupOptions: {
|
|
input: {
|
|
main: resolve("index.html"),
|
|
},
|
|
output: {
|
|
chunkFileNames: "static/js/[name]-[hash].js",
|
|
entryFileNames: "static/js/[name]-[hash].js",
|
|
assetFileNames: (assetInfo: any) => {
|
|
if (assetInfo.type === "asset" && /\.(jpe?g|png|gif|svg)$/i.test(assetInfo.name)) {
|
|
return "static/img/[name].[hash][ext]";
|
|
}
|
|
if (assetInfo.type === "asset" && /\.(ttf|woff|woff2|eot)$/i.test(assetInfo.name)) {
|
|
return "static/fonts/[name].[hash][ext]";
|
|
}
|
|
return "static/[ext]/[name]-[hash].[ext]";
|
|
},
|
|
},
|
|
manualEntrypoint: "index.html",
|
|
},
|
|
},
|
|
};
|