@umijs/bundler-webpack 4.0.0-rc.7 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/client/client.js +65 -37
- package/client/constants.js +9 -0
- package/compiled/babel-loader/index.js +2 -2
- package/compiled/copy-webpack-plugin/{576.index.js → 939.index.js} +11 -11
- package/compiled/copy-webpack-plugin/index.js +12 -12
- package/compiled/css-minimizer-webpack-plugin/index.js +7 -7
- package/compiled/cssnano/index.js +6 -6
- package/compiled/fork-ts-checker-webpack-plugin/index.js +7 -13
- package/compiled/{tapable → react-refresh}/LICENSE +6 -6
- package/compiled/react-refresh/index.js +9 -7
- package/compiled/react-refresh/package.json +1 -0
- package/compiled/webpack/BasicEffectRulePlugin.js +1 -0
- package/compiled/webpack/BasicMatcherRulePlugin.js +1 -0
- package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
- package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
- package/compiled/webpack/ObjectMatcherRulePlugin.js +1 -0
- package/compiled/webpack/RuleSetCompiler.js +1 -0
- package/compiled/webpack/UseEffectRulePlugin.js +1 -0
- package/compiled/webpack/deepImports.json +6 -1
- package/compiled/webpack/index.js +3978 -3167
- package/compiled/webpack/types.d.ts +606 -171
- package/compiled/webpack-dev-middleware/index.js +8 -7
- package/compiled/webpack-manifest-plugin/index.js +1 -1
- package/dist/build.d.ts +1 -0
- package/dist/build.js +49 -56
- package/dist/cli.js +6 -15
- package/dist/client/client.js +52 -50
- package/dist/config/_sampleFeature.js +6 -17
- package/dist/config/assetRules.js +44 -55
- package/dist/config/bundleAnalyzerPlugin.js +12 -23
- package/dist/config/compressPlugin.js +89 -70
- package/dist/config/config.d.ts +2 -0
- package/dist/config/config.js +181 -179
- package/dist/config/copyPlugin.js +29 -40
- package/dist/config/cssRules.js +114 -83
- package/dist/config/definePlugin.js +11 -19
- package/dist/config/detectDeadCodePlugin.js +16 -21
- package/dist/config/fastRefreshPlugin.js +11 -22
- package/dist/config/forkTSCheckerPlugin.js +11 -22
- package/dist/config/harmonyLinkingErrorPlugin.js +3 -14
- package/dist/config/ignorePlugin.js +10 -21
- package/dist/config/javaScriptRules.d.ts +1 -0
- package/dist/config/javaScriptRules.js +152 -135
- package/dist/config/manifestPlugin.d.ts +1 -1
- package/dist/config/manifestPlugin.js +10 -18
- package/dist/config/miniCSSExtractPlugin.js +15 -23
- package/dist/config/nodePolyfill.js +14 -20
- package/dist/config/nodePrefixPlugin.d.ts +11 -0
- package/dist/config/nodePrefixPlugin.js +14 -0
- package/dist/config/progressPlugin.js +7 -18
- package/dist/config/purgecssWebpackPlugin.js +15 -26
- package/dist/config/speedMeasureWebpackPlugin.js +12 -23
- package/dist/config/ssrPlugin.d.ts +11 -0
- package/dist/config/ssrPlugin.js +66 -0
- package/dist/config/svgRules.js +44 -47
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +7 -1
- package/dist/dev.d.ts +4 -0
- package/dist/dev.js +115 -94
- package/dist/index.d.ts +3 -0
- package/dist/index.js +16 -0
- package/dist/loader/svgr.js +4 -13
- package/dist/loader/swc.js +9 -14
- package/dist/plugins/ProgressPlugin.js +3 -3
- package/dist/plugins/RuntimePublicPathPlugin.js +4 -1
- package/dist/schema.js +24 -8
- package/dist/server/server.d.ts +3 -1
- package/dist/server/server.js +165 -150
- package/dist/server/ws.d.ts +7 -2
- package/dist/swcPlugins/autoCSSModules.js +3 -1
- package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
- package/dist/swcPlugins/changeImportFromString.js +10 -0
- package/dist/swcPlugins/lockCoreJS.js +3 -2
- package/dist/types.d.ts +3 -0
- package/dist/utils/getEsBuildTarget.d.ts +5 -0
- package/dist/utils/getEsBuildTarget.js +12 -0
- package/package.json +23 -21
- package/compiled/tapable/index.js +0 -1
- package/compiled/tapable/package.json +0 -1
- package/compiled/tapable/tapable.d.ts +0 -116
- package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +0 -11
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +0 -63
- package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +0 -10
- package/dist/plugins/ParcelCSSMinifyPlugin.js +0 -75
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -16,68 +7,96 @@ exports.addCompressPlugin = void 0;
|
|
|
16
7
|
// @ts-ignore
|
|
17
8
|
const css_minimizer_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/css-minimizer-webpack-plugin"));
|
|
18
9
|
const terser_webpack_plugin_1 = __importDefault(require("../../compiled/terser-webpack-plugin"));
|
|
19
|
-
const ESBuildCSSMinifyPlugin_1 = __importDefault(require("../plugins/ESBuildCSSMinifyPlugin"));
|
|
20
|
-
const ParcelCSSMinifyPlugin_1 = require("../plugins/ParcelCSSMinifyPlugin");
|
|
21
10
|
const types_1 = require("../types");
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
else if (jsMinifier === types_1.JSMinifier.terser) {
|
|
39
|
-
minify = terser_webpack_plugin_1.default.terserMinify;
|
|
40
|
-
}
|
|
41
|
-
else if (jsMinifier === types_1.JSMinifier.swc) {
|
|
42
|
-
minify = terser_webpack_plugin_1.default.swcMinify;
|
|
43
|
-
}
|
|
44
|
-
else if (jsMinifier === types_1.JSMinifier.uglifyJs) {
|
|
45
|
-
minify = terser_webpack_plugin_1.default.uglifyJsMinify;
|
|
46
|
-
}
|
|
47
|
-
else if (jsMinifier !== types_1.JSMinifier.none) {
|
|
48
|
-
throw new Error(`Unsupported jsMinifier ${userConfig.jsMinifier}.`);
|
|
49
|
-
}
|
|
50
|
-
if (jsMinifier !== types_1.JSMinifier.none) {
|
|
51
|
-
config.optimization.minimizer(`js-${jsMinifier}`).use(terser_webpack_plugin_1.default, [
|
|
52
|
-
{
|
|
53
|
-
minify,
|
|
54
|
-
terserOptions: userConfig.jsMinifierOptions,
|
|
55
|
-
},
|
|
56
|
-
]);
|
|
57
|
-
}
|
|
58
|
-
if (cssMinifier === types_1.CSSMinifier.esbuild) {
|
|
59
|
-
config.optimization
|
|
60
|
-
.minimizer(`css-${cssMinifier}`)
|
|
61
|
-
.use(ESBuildCSSMinifyPlugin_1.default, [userConfig.cssMinifierOptions]);
|
|
62
|
-
}
|
|
63
|
-
else if (cssMinifier === types_1.CSSMinifier.cssnano) {
|
|
64
|
-
config.optimization
|
|
65
|
-
.minimizer(`css-${cssMinifier}`)
|
|
66
|
-
.use(css_minimizer_webpack_plugin_1.default, [
|
|
67
|
-
{
|
|
68
|
-
minimizerOptions: userConfig.cssMinifierOptions,
|
|
69
|
-
parallel: true,
|
|
70
|
-
},
|
|
71
|
-
]);
|
|
72
|
-
}
|
|
73
|
-
else if (cssMinifier === types_1.CSSMinifier.parcelCSS) {
|
|
74
|
-
config.optimization
|
|
75
|
-
.minimizer(`css-${cssMinifier}`)
|
|
76
|
-
.use(ParcelCSSMinifyPlugin_1.ParcelCSSMinifyPlugin);
|
|
77
|
-
}
|
|
78
|
-
else if (cssMinifier !== types_1.CSSMinifier.none) {
|
|
79
|
-
throw new Error(`Unsupported cssMinifier ${userConfig.cssMinifier}.`);
|
|
80
|
-
}
|
|
11
|
+
const getEsBuildTarget_1 = require("../utils/getEsBuildTarget");
|
|
12
|
+
async function addCompressPlugin(opts) {
|
|
13
|
+
const { config, userConfig, env } = opts;
|
|
14
|
+
const jsMinifier = userConfig.jsMinifier || types_1.JSMinifier.esbuild;
|
|
15
|
+
const cssMinifier = userConfig.cssMinifier || types_1.CSSMinifier.esbuild;
|
|
16
|
+
if (env === types_1.Env.development ||
|
|
17
|
+
process.env.COMPRESS === 'none' ||
|
|
18
|
+
(jsMinifier === types_1.JSMinifier.none && cssMinifier === types_1.CSSMinifier.none)) {
|
|
19
|
+
config.optimization.minimize(false);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
config.optimization.minimize(true);
|
|
23
|
+
// esbuild transform only allow `string[]` as target
|
|
24
|
+
const esbuildTarget = (0, getEsBuildTarget_1.getEsBuildTarget)({
|
|
25
|
+
targets: userConfig.targets || {},
|
|
81
26
|
});
|
|
27
|
+
let minify;
|
|
28
|
+
let terserOptions;
|
|
29
|
+
if (jsMinifier === types_1.JSMinifier.esbuild) {
|
|
30
|
+
minify = terser_webpack_plugin_1.default.esbuildMinify;
|
|
31
|
+
terserOptions = {
|
|
32
|
+
target: esbuildTarget,
|
|
33
|
+
// remove all comments
|
|
34
|
+
legalComments: 'none',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
else if (jsMinifier === types_1.JSMinifier.terser) {
|
|
38
|
+
minify = terser_webpack_plugin_1.default.terserMinify;
|
|
39
|
+
terserOptions = {
|
|
40
|
+
format: {
|
|
41
|
+
comments: false,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
else if (jsMinifier === types_1.JSMinifier.swc) {
|
|
46
|
+
minify = terser_webpack_plugin_1.default.swcMinify;
|
|
47
|
+
}
|
|
48
|
+
else if (jsMinifier === types_1.JSMinifier.uglifyJs) {
|
|
49
|
+
minify = terser_webpack_plugin_1.default.uglifyJsMinify;
|
|
50
|
+
terserOptions = {
|
|
51
|
+
output: {
|
|
52
|
+
comments: false,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
else if (jsMinifier !== types_1.JSMinifier.none) {
|
|
57
|
+
throw new Error(`Unsupported jsMinifier ${userConfig.jsMinifier}.`);
|
|
58
|
+
}
|
|
59
|
+
terserOptions = {
|
|
60
|
+
...terserOptions,
|
|
61
|
+
...userConfig.jsMinifierOptions,
|
|
62
|
+
};
|
|
63
|
+
if (jsMinifier !== types_1.JSMinifier.none) {
|
|
64
|
+
config.optimization.minimizer(`js-${jsMinifier}`).use(terser_webpack_plugin_1.default, [
|
|
65
|
+
{
|
|
66
|
+
extractComments: false,
|
|
67
|
+
minify,
|
|
68
|
+
terserOptions,
|
|
69
|
+
},
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
let cssMinify;
|
|
73
|
+
let minimizerOptions;
|
|
74
|
+
if (cssMinifier === types_1.CSSMinifier.esbuild) {
|
|
75
|
+
cssMinify = css_minimizer_webpack_plugin_1.default.esbuildMinify;
|
|
76
|
+
minimizerOptions = {
|
|
77
|
+
target: esbuildTarget,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
else if (cssMinifier === types_1.CSSMinifier.cssnano) {
|
|
81
|
+
cssMinify = css_minimizer_webpack_plugin_1.default.cssnanoMinify;
|
|
82
|
+
}
|
|
83
|
+
else if (cssMinifier === types_1.CSSMinifier.parcelCSS) {
|
|
84
|
+
cssMinify = css_minimizer_webpack_plugin_1.default.parcelCssMinify;
|
|
85
|
+
}
|
|
86
|
+
else if (cssMinifier !== types_1.CSSMinifier.none) {
|
|
87
|
+
throw new Error(`Unsupported cssMinifier ${userConfig.cssMinifier}.`);
|
|
88
|
+
}
|
|
89
|
+
minimizerOptions = {
|
|
90
|
+
...minimizerOptions,
|
|
91
|
+
...userConfig.cssMinifierOptions,
|
|
92
|
+
};
|
|
93
|
+
config.optimization
|
|
94
|
+
.minimizer(`css-${cssMinifier}`)
|
|
95
|
+
.use(css_minimizer_webpack_plugin_1.default, [
|
|
96
|
+
{
|
|
97
|
+
minify: cssMinify,
|
|
98
|
+
minimizerOptions,
|
|
99
|
+
},
|
|
100
|
+
]);
|
|
82
101
|
}
|
|
83
102
|
exports.addCompressPlugin = addCompressPlugin;
|
package/dist/config/config.d.ts
CHANGED
|
@@ -2,10 +2,12 @@ import { Configuration } from '../../compiled/webpack';
|
|
|
2
2
|
import { Env, IConfig } from '../types';
|
|
3
3
|
export interface IOpts {
|
|
4
4
|
cwd: string;
|
|
5
|
+
rootDir?: string;
|
|
5
6
|
env: Env;
|
|
6
7
|
entry: Record<string, string>;
|
|
7
8
|
extraBabelPresets?: any[];
|
|
8
9
|
extraBabelPlugins?: any[];
|
|
10
|
+
extraBabelIncludes?: string[];
|
|
9
11
|
extraEsbuildLoaderHandler?: any[];
|
|
10
12
|
babelPreset?: any;
|
|
11
13
|
chainWebpack?: Function;
|
package/dist/config/config.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -37,184 +28,195 @@ const miniCSSExtractPlugin_1 = require("./miniCSSExtractPlugin");
|
|
|
37
28
|
const nodePolyfill_1 = require("./nodePolyfill");
|
|
38
29
|
const progressPlugin_1 = require("./progressPlugin");
|
|
39
30
|
const speedMeasureWebpackPlugin_1 = require("./speedMeasureWebpackPlugin");
|
|
31
|
+
const ssrPlugin_1 = __importDefault(require("./ssrPlugin"));
|
|
40
32
|
const svgRules_1 = require("./svgRules");
|
|
41
|
-
function getConfig(opts) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (isDev && opts.hmr) {
|
|
71
|
-
entry.add(require.resolve('../../client/client/client'));
|
|
72
|
-
}
|
|
73
|
-
entry.add(opts.entry[key]);
|
|
74
|
-
});
|
|
75
|
-
// devtool
|
|
76
|
-
config.devtool(isDev
|
|
77
|
-
? userConfig.devtool === false
|
|
78
|
-
? false
|
|
79
|
-
: userConfig.devtool || constants_1.DEFAULT_DEVTOOL
|
|
80
|
-
: userConfig.devtool);
|
|
81
|
-
// output
|
|
82
|
-
const absOutputPath = (0, path_1.join)(opts.cwd, userConfig.outputPath || constants_1.DEFAULT_OUTPUT_PATH);
|
|
83
|
-
const disableCompress = process.env.COMPRESS === 'none';
|
|
84
|
-
config.output
|
|
85
|
-
.path(absOutputPath)
|
|
86
|
-
.filename(useHash ? `[name].[contenthash:8].js` : `[name].js`)
|
|
87
|
-
.chunkFilename(useHash ? `[name].[contenthash:8].async.js` : `[name].js`)
|
|
88
|
-
.publicPath(userConfig.publicPath || 'auto')
|
|
89
|
-
.pathinfo(isDev || disableCompress);
|
|
90
|
-
// resolve
|
|
91
|
-
// prettier-ignore
|
|
92
|
-
config.resolve
|
|
93
|
-
.set('symlinks', true)
|
|
94
|
-
.modules
|
|
95
|
-
.add('node_modules')
|
|
96
|
-
.end()
|
|
97
|
-
.alias
|
|
98
|
-
.merge(userConfig.alias || {})
|
|
99
|
-
.end()
|
|
100
|
-
.extensions
|
|
101
|
-
.merge([
|
|
102
|
-
'.wasm',
|
|
103
|
-
'.mjs',
|
|
104
|
-
'.js',
|
|
105
|
-
'.jsx',
|
|
106
|
-
'.ts',
|
|
107
|
-
'.tsx',
|
|
108
|
-
'.json'
|
|
109
|
-
])
|
|
110
|
-
.end();
|
|
111
|
-
// externals
|
|
112
|
-
config.externals(userConfig.externals || []);
|
|
113
|
-
// target
|
|
114
|
-
config.target(['web', 'es5']);
|
|
115
|
-
// experiments
|
|
116
|
-
config.experiments({
|
|
117
|
-
topLevelAwait: true,
|
|
118
|
-
outputModule: !!userConfig.esm,
|
|
119
|
-
});
|
|
120
|
-
// node polyfill
|
|
121
|
-
yield (0, nodePolyfill_1.addNodePolyfill)(applyOpts);
|
|
122
|
-
// rules
|
|
123
|
-
yield (0, javaScriptRules_1.addJavaScriptRules)(applyOpts);
|
|
124
|
-
yield (0, cssRules_1.addCSSRules)(applyOpts);
|
|
125
|
-
yield (0, assetRules_1.addAssetRules)(applyOpts);
|
|
126
|
-
yield (0, svgRules_1.addSVGRules)(applyOpts);
|
|
127
|
-
// plugins
|
|
128
|
-
// mini-css-extract-plugin
|
|
129
|
-
yield (0, miniCSSExtractPlugin_1.addMiniCSSExtractPlugin)(applyOpts);
|
|
130
|
-
// ignoreMomentLocale
|
|
131
|
-
yield (0, ignorePlugin_1.addIgnorePlugin)(applyOpts);
|
|
132
|
-
// define
|
|
133
|
-
yield (0, definePlugin_1.addDefinePlugin)(applyOpts);
|
|
134
|
-
// fast refresh
|
|
135
|
-
yield (0, fastRefreshPlugin_1.addFastRefreshPlugin)(applyOpts);
|
|
136
|
-
// progress
|
|
137
|
-
yield (0, progressPlugin_1.addProgressPlugin)(applyOpts);
|
|
138
|
-
// detect-dead-code-plugin
|
|
139
|
-
yield (0, detectDeadCodePlugin_1.addDetectDeadCodePlugin)(applyOpts);
|
|
140
|
-
// fork-ts-checker
|
|
141
|
-
yield (0, forkTSCheckerPlugin_1.addForkTSCheckerPlugin)(applyOpts);
|
|
142
|
-
// copy
|
|
143
|
-
yield (0, copyPlugin_1.addCopyPlugin)(applyOpts);
|
|
144
|
-
// manifest
|
|
145
|
-
yield (0, manifestPlugin_1.addManifestPlugin)(applyOpts);
|
|
146
|
-
// hmr
|
|
33
|
+
async function getConfig(opts) {
|
|
34
|
+
const { userConfig } = opts;
|
|
35
|
+
const isDev = opts.env === types_1.Env.development;
|
|
36
|
+
const config = new webpack_5_chain_1.default();
|
|
37
|
+
userConfig.targets || (userConfig.targets = constants_1.DEFAULT_BROWSER_TARGETS);
|
|
38
|
+
const useHash = !!(opts.hash || (userConfig.hash && !isDev));
|
|
39
|
+
const applyOpts = {
|
|
40
|
+
name: opts.name,
|
|
41
|
+
config,
|
|
42
|
+
userConfig,
|
|
43
|
+
cwd: opts.cwd,
|
|
44
|
+
env: opts.env,
|
|
45
|
+
babelPreset: opts.babelPreset,
|
|
46
|
+
extraBabelPlugins: opts.extraBabelPlugins || [],
|
|
47
|
+
extraBabelPresets: opts.extraBabelPresets || [],
|
|
48
|
+
extraBabelIncludes: opts.extraBabelIncludes || [],
|
|
49
|
+
extraEsbuildLoaderHandler: opts.extraEsbuildLoaderHandler || [],
|
|
50
|
+
browsers: (0, browsersList_1.getBrowsersList)({
|
|
51
|
+
targets: userConfig.targets,
|
|
52
|
+
}),
|
|
53
|
+
useHash,
|
|
54
|
+
staticPathPrefix: opts.staticPathPrefix !== undefined ? opts.staticPathPrefix : 'static/',
|
|
55
|
+
};
|
|
56
|
+
// mode
|
|
57
|
+
config.mode(opts.env);
|
|
58
|
+
config.stats('none');
|
|
59
|
+
// entry
|
|
60
|
+
Object.keys(opts.entry).forEach((key) => {
|
|
61
|
+
const entry = config.entry(key);
|
|
147
62
|
if (isDev && opts.hmr) {
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
// compress
|
|
151
|
-
yield (0, compressPlugin_1.addCompressPlugin)(applyOpts);
|
|
152
|
-
// purgecss
|
|
153
|
-
// await applyPurgeCSSWebpackPlugin(applyOpts);
|
|
154
|
-
// handle HarmonyLinkingError
|
|
155
|
-
yield (0, harmonyLinkingErrorPlugin_1.addHarmonyLinkingErrorPlugin)(applyOpts);
|
|
156
|
-
// runtimePublicPath
|
|
157
|
-
if (userConfig.runtimePublicPath) {
|
|
158
|
-
config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
|
|
63
|
+
entry.add(require.resolve('../../client/client/client'));
|
|
159
64
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
65
|
+
entry.add(opts.entry[key]);
|
|
66
|
+
});
|
|
67
|
+
// devtool
|
|
68
|
+
config.devtool(isDev
|
|
69
|
+
? userConfig.devtool === false
|
|
70
|
+
? false
|
|
71
|
+
: userConfig.devtool || constants_1.DEFAULT_DEVTOOL
|
|
72
|
+
: userConfig.devtool);
|
|
73
|
+
// output
|
|
74
|
+
const absOutputPath = (0, path_1.join)(opts.cwd, userConfig.outputPath || constants_1.DEFAULT_OUTPUT_PATH);
|
|
75
|
+
const disableCompress = process.env.COMPRESS === 'none';
|
|
76
|
+
config.output
|
|
77
|
+
.path(absOutputPath)
|
|
78
|
+
.filename(useHash ? `[name].[contenthash:8].js` : `[name].js`)
|
|
79
|
+
.chunkFilename(useHash ? `[name].[contenthash:8].async.js` : `[name].async.js`)
|
|
80
|
+
.publicPath(userConfig.publicPath || 'auto')
|
|
81
|
+
.pathinfo(isDev || disableCompress);
|
|
82
|
+
// resolve
|
|
83
|
+
// prettier-ignore
|
|
84
|
+
config.resolve
|
|
85
|
+
.set('symlinks', true)
|
|
86
|
+
.modules
|
|
87
|
+
.add('node_modules')
|
|
88
|
+
.end()
|
|
89
|
+
.alias
|
|
90
|
+
.merge(userConfig.alias || {})
|
|
91
|
+
.end()
|
|
92
|
+
.extensions
|
|
93
|
+
.merge([
|
|
94
|
+
'.wasm',
|
|
95
|
+
'.mjs',
|
|
96
|
+
'.js',
|
|
97
|
+
'.jsx',
|
|
98
|
+
'.ts',
|
|
99
|
+
'.tsx',
|
|
100
|
+
'.json'
|
|
101
|
+
])
|
|
102
|
+
.end();
|
|
103
|
+
// externals
|
|
104
|
+
config.externals(userConfig.externals || []);
|
|
105
|
+
// target
|
|
106
|
+
config.target(['web', 'es5']);
|
|
107
|
+
// experiments
|
|
108
|
+
config.experiments({
|
|
109
|
+
topLevelAwait: true,
|
|
110
|
+
outputModule: !!userConfig.esm,
|
|
111
|
+
});
|
|
112
|
+
// node polyfill
|
|
113
|
+
await (0, nodePolyfill_1.addNodePolyfill)(applyOpts);
|
|
114
|
+
// rules
|
|
115
|
+
await (0, javaScriptRules_1.addJavaScriptRules)(applyOpts);
|
|
116
|
+
await (0, cssRules_1.addCSSRules)(applyOpts);
|
|
117
|
+
await (0, assetRules_1.addAssetRules)(applyOpts);
|
|
118
|
+
await (0, svgRules_1.addSVGRules)(applyOpts);
|
|
119
|
+
// plugins
|
|
120
|
+
// mini-css-extract-plugin
|
|
121
|
+
await (0, miniCSSExtractPlugin_1.addMiniCSSExtractPlugin)(applyOpts);
|
|
122
|
+
// ignoreMomentLocale
|
|
123
|
+
await (0, ignorePlugin_1.addIgnorePlugin)(applyOpts);
|
|
124
|
+
// define
|
|
125
|
+
await (0, definePlugin_1.addDefinePlugin)(applyOpts);
|
|
126
|
+
// fast refresh
|
|
127
|
+
await (0, fastRefreshPlugin_1.addFastRefreshPlugin)(applyOpts);
|
|
128
|
+
// progress
|
|
129
|
+
await (0, progressPlugin_1.addProgressPlugin)(applyOpts);
|
|
130
|
+
// detect-dead-code-plugin
|
|
131
|
+
await (0, detectDeadCodePlugin_1.addDetectDeadCodePlugin)(applyOpts);
|
|
132
|
+
// fork-ts-checker
|
|
133
|
+
await (0, forkTSCheckerPlugin_1.addForkTSCheckerPlugin)(applyOpts);
|
|
134
|
+
// copy
|
|
135
|
+
await (0, copyPlugin_1.addCopyPlugin)(applyOpts);
|
|
136
|
+
// manifest
|
|
137
|
+
await (0, manifestPlugin_1.addManifestPlugin)(applyOpts);
|
|
138
|
+
// hmr
|
|
139
|
+
if (isDev && opts.hmr) {
|
|
140
|
+
config.plugin('hmr').use(webpack_1.default.HotModuleReplacementPlugin);
|
|
141
|
+
}
|
|
142
|
+
// ssr
|
|
143
|
+
await (0, ssrPlugin_1.default)(applyOpts);
|
|
144
|
+
// compress
|
|
145
|
+
await (0, compressPlugin_1.addCompressPlugin)(applyOpts);
|
|
146
|
+
// purgecss
|
|
147
|
+
// await applyPurgeCSSWebpackPlugin(applyOpts);
|
|
148
|
+
// handle HarmonyLinkingError
|
|
149
|
+
await (0, harmonyLinkingErrorPlugin_1.addHarmonyLinkingErrorPlugin)(applyOpts);
|
|
150
|
+
// remove node: prefix
|
|
151
|
+
// disable for performance
|
|
152
|
+
// await addNodePrefixPlugin(applyOpts);
|
|
153
|
+
// runtimePublicPath
|
|
154
|
+
if (userConfig.runtimePublicPath) {
|
|
155
|
+
config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
|
|
156
|
+
}
|
|
157
|
+
// cache
|
|
158
|
+
if (opts.cache) {
|
|
159
|
+
config.cache({
|
|
160
|
+
type: 'filesystem',
|
|
161
|
+
version: require('../../package.json').version,
|
|
162
|
+
buildDependencies: {
|
|
163
|
+
config: opts.cache.buildDependencies || [],
|
|
164
|
+
},
|
|
165
|
+
cacheDirectory: opts.cache.cacheDirectory ||
|
|
166
|
+
// 使用 rootDir 是在有 APP_ROOT 时,把 cache 目录放在根目录下
|
|
167
|
+
(0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules', '.cache', 'bundler-webpack'),
|
|
168
|
+
});
|
|
169
|
+
// tnpm 安装依赖的情况 webpack 默认的 managedPaths 不生效
|
|
170
|
+
// 使用 immutablePaths 避免 node_modules 的内容被写入缓存
|
|
171
|
+
// tnpm 安装的依赖路径中同时包含包名和版本号,满足 immutablePaths 使用的条件
|
|
172
|
+
// 同时配置 managedPaths 将 tnpm 的软连接结构标记为可信,避免执行快照序列化时 OOM
|
|
173
|
+
// ref: smallfish
|
|
174
|
+
if ( /*isTnpm*/require('@umijs/utils/package').__npminstall_done) {
|
|
175
|
+
const nodeModulesPath = opts.cache.absNodeModulesPath ||
|
|
176
|
+
(0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules');
|
|
177
|
+
config.snapshot({
|
|
178
|
+
immutablePaths: [nodeModulesPath],
|
|
179
|
+
managedPaths: [nodeModulesPath],
|
|
170
180
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if ( /*isTnpm*/require('@umijs/utils/package').__npminstall_done) {
|
|
176
|
-
config.snapshot({
|
|
177
|
-
immutablePaths: [
|
|
178
|
-
opts.cache.absNodeModulesPath || (0, path_1.join)(opts.cwd, 'node_modules'),
|
|
179
|
-
],
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
config.infrastructureLogging(Object.assign({ level: 'error' }, (process.env.WEBPACK_FS_CACHE_DEBUG
|
|
181
|
+
}
|
|
182
|
+
config.infrastructureLogging({
|
|
183
|
+
level: 'error',
|
|
184
|
+
...(process.env.WEBPACK_FS_CACHE_DEBUG
|
|
183
185
|
? {
|
|
184
186
|
debug: /webpack\.cache/,
|
|
185
187
|
}
|
|
186
|
-
: {})
|
|
187
|
-
}
|
|
188
|
-
// analyzer
|
|
189
|
-
if (opts.analyze) {
|
|
190
|
-
yield (0, bundleAnalyzerPlugin_1.addBundleAnalyzerPlugin)(applyOpts);
|
|
191
|
-
}
|
|
192
|
-
// chain webpack
|
|
193
|
-
if (opts.chainWebpack) {
|
|
194
|
-
yield opts.chainWebpack(config, {
|
|
195
|
-
env: opts.env,
|
|
196
|
-
webpack: webpack_1.default,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
if (userConfig.chainWebpack) {
|
|
200
|
-
yield userConfig.chainWebpack(config, {
|
|
201
|
-
env: opts.env,
|
|
202
|
-
webpack: webpack_1.default,
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
let webpackConfig = config.toConfig();
|
|
206
|
-
// speed measure
|
|
207
|
-
// TODO: mini-css-extract-plugin 报错
|
|
208
|
-
webpackConfig = yield (0, speedMeasureWebpackPlugin_1.addSpeedMeasureWebpackPlugin)({
|
|
209
|
-
webpackConfig,
|
|
188
|
+
: {}),
|
|
210
189
|
});
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
190
|
+
}
|
|
191
|
+
// analyzer
|
|
192
|
+
if (opts.analyze) {
|
|
193
|
+
await (0, bundleAnalyzerPlugin_1.addBundleAnalyzerPlugin)(applyOpts);
|
|
194
|
+
}
|
|
195
|
+
// chain webpack
|
|
196
|
+
if (opts.chainWebpack) {
|
|
197
|
+
await opts.chainWebpack(config, {
|
|
198
|
+
env: opts.env,
|
|
199
|
+
webpack: webpack_1.default,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (userConfig.chainWebpack) {
|
|
203
|
+
await userConfig.chainWebpack(config, {
|
|
204
|
+
env: opts.env,
|
|
205
|
+
webpack: webpack_1.default,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
let webpackConfig = config.toConfig();
|
|
209
|
+
// speed measure
|
|
210
|
+
// TODO: mini-css-extract-plugin 报错
|
|
211
|
+
webpackConfig = await (0, speedMeasureWebpackPlugin_1.addSpeedMeasureWebpackPlugin)({
|
|
212
|
+
webpackConfig,
|
|
218
213
|
});
|
|
214
|
+
if (opts.modifyWebpackConfig) {
|
|
215
|
+
webpackConfig = await opts.modifyWebpackConfig(webpackConfig, {
|
|
216
|
+
env: opts.env,
|
|
217
|
+
webpack: webpack_1.default,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return webpackConfig;
|
|
219
221
|
}
|
|
220
222
|
exports.getConfig = getConfig;
|
|
@@ -1,49 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.addCopyPlugin = void 0;
|
|
13
4
|
const fs_1 = require("fs");
|
|
14
5
|
const path_1 = require("path");
|
|
15
|
-
function addCopyPlugin(opts) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (typeof item === 'string') {
|
|
25
|
-
return {
|
|
26
|
-
from: (0, path_1.join)(cwd, item),
|
|
27
|
-
to: item,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
6
|
+
async function addCopyPlugin(opts) {
|
|
7
|
+
const { config, userConfig, cwd } = opts;
|
|
8
|
+
const copyPatterns = [
|
|
9
|
+
(0, fs_1.existsSync)((0, path_1.join)(cwd, 'public')) && {
|
|
10
|
+
from: (0, path_1.join)(cwd, 'public'),
|
|
11
|
+
},
|
|
12
|
+
...(userConfig.copy
|
|
13
|
+
? userConfig.copy.map((item) => {
|
|
14
|
+
if (typeof item === 'string') {
|
|
30
15
|
return {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
to: item.to,
|
|
16
|
+
from: (0, path_1.join)(cwd, item),
|
|
17
|
+
to: item,
|
|
34
18
|
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
// 相对于 process.cwd,所以这里需要使用绝对路径
|
|
22
|
+
from: (0, path_1.join)(cwd, item.from),
|
|
23
|
+
to: item.to,
|
|
24
|
+
};
|
|
25
|
+
})
|
|
26
|
+
: []),
|
|
27
|
+
].filter(Boolean);
|
|
28
|
+
if (copyPatterns.length) {
|
|
29
|
+
config
|
|
30
|
+
.plugin('copy')
|
|
31
|
+
.use(require('@umijs/bundler-webpack/compiled/copy-webpack-plugin'), [
|
|
32
|
+
{
|
|
33
|
+
patterns: copyPatterns,
|
|
34
|
+
},
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
48
37
|
}
|
|
49
38
|
exports.addCopyPlugin = addCopyPlugin;
|