const { defineConfig } = require('@vue/cli-service') const path = require('path') const AutoImport = require('unplugin-auto-import/webpack') const Components = require('unplugin-vue-components/webpack') const { ElementPlusResolver, VantResolver } = require('unplugin-vue-components/resolvers') const ElementPlus = require('unplugin-element-plus/webpack') const CompressionPlugin = require('compression-webpack-plugin') const Timestamp= new Date().getTime() function resolve (dir) { return path.join(__dirname, dir) } module.exports = defineConfig({ transpileDependencies: true, devServer: { proxy: { // 配置跨域 '/api': { target: 'http://duanju.wenxingshuju.com', changeOrigin: true, // 允许跨域 pathRewrite: { '^/api': '' // 请求的时候使用这个api就可以 } } } }, lintOnSave: false, publicPath: process.env.NODE_ENV === 'production' ? './' : '/', outputDir: 'dist', productionSourceMap: false,//打包不到.map文件 configureWebpack: { // provide the app's title in webpack's name field, so that // it can be accessed in index.html to inject the correct title. resolve: { alias: { '@': resolve('src') } }, output: { // 输出重构 打包编译后的 文件名称 filename: `js/[name].[hash].${Timestamp}.js`, chunkFilename: `js/[name].[hash].${Timestamp}.js` }, plugins: [ AutoImport({ resolvers: [ElementPlusResolver()], }), Components({ resolvers: [ElementPlusResolver(), VantResolver()], }), ElementPlus(), new CompressionPlugin({ test: /\.js$|\.html$|\.css/, //匹配文件名 threshold: 10240, //对超过10k的数据进行压缩 deleteOriginalAssets: false //是否删除原文件 }), ], }, })