@umijs/bundler-webpack 4.0.0-rc.14 → 4.0.0-rc.17

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 (39) hide show
  1. package/dist/build.js +48 -59
  2. package/dist/cli.js +6 -15
  3. package/dist/client/client.js +34 -47
  4. package/dist/config/_sampleFeature.js +6 -17
  5. package/dist/config/assetRules.js +44 -55
  6. package/dist/config/bundleAnalyzerPlugin.js +12 -23
  7. package/dist/config/compressPlugin.js +68 -76
  8. package/dist/config/config.js +177 -185
  9. package/dist/config/copyPlugin.js +29 -40
  10. package/dist/config/cssRules.js +93 -83
  11. package/dist/config/definePlugin.js +11 -19
  12. package/dist/config/detectDeadCodePlugin.js +16 -21
  13. package/dist/config/fastRefreshPlugin.js +11 -22
  14. package/dist/config/forkTSCheckerPlugin.js +11 -22
  15. package/dist/config/harmonyLinkingErrorPlugin.js +3 -14
  16. package/dist/config/ignorePlugin.js +10 -21
  17. package/dist/config/javaScriptRules.js +151 -162
  18. package/dist/config/manifestPlugin.js +10 -18
  19. package/dist/config/miniCSSExtractPlugin.js +12 -23
  20. package/dist/config/nodePolyfill.js +14 -21
  21. package/dist/config/nodePrefixPlugin.js +8 -19
  22. package/dist/config/progressPlugin.js +7 -18
  23. package/dist/config/purgecssWebpackPlugin.js +15 -26
  24. package/dist/config/speedMeasureWebpackPlugin.js +12 -23
  25. package/dist/config/svgRules.js +43 -47
  26. package/dist/dev.js +101 -112
  27. package/dist/loader/svgr.js +4 -13
  28. package/dist/loader/swc.js +9 -14
  29. package/dist/plugins/ESBuildCSSMinifyPlugin.js +23 -34
  30. package/dist/plugins/ParcelCSSMinifyPlugin.js +30 -32
  31. package/dist/plugins/RuntimePublicPathPlugin.js +1 -1
  32. package/dist/schema.js +18 -6
  33. package/dist/server/server.d.ts +1 -1
  34. package/dist/server/server.js +161 -170
  35. package/dist/server/ws.d.ts +1 -1
  36. package/dist/types.d.ts +2 -6
  37. package/package.json +9 -11
  38. package/dist/server/https.d.ts +0 -4
  39. package/dist/server/https.js +0 -74
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.addDefinePlugin = exports.resolveDefine = void 0;
13
4
  const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
@@ -29,17 +20,18 @@ function resolveDefine(opts) {
29
20
  define[key] = JSON.stringify(opts.define[key]);
30
21
  }
31
22
  }
32
- return Object.assign({ 'process.env': env }, define);
23
+ return {
24
+ 'process.env': env,
25
+ ...define,
26
+ };
33
27
  }
34
28
  exports.resolveDefine = resolveDefine;
35
- function addDefinePlugin(opts) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const { config, userConfig } = opts;
38
- config.plugin('define').use(webpack_1.DefinePlugin, [
39
- resolveDefine({
40
- define: userConfig.define || {},
41
- }),
42
- ]);
43
- });
29
+ async function addDefinePlugin(opts) {
30
+ const { config, userConfig } = opts;
31
+ config.plugin('define').use(webpack_1.DefinePlugin, [
32
+ resolveDefine({
33
+ define: userConfig.define || {},
34
+ }),
35
+ ]);
44
36
  }
45
37
  exports.addDefinePlugin = addDefinePlugin;
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  exports.addDetectDeadCodePlugin = void 0;
36
27
  const types_1 = require("../types");
@@ -52,24 +43,28 @@ class DetectDeadCodePlugin {
52
43
  if (!options) {
53
44
  return;
54
45
  }
55
- this.options = Object.assign(Object.assign({}, this.options), options);
46
+ this.options = {
47
+ ...this.options,
48
+ ...options,
49
+ };
56
50
  }
