赞
踩
废话不多说,直接开始
下面是npm命令,但是有些库npm在国内安装会报错,建议换yarn
npm install --save nprogress sass axios pinia qs lodash moment @types/node unplugin-auto-import unplugin-vue-components @element-plus/icons-vue element-plus ts-md5 pinia-plugin-persistedstate vite-plugin-compression @vitejs/plugin-legacy vite-plugin-imagemin -D
暂时就这么多吧,欢迎补充,如果不对的地方欢迎大佬指点
以下是vite.config.ts 文件详情
import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import AutoImport from 'unplugin-auto-import/vite' import Components from 'unplugin-vue-components/vite' import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' import viteCompression from 'vite-plugin-compression' import legacyPlugin from '@vitejs/plugin-legacy' import { resolve } from "path"; // https://vitejs.dev/config/ export default defineConfig({ resolve: { alias: { '@': resolve('./src') } }, plugins: [ vue(), // 自动导入ui库 AutoImport({ resolvers: [ElementPlusResolver()], }), Components({ resolvers: [ElementPlusResolver()], }), // 开启gzip压缩 viteCompression({ verbose: true, disable: false, threshold: 10240, algorithm: 'gzip', ext: '.gz', }), // 兼容旧版浏览器 legacyPlugin({ targets: ['chrome 52'], additionalLegacyPolyfills: ['regenerator-runtime/runtime'], renderLegacyChunks: true, polyfills: [ 'es.symbol', 'es.array.filter', 'es.promise', 'es.promise.finally', 'es/map', 'es/set', 'es.array.for-each', 'es.object.define-properties', 'es.object.define-property', 'es.object.get-own-property-descriptor', 'es.object.get-own-property-descriptors', 'es.object.keys', 'es.object.to-string', 'web.dom-collections.for-each', 'esnext.global-this', 'esnext.string.match-all' ] }) ], // 打包优化 build: { minify: 'terser', rollupOptions: { output: { chunkFileNames: 'static/js/[name]-[hash].js', entryFileNames: 'static/js/[name]-[hash].js', assetFileNames: 'static/[ext]/[name]-[hash].[ext]', manualChunks(id) { if (id.includes('node_modules')) { return id.toString().split('node_modules/')[1].split('/')[0].toString(); } } } }, // build时去除log terserOptions: { compress: { drop_console: true, drop_debugger: true, }, }, }, })
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。