You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

116 lines
3.1 KiB

const path = require("path");
// const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const ProgressBarPlugin = require("progress-bar-webpack-plugin");
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const IS_PROD = process.env.NODE_ENV === "production";
const chalk = require("chalk");
const baseUrl = process.env.VUE_APP_BASE_URL;
console.log(baseUrl);
const proxyObj = {
[`${baseUrl}`]: {
target: process.env.VUE_APP_URL,
// target: "https://apinvoice-uat.baozun.com",
ws: true,
changeOrigin: true,
pathRewrite: {
[`^${baseUrl}`]: "",
},
},
// "/ws": {
// target: "https://apis.map.qq.com",
// ws: true,
// changeOrigin: true,
// pathRewrite: {
// "^/ws": ""
// }
// }
};
const OUT_DIR = process.env.VUE_APP_ZIP_NAME;
const PATH = baseUrl.split("/api")[0];
const PUBLIC_PATH = PATH == "" ? "/" : PATH;
function resolve(dir) {
return path.join(__dirname, dir);
}
module.exports = {
lintOnSave: true,
publicPath: PUBLIC_PATH,
assetsDir: "./",
productionSourceMap: false,
outputDir: OUT_DIR,
parallel: require("os").cpus().length > 1,
configureWebpack: (config) => {
if (IS_PROD) {
config.plugins.push(
new ProgressBarPlugin({
format:
" build [:bar] " +
chalk.green.bold(":percent") +
" (:elapsed seconds)",
clear: false,
})
// new BundleAnalyzerPlugin()
);
config.optimization = {
runtimeChunk: "single",
splitChunks: {
chunks: "all",
maxInitialRequests: Infinity,
minSize: 20000,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/
)[1];
return `npm.${packageName.replace("@", "")}`;
},
},
},
},
// usedExports: true //treeShaking
};
}
},
devServer: {
open: true,
proxy: proxyObj,
},
pluginOptions: {
"style-resources-loader": {
preProcessor: "less",
patterns: [
path.resolve(__dirname, "./src/style/common.less"),
path.resolve(__dirname, "./src/style/element.less"),
], // 引入全局样式变量
},
},
// webpack chian
chainWebpack: (config) => {
/* if (IS_PROD) {
// 对图片资源进行打包 可减小体积
config.module
.rule("images")
.test(/\.(png|jpe?g|gif|webp)(\?.*)?$/)
.use("image-webpack-loader")
.loader("image-webpack-loader")
.options({
bypassOnDebug: true,
})
.end()
.use("url-loader")
.loader("file-loader")
.options({
name: "assets/[name].[hash:8].[ext]",
})
.end();
} */
config.resolve.alias
.set("@", resolve("src"))
.set("@api", resolve("src/api"))
.set("@utils", resolve("src/utils"))
.set("@comp", resolve("src/components"));
},
};