const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const OptimizeCssnanoPlugin = require("@intervolga/optimize-cssnano-plugin");
const path = require("path");
const isProd =
process.env.VUE_APP_FLAG === "production" ||
process.env.VUE_APP_FLAG === "prod";
const name = process.env.VUE_APP_TITLE || "clean-front";
var plugins = [
new OptimizeCssnanoPlugin({
sourceMap: false,
cssnanoOptions: {
preset: [
"default",
{
mergeLonghand: false,
cssDeclarationSorter: false,
},
],
},
}),
];
console.log("================================isProd", isProd);
if (isProd) {
plugins.unshift(
new UglifyJsPlugin({
uglifyOptions: {
compress: {
drop_debugger: true,
drop_console: true,
},
},
sourceMap: false,
parallel: true,
})
);
}
const publicPathObj = {
development: "/",
test: "***",
production:
"***",
};
console.log("process.env.VUE_APP_FLAG]: ", process.env.VUE_APP_FLAG);
module.exports = {
publicPath: publicPathObj[process.env.VUE_APP_FLAG],
outputDir: isProd ? "target/prod" : "target/test",
assetsDir: "static",
configureWebpack: {
name: name,
devtool:
process.env.VUE_APP_FLAG != "development" ? false : "eval-source-map",
resolve: {
alias: {
"@": path.join(__dirname, "src"),
"~": path.join(__dirname),
},
},
plugins: plugins,
optimization: {
splitChunks: {
cacheGroups: {
common: {
name: "chunk-common",
chunks: "initial",
minChunks: 1,
maxInitialRequests: 5,
minSize: 0,
priority: 1,
reuseExistingChunk: true,
},
vendors: {
name: "chunk-vendors",
test: /[\\/]node_modules[\\/]/,
chunks: "initial",
maxSize: 600000,
maxInitialRequests: 20,
priority: 2,
reuseExistingChunk: true,
enforce: true,
},
antDesignVue: {
name: "chunk-ant-design-vue",
test: /[\\/]node_modules[\\/]ant-design-vue[\\/]/,
chunks: "initial",
priority: 3,
maxSize: 600000,
reuseExistingChunk: true,
enforce: true,
},
styles: {
name: "styles",
test: /\.css$/,
chunks: "all",
enforce: true,
},
},
},
},
devServer: {
headers: {
"Access-Control-Allow-Origin": "*",
},
},
},
devServer: {
open: true,
port: 8080,
host: "0.0.0.0",
https: false,
hotOnly: true,
disableHostCheck: true,
proxy: {
"/api": {
target:
"https://www.fastmock.site/mock/08e002ebed3dde51cdd5e7a73071b386/mockApi",
changeOrigin: true,
ws: true,
pathRewrite: {
"^/api": "/",
},
},
},
},
};