57
51
  apply(compiler) {
58
52
  if (!this.options.context) {
59
- this.options = Object.assign(Object.assign({}, this.options), { context: compiler.context });
53
+ this.options = {
54
+ ...this.options,
55
+ context: compiler.context,
56
+ };
60
57
  }
61
58
  compiler.hooks.afterEmit.tapAsync('DetectDeadCodePlugin', this.handleAfterEmit);
62
59
  }
63
60
  }
64
- function addDetectDeadCodePlugin(opts) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- const { config, userConfig } = opts;
67
- const isDev = opts.env === types_1.Env.development;
68
- if (userConfig.deadCode && !isDev) {
69
- config
70
- .plugin('detect-dead-code-plugin')
71
- .use(DetectDeadCodePlugin, [userConfig.deadCode]);
72
- }
73
- });
61
+ async function addDetectDeadCodePlugin(opts) {
62
+ const { config, userConfig } = opts;
63
+ const isDev = opts.env === types_1.Env.development;
64
+ if (userConfig.deadCode && !isDev) {
65
+ config
66
+ .plugin('detect-dead-code-plugin')
67
+ .use(DetectDeadCodePlugin, [userConfig.deadCode]);
68
+ }
74
69
  }
75
70
  exports.addDetectDeadCodePlugin = addDetectDeadCodePlugin;
@@ -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
  };
@@ -17,18 +8,16 @@ exports.addFastRefreshPlugin = void 0;
17
8
  const lib_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin/lib"));
18
9
  const constants_1 = require("../constants");
19
10
  const types_1 = require("../types");
20
- function addFastRefreshPlugin(opts) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const { config, userConfig, name } = opts;
23
- const isDev = opts.env === types_1.Env.development;
24
- const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
25
- // TODO: Should only run in react csr
26
- if (useFastRefresh) {
27
- config
28
- .plugin('fastRefresh')
29
- .after('hmr')
30
- .use(lib_1.default, [{ overlay: false }]);
31
- }
32
- });
11
+ async function addFastRefreshPlugin(opts) {
12
+ const { config, userConfig, name } = opts;
13
+ const isDev = opts.env === types_1.Env.development;
14
+ const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
15
+ // TODO: Should only run in react csr
16
+ if (useFastRefresh) {
17
+ config
18
+ .plugin('fastRefresh')
19
+ .after('hmr')
20
+ .use(lib_1.default, [{ overlay: false }]);
21
+ }
33
22
  }
34
23
  exports.addFastRefreshPlugin = addFastRefreshPlugin;
@@ -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
  };
@@ -15,20 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.addForkTSCheckerPlugin = void 0;
16
7
  // @ts-ignore
17
8
  const fork_ts_checker_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/fork-ts-checker-webpack-plugin"));
18
- function addForkTSCheckerPlugin(opts) {
9
+ async function addForkTSCheckerPlugin(opts) {
19
10
  var _a;
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const { config, userConfig } = opts;
22
- if (userConfig.forkTSChecker) {
23
- // use user's typescript
24
- if ((_a = userConfig.forkTSChecker.typescript) === null || _a === void 0 ? void 0 : _a.enable) {
25
- userConfig.forkTSChecker.typescript.typescriptPath =
26
- require.resolve('typescript');
27
- }
28
- config
29
- .plugin('fork-ts-checker-plugin')
30
- .use(fork_ts_checker_webpack_plugin_1.default, [userConfig.forkTSChecker]);
11
+ const { config, userConfig } = opts;
12
+ if (userConfig.forkTSChecker) {
13
+ // use user's typescript
14
+ if ((_a = userConfig.forkTSChecker.typescript) === null || _a === void 0 ? void 0 : _a.enable) {
15
+ userConfig.forkTSChecker.typescript.typescriptPath =
16
+ require.resolve('typescript');
31
17
  }
32
- });
18
+ config
19
+ .plugin('fork-ts-checker-plugin')
20
+ .use(fork_ts_checker_webpack_plugin_1.default, [userConfig.forkTSChecker]);
21
+ }
33
22
  }
