1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import { defineConfig } from "vite";
- import vue from "@vitejs/plugin-vue";
- import vueJsx from "@vitejs/plugin-vue-jsx";
- import legacy from "@vitejs/plugin-legacy";
- import { resolve } from "path";
- import postCssPxToRem from "postcss-pxtorem";
- import { visualizer } from "rollup-plugin-visualizer";
- import viteCompression from "vite-plugin-compression";
- // https://vitejs.dev/config/
- export default defineConfig({
- base: "./",
- resolve: {},
- // assetsInclude: ['**/*.html'],
- plugins: [
- // mkcert(), // 本地https
- // viteCompression({
- // algorithm: "gzip", // 指定压缩算法为gzip,[ 'gzip' , 'brotliCompress' ,'deflate' , 'deflateRaw']
- // ext: ".gz", // 指定压缩后的文件扩展名为.gz
- // threshold: 10240, // 仅对文件大小大于threshold的文件进行压缩,默认为10KB
- // deleteOriginFile: false, // 是否删除原始文件,默认为false
- // filter: /\.(js|css|json|html|ico|svg)(\?.*)?$/i, // 匹配要压缩的文件的正则表达式,默认为匹配.js、.css、.json、.html、.ico和.svg文件
- // compressionOptions: { level: 9 }, // 指定gzip压缩级别,默认为9(最高级别)
- // verbose: true, //是否在控制台输出压缩结果
- // disable: false, //是否禁用插件
- // }),
- legacy({
- targets: ["Chrome 63"],
- additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
- modernPolyfills: true,
- }),
- vue(),
- vueJsx(),
- visualizer({ open: true }), // 自动开启分析页面
- ],
- css: {
- postcss: {
- plugins: [
- postCssPxToRem({
- rootValue: 37.5,
- propList: ["*"],
- selectorBlackList: [".norem"],
- }),
- ],
- },
- },
- build: {
- minify: 'terser', // 启用 terser 压缩
- terserOptions: {
- compress: {
- pure_funcs: ['console.log'], // 只删除 console.log
- //drop_console: true, // 删除所有 console
- drop_debugger: true, // 删除 debugger
- }
- },
- rollupOptions: {
- input: {
- instrument: resolve(__dirname, "instrument.html"),
- },
- output: {
- // 最小化拆分包
- manualChunks(id) {
- if (id.includes("osmd-extended")) {
- // 通过拆分包的方式将所有来自osmd-extended的模块打包到单独的chunk中
- return id
- .toString()
- .split("osmd-extended/")[1]
- .split("/")[0]
- .toString();
- }
- },
- chunkFileNames: "js/[name]-[hash].js", // 引入文件名的名称
- entryFileNames: "js/[name]-[hash].js", // 包的入口文件名称
- assetFileNames: "[ext]/[name]-[hash].[ext]", // 资源文件像 字体,图片等
- },
- },
- },
- server: {
- cors: true,
- port: 3000,
- // https: true,
- proxy: {
- "^/instrument/.*": {
- target: "https://test.gym.lexiaoya.cn",
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/instrument/, ""),
- },
- },
- },
- preview: {
- port: 3000,
- host: "192.168.3.114",
- },
- });
- // vite.config.js
|