ko
Version:
build & lint library
104 lines (103 loc) • 4.48 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const webpack_1 = require("webpack");
const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
const case_sensitive_paths_webpack_plugin_1 = __importDefault(require("case-sensitive-paths-webpack-plugin"));
const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin"));
const webpackbar_1 = __importDefault(require("webpackbar"));
const clean_webpack_plugin_1 = require("clean-webpack-plugin");
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
const auto_polyfills_webpack_plugin_1 = __importDefault(require("@dtinsight/auto-polyfills-webpack-plugin"));
const friendly_errors_webpack_plugin_1 = __importDefault(require("@nuxt/friendly-errors-webpack-plugin"));
const purge_cache_webpack_plugin_1 = __importDefault(require("./custom-plugins/purge-cache-webpack-plugin"));
function getPlugins(opts) {
const { isProd, htmlTemplate, htmlChunks, copy, analyzer, autoPolyfills, serve: { host, port, compilationSuccessInfo }, } = opts;
const htmlOptions = {
template: htmlTemplate,
};
if (htmlChunks) {
htmlOptions.chunks = htmlChunks;
}
return [
new webpack_1.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
}),
isProd &&
new webpack_1.optimize.SplitChunksPlugin({
chunks: 'all',
minSize: 30000,
maxSize: 600000,
minChunks: 1,
automaticNameDelimiter: '_',
cacheGroups: {
baseCommon: {
test: new RegExp(`[\\/]node_modules[\\/](${[
'react',
'react-router',
'react-dom',
'react-redux',
'redux',
'react-router-redux',
].join('|')})`),
priority: 1,
},
antd: {
name: 'antd',
test: /[\\/]node_modules[\\/]antd[\\/]/,
chunks: 'initial',
},
lodash: {
name: 'lodash',
test: /[\\/]node_modules[\\/]lodash[\\/]/,
chunks: 'initial',
priority: -10,
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
}),
isProd &&
new mini_css_extract_plugin_1.default({
filename: 'css/[name].[contenthash].css',
chunkFilename: 'css/[id].[contenthash].css',
}),
new case_sensitive_paths_webpack_plugin_1.default(),
new html_webpack_plugin_1.default(htmlOptions),
copy &&
new copy_webpack_plugin_1.default({
patterns: copy,
}),
new webpackbar_1.default(),
new clean_webpack_plugin_1.CleanWebpackPlugin({
verbose: false,
dry: false,
}),
new react_refresh_webpack_plugin_1.default({
overlay: false,
}),
analyzer && new webpack_bundle_analyzer_1.BundleAnalyzerPlugin(),
!isProd &&
new friendly_errors_webpack_plugin_1.default({
compilationSuccessInfo: compilationSuccessInfo ?? {
messages: [`Your application is running at http://${host}:${port}`],
notes: [],
},
}),
!isProd && new purge_cache_webpack_plugin_1.default(),
isProd &&
autoPolyfills &&
(typeof autoPolyfills === 'boolean'
? new auto_polyfills_webpack_plugin_1.default()
: new auto_polyfills_webpack_plugin_1.default(autoPolyfills)),
].filter(Boolean);
}
exports.default = getPlugins;