34
23
  exports.addForkTSCheckerPlugin = addForkTSCheckerPlugin;
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.addHarmonyLinkingErrorPlugin = void 0;
13
4
  // ref: https://github.com/webpack/webpack/blob/ccecc17c01af96edddb931a76e7a3b21ef2969d8/lib/dependencies/HarmonyImportDependency.js#L164
@@ -33,10 +24,8 @@ class HarmonyLinkingErrorPlugin {
33
24
  });
34
25
  }
35
26
  }
36
- function addHarmonyLinkingErrorPlugin(opts) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const { config } = opts;
39
- config.plugin('harmony-linking-error-plugin').use(HarmonyLinkingErrorPlugin);
40
- });
27
+ async function addHarmonyLinkingErrorPlugin(opts) {
28
+ const { config } = opts;
29
+ config.plugin('harmony-linking-error-plugin').use(HarmonyLinkingErrorPlugin);
41
30
  }
42
31
  exports.addHarmonyLinkingErrorPlugin = addHarmonyLinkingErrorPlugin;
@@ -1,27 +1,16 @@
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.addIgnorePlugin = void 0;
13
4
  const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
14
- function addIgnorePlugin(opts) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- const { config, userConfig } = opts;
17
- if (userConfig.ignoreMomentLocale) {
18
- config.plugin('ignore-moment-locale').use(webpack_1.IgnorePlugin, [
19
- {
20
- resourceRegExp: /^\.\/locale$/,
21
- contextRegExp: /moment$/,
22
- },
23
- ]);
24
- }
25
- });
5
+ async function addIgnorePlugin(opts) {
6
+ const { config, userConfig } = opts;
7
+ if (userConfig.ignoreMomentLocale) {
8
+ config.plugin('ignore-moment-locale').use(webpack_1.IgnorePlugin, [
9
+ {
10
+ resourceRegExp: /^\.\/locale$/,
11
+ contextRegExp: /moment$/,
12
+ },
13
+ ]);
14
+ }
26
15
  }
27
16
  exports.addIgnorePlugin = addIgnorePlugin;
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.addJavaScriptRules = void 0;
13
4
  const mfsu_1 = require("@umijs/mfsu");
@@ -17,172 +8,170 @@ const webpack_1 = require("../../compiled/webpack");
17
8
  const constants_1 = require("../constants");
18
9
  const types_1 = require("../types");
19
10
  const depMatch_1 = require("../utils/depMatch");
