const { defineConfig } = require('@vue/cli-service') const CompressionPlugin = require('compression-webpack-plugin') const webpack = require("webpack"); const path = require('path') const resolve = (dir)=>{ return path.join(__dirname, dir) } module.exports = defineConfig({ productionSourceMap:process.env.NODE_ENV!=="production", transpileDependencies: true, lintOnSave: true, // 在保存时校验格式 runtimeCompiler:true, css:{ loaderOptions:{ scss:{ additionalData:`@import "@/assets/common/scss/hbt-base.scss";` } } }, configureWebpack: { plugins: [ new webpack.ProvidePlugin({ $:"jquery", jQuery:"jquery", "window.jQuery":"jquery" }), // http://doc.hbt.vip/hbt-vue/other/faq.html#使用gzip解压缩静态文件 new CompressionPlugin({ cache: false, // 不启用文件缓存 test: /\.(js|css|html)?$/i, // 压缩文件格式 filename: '[path].gz[query]', // 压缩后的文件名 algorithm: 'gzip', // 使用gzip压缩 minRatio: 0.8 // 压缩率小于1才会压缩 }) ], }, chainWebpack: config => { config.extensions = ['.js', '.ts','.scss', '.vue', '.html']; config.plugin('module-federation-plugin').use(require("webpack").container.ModuleFederationPlugin,[{ name: "test", filename: "test.js", remotes: { common:`common@${process.env.VUE_APP_REMOTES_URL}/common.js` }, shared:require("./package.json").dependencies, }]); config.module .rule("html") .test(/\.html$/) .use('html-loader') .loader('html-loader')//预读,识别html文件 .end() // set svg-sprite-loader config.module .rule('svg') .exclude.add(resolve('src/assets')) .end() config.module .rule('icons') .test(/\.svg$/) .include.add(resolve('src/assets')) .end() .use('svg-sprite-loader') .loader('svg-sprite-loader') .options({ symbolId: 'icon-[name]' }) .end() }, devServer: { proxy: { // detail: https://cli.vuejs.org/config/#devserver-proxy [process.env.VUE_APP_BASE_API_URL]: { target: `http://119.45.158.12:8081`, changeOrigin: true, pathRewrite: { ['^' + process.env.VUE_APP_BASE_API_URL]: '' } } }, // disableHostCheck: true }, })