hbt-prevention-ui/vue.config.js

124 lines
4.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const { defineConfig } = require("@vue/cli-service");
const CompressionPlugin = require("compression-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const path = require("path");
const resolve = (dir) => {
return path.join(__dirname, dir);
};
module.exports = defineConfig({
publicPath: process.env.VUE_APP_EXPOSES_URL,
productionSourceMap: process.env.NODE_ENV !== "production",
transpileDependencies: true,
lintOnSave: true, // 在保存时校验格式
runtimeCompiler: true,
css: {
loaderOptions: {
scss: {
additionalData: `@import "@/assets/common/scss/hbt-base.scss";`,
},
},
},
configureWebpack: {
optimization: {
minimize: true,
// 使用 UglifyJsPlugin 插件
// 如果已经配置了 optimization.minimizer 使用其它插件,请在此处对应修改
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
// 去除未定义变量的报错
warnings: false,
// 去除 console.log
drop_console: true,
// 去除 debugger
drop_debugger: true,
},
},
}),
],
// 用于生成文件的代码块最小化的切割
splitChunks: {
minSize: 10000,
maxSize: 250000,
},
},
plugins: [
// 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: "prevention",
filename: "prevention.js",
exposes: {
"./store": "./src/store/prevention/index.ts", // 包保责任制
"./preventionBlank": "./src/views/blank.component.vue", // 包保责任制
"./majorHazard":
"./src/views/responsibility/majorHazard/majorHazard.component.vue", // 包保责任制
"./checkTasks":
"./src/views/responsibility/checkTasks/checkTasks.component.vue", // 排查任务
"./checkResumption":
"./src/views/estimate/checkResumption.component.vue", // 排查任务履职情况
"./hiddendangerResumption":
"./src/views/estimate/hiddendangerResumption.component.vue", // 隐患执行履职情况
"./publicityResumption":
"./src/views/estimate/publicityResumption/publicityResumption.component.vue", // 履职情况公示
},
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: {
client: {
overlay: false,
},
proxy: {
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_GATEWAY_URL]: {
target: process.env.VUE_APP_BASE_API_URL,
changeOrigin: true,
pathRewrite: {
["^" + process.env.VUE_APP_GATEWAY_URL]: "",
},
},
},
// disableHostCheck: true
},
});