20
- function addJavaScriptRules(opts) {
11
+ async function addJavaScriptRules(opts) {
21
12
  var _a, _b;
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const { config, userConfig, cwd, name } = opts;
24
- const isDev = opts.env === types_1.Env.development;
25
- const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
26
- const depPkgs = Object.assign({}, (0, depMatch_1.es5ImcompatibleVersionsToPkg)());
27
- const srcRules = [
28
- config.module
29
- .rule('src')
30
- .test(/\.(js|mjs)$/)
31
- .include.add([
32
- cwd,
33
- // import module out of cwd using APP_ROOT
34
- // issue: https://github.com/umijs/umi/issues/5594
35
- ...(process.env.APP_ROOT ? [process.cwd()] : []),
36
- ])
37
- .end()
38
- .exclude.add(/node_modules/)
39
- .end(),
40
- config.module.rule('jsx-ts-tsx').test(/\.(jsx|ts|tsx)$/),
41
- config.module
42
- .rule('extra-src')
43
- .test(/\.(js|mjs)$/)
44
- .include.add([
45
- // support extraBabelIncludes
46
- ...opts.extraBabelIncludes.map((p) => {
47
- // handle absolute path
48
- if ((0, path_1.isAbsolute)(p)) {
49
- return p;
50
- }
51
- // resolve npm package name
52
- try {
53
- if (p.startsWith('./')) {
54
- return require.resolve(p, { paths: [cwd] });
55
- }
56
- return (0, path_1.dirname)(require.resolve(`${p}/package.json`, { paths: [cwd] }));
57
- }
58
- catch (e) {
59
- if (e.code === 'MODULE_NOT_FOUND') {
60
- throw new Error('Cannot resolve extraBabelIncludes: ' + p);
61
- }
62
- throw e;
63
- }
64
- }),
65
- // support es5ImcompatibleVersions
66
- (path) => {
67
- try {
68
- // do src transform for bundler-webpack/client/client/client.js
69
- if (path.includes('client/client/client'))
70
- return true;
71
- return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
13
+ const { config, userConfig, cwd, name } = opts;
14
+ const isDev = opts.env === types_1.Env.development;
15
+ const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
16
+ const depPkgs = Object.assign({}, (0, depMatch_1.es5ImcompatibleVersionsToPkg)());
17
+ const srcRules = [
18
+ config.module
19
+ .rule('src')
20
+ .test(/\.(js|mjs)$/)
21
+ .include.add([
22
+ cwd,
23
+ // import module out of cwd using APP_ROOT
24
+ // issue: https://github.com/umijs/umi/issues/5594
25
+ ...(process.env.APP_ROOT ? [process.cwd()] : []),
26
+ ])
27
+ .end()
28
+ .exclude.add(/node_modules/)
29
+ .end(),
30
+ config.module.rule('jsx-ts-tsx').test(/\.(jsx|ts|tsx)$/),
31
+ config.module
32
+ .rule('extra-src')
33
+ .test(/\.(js|mjs)$/)
34
+ .include.add([
35
+ // support extraBabelIncludes
36
+ ...opts.extraBabelIncludes.map((p) => {
37
+ // handle absolute path
38
+ if ((0, path_1.isAbsolute)(p)) {
39
+ return p;
40
+ }
41
+ // resolve npm package name
42
+ try {
43
+ if (p.startsWith('./')) {
44
+ return require.resolve(p, { paths: [cwd] });
72
45
  }
73
- catch (e) {
74
- console.error(utils_1.chalk.red(e));
75
- throw e;
46
+ return (0, path_1.dirname)(require.resolve(`${p}/package.json`, { paths: [cwd] }));
47
+ }
48
+ catch (e) {
49
+ if (e.code === 'MODULE_NOT_FOUND') {
50
+ throw new Error('Cannot resolve extraBabelIncludes: ' + p);
76
51
  }
77
- },
78
- ])
79
- .end(),
80
- ];
81
- if (userConfig.mdx) {
82
- srcRules.push(config.module.rule('markdown').test(/\.mdx?$/));
83
- }
84
- const depRules = [
85
- config.module
86
- .rule('dep')
87
- .test(/\.(js|mjs)$/)
88
- .include.add(/node_modules/)
89
- .end()
90
- .exclude.add((path) => {
52
+ throw e;
53
+ }
54
+ }),
55
+ // support es5ImcompatibleVersions
56
+ (path) => {
91
57
  try {
58
+ // do src transform for bundler-webpack/client/client/client.js
59
+ if (path.includes('client/client/client'))
60
+ return true;
92
61
  return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
93
62
  }
94
63
  catch (e) {
95
64
  console.error(utils_1.chalk.red(e));
96
65
  throw e;
97
66
  }
98
- })
99
- .end(),
100
- ];
101
- // const prefix = existsSync(join(cwd, 'src')) ? join(cwd, 'src') : cwd;
102
- const srcTranspiler = userConfig.srcTranspiler || types_1.Transpiler.babel;
103
- srcRules.forEach((rule) => {
104
- if (srcTranspiler === types_1.Transpiler.babel) {
105
- rule
106
- .use('babel-loader')
107
- .loader(require.resolve('../../compiled/babel-loader'))
108
- .options({
109
- // Tell babel to guess the type, instead assuming all files are modules
110
- // https://github.com/webpack/webpack/issues/4039#issuecomment-419284940
111
- sourceType: 'unambiguous',
112
- babelrc: false,
113
- cacheDirectory: false,
114
- // process.env.BABEL_CACHE !== 'none'
115
- // ? join(cwd, `.umi/.cache/babel-loader`)
116
- // : false,
117
- targets: userConfig.targets,
118
- presets: [
119
- opts.babelPreset || [
120
- require.resolve('@umijs/babel-preset-umi'),
121
- {
122
- presetEnv: {},
123
- presetReact: {},
124
- presetTypeScript: {},
125
- pluginTransformRuntime: {},
126
- pluginLockCoreJS: {},
127
- pluginDynamicImportNode: false,
128
- pluginAutoCSSModules: userConfig.autoCSSModules,
129
- },
130
- ],
131
- ...opts.extraBabelPresets,
132
- ...(userConfig.extraBabelPresets || []).filter(Boolean),
133
- ],
134
- plugins: [
135
- useFastRefresh && require.resolve('react-refresh/babel'),
136
- ...opts.extraBabelPlugins,
137
- ...(userConfig.extraBabelPlugins || []),
138
- ].filter(Boolean),
139
- });
67
+ },
68
+ ])
69
+ .end(),
70
+ ];
71
+ if (userConfig.mdx) {
72
+ srcRules.push(config.module.rule('markdown').test(/\.mdx?$/));
73
+ }
74
+ const depRules = [
75
+ config.module
76
+ .rule('dep')
77
+ .test(/\.(js|mjs)$/)
78
+ .include.add(/node_modules/)
79
+ .end()
80
+ .exclude.add((path) => {
81
+ try {
82
+ return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
140
83
  }
141
- else if (srcTranspiler === types_1.Transpiler.swc) {
142
- const AutoCSSModule = require('../swcPlugins/autoCSSModules').default;
143
- rule
144
- .use('swc-loader')
145
- .loader(require.resolve('../loader/swc'))
146
- .options({
147
- plugin: (m) => new AutoCSSModule().visitProgram(m),
148
- });
84
+ catch (e) {
85
+ console.error(utils_1.chalk.red(e));
86
+ throw e;
149
87
  }
150
- else if (srcTranspiler === types_1.Transpiler.esbuild) {
151
- rule
152
- .use('esbuild-loader')
153
- .loader(mfsu_1.esbuildLoader)
154
- .options({
155
- target: isDev ? 'esnext' : 'es2015',
156
- handler: [mfsu_1.autoCssModulesHandler, ...opts.extraEsbuildLoaderHandler],
157
- });
158
- // esbuild loader can not auto import `React`
159
- config.plugin('react-provide-plugin').use(webpack_1.ProvidePlugin, [
160
- {
161
- React: 'react',
162
- },
163
- ]);
164
- }
165
- else {
166
- throw new Error(`Unsupported srcTranspiler ${srcTranspiler}.`);
167
- }
168
- });
169
- if (userConfig.mdx) {
170
- config.module
171
- .rule('mdx')
172
- .test(/\.mdx?$/)
173
- .use('mdx-loader')
174
- .loader((_a = userConfig.mdx) === null || _a === void 0 ? void 0 : _a.loader)
175
- .options((_b = userConfig.mdx) === null || _b === void 0 ? void 0 : _b.loaderOptions);
88
+ })
89
+ .end(),
90
+ ];
91
+ // const prefix = existsSync(join(cwd, 'src')) ? join(cwd, 'src') : cwd;
92
+ const srcTranspiler = userConfig.srcTranspiler || types_1.Transpiler.babel;
93
+ srcRules.forEach((rule) => {
94
+ if (srcTranspiler === types_1.Transpiler.babel) {
95
+ rule
96
+ .use('babel-loader')
97
+ .loader(require.resolve('../../compiled/babel-loader'))
98
+ .options({
99
+ // Tell babel to guess the type, instead assuming all files are modules
100
+ // https://github.com/webpack/webpack/issues/4039#issuecomment-419284940
101
+ sourceType: 'unambiguous',
102
+ babelrc: false,
103
+ cacheDirectory: false,
104
+ // process.env.BABEL_CACHE !== 'none'
105
+ // ? join(cwd, `.umi/.cache/babel-loader`)
106
+ // : false,
107
+ targets: userConfig.targets,
108
+ presets: [
109
+ opts.babelPreset || [
110
+ require.resolve('@umijs/babel-preset-umi'),
111
+ {
112
+ presetEnv: {},
113
+ presetReact: {},
114
+ presetTypeScript: {},
115
+ pluginTransformRuntime: {},
116
+ pluginLockCoreJS: {},
117
+ pluginDynamicImportNode: false,
118
+ pluginAutoCSSModules: userConfig.autoCSSModules,
119
+ },
120
+ ],
121
+ ...opts.extraBabelPresets,
122
+ ...(userConfig.extraBabelPresets || []).filter(Boolean),
123
+ ],
124
+ plugins: [
125
+ useFastRefresh && require.resolve('react-refresh/babel'),
126
+ ...opts.extraBabelPlugins,
127
+ ...(userConfig.extraBabelPlugins || []),
128
+ ].filter(Boolean),
129
+ });
130
+ }
131
+ else if (srcTranspiler === types_1.Transpiler.swc) {
132
+ const AutoCSSModule = require('../swcPlugins/autoCSSModules').default;
133
+ rule
134
+ .use('swc-loader')
135
+ .loader(require.resolve('../loader/swc'))
136
+ .options({
137
+ plugin: (m) => new AutoCSSModule().visitProgram(m),
138
+ });
139
+ }
140
+ else if (srcTranspiler === types_1.Transpiler.esbuild) {
141
+ rule
142
+ .use('esbuild-loader')
143
+ .loader(mfsu_1.esbuildLoader)
144
+ .options({
145
+ target: isDev ? 'esnext' : 'es2015',
146
+ handler: [mfsu_1.autoCssModulesHandler, ...opts.extraEsbuildLoaderHandler],
147
+ });
148
+ // esbuild loader can not auto import `React`
149
+ config.plugin('react-provide-plugin').use(webpack_1.ProvidePlugin, [
150
+ {
151
+ React: 'react',
152
+ },
153
+ ]);
154
+ }
155
+ else {
156
+ throw new Error(`Unsupported srcTranspiler ${srcTranspiler}.`);
157
+ }
158
+ });
159
+ if (userConfig.mdx) {
160
+ config.module
161
+ .rule('mdx')
162
+ .test(/\.mdx?$/)
163
+ .use('mdx-loader')
164
+ .loader((_a = userConfig.mdx) === null || _a === void 0 ? void 0 : _a.loader)
165
+ .options((_b = userConfig.mdx) === null || _b === void 0 ? void 0 : _b.loaderOptions);
166
+ }
167
+ const depTranspiler = userConfig.depTranspiler || types_1.Transpiler.none;
168
+ depRules.forEach((_rule) => {
169
+ if (depTranspiler === types_1.Transpiler.none) {
170
+ // noop
171
+ }
172
+ else {
173
+ throw new Error(`Unsupported depTranspiler ${depTranspiler}.`);
176
174
  }
177
- const depTranspiler = userConfig.depTranspiler || types_1.Transpiler.none;
178
- depRules.forEach((_rule) => {
179
- if (depTranspiler === types_1.Transpiler.none) {
180
- // noop
181
- }
182
- else {
183
- throw new Error(`Unsupported depTranspiler ${depTranspiler}.`);
184
- }
185
- });
186
175
  });
187
176
  }
188
177
  exports.addJavaScriptRules = addJavaScriptRules;
@@ -1,25 +1,17 @@
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.addManifestPlugin = void 0;
13
4
  // @ts-ignore
14
5
  const webpack_manifest_plugin_1 = require("@umijs/bundler-webpack/compiled/webpack-manifest-plugin");
15
- function addManifestPlugin(opts) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const { config, userConfig } = opts;
18
- if (userConfig.manifest) {
19
- config.plugin('manifest-plugin').use(webpack_manifest_plugin_1.WebpackManifestPlugin, [
20
- Object.assign({ fileName: 'asset-manifest.json' }, userConfig.manifest),
21
- ]);
22
- }
23
- });
6
+ async function addManifestPlugin(opts) {
7
+ const { config, userConfig } = opts;
8
+ if (userConfig.manifest) {
9
+ config.plugin('manifest-plugin').use(webpack_manifest_plugin_1.WebpackManifestPlugin, [
10
+ {
11
+ fileName: 'asset-manifest.json',
12
+ ...userConfig.manifest,
13
+ },
14
+ ]);
15
+ }
24
16
  }
25
17
  exports.addManifestPlugin = addManifestPlugin;