@umijs/bundler-webpack 4.0.0-rc.9 → 4.0.2

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