@umijs/bundler-webpack 4.0.0-rc.14 → 4.0.0-rc.15
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/dist/build.js +48 -59
- package/dist/cli.js +6 -15
- package/dist/client/client.js +34 -47
- 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 +68 -76
- package/dist/config/config.js +177 -185
- package/dist/config/copyPlugin.js +29 -40
- package/dist/config/cssRules.js +93 -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.js +151 -162
- package/dist/config/manifestPlugin.js +10 -18
- package/dist/config/miniCSSExtractPlugin.js +12 -23
- package/dist/config/nodePolyfill.js +14 -21
- package/dist/config/nodePrefixPlugin.js +8 -19
- package/dist/config/progressPlugin.js +7 -18
- package/dist/config/purgecssWebpackPlugin.js +15 -26
- package/dist/config/speedMeasureWebpackPlugin.js +12 -23
- package/dist/config/svgRules.js +43 -47
- package/dist/dev.js +101 -112
- package/dist/loader/svgr.js +4 -13
- package/dist/loader/swc.js +9 -14
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +23 -34
- package/dist/plugins/ParcelCSSMinifyPlugin.js +30 -32
- package/dist/server/server.d.ts +1 -1
- package/dist/server/server.js +161 -170
- package/dist/server/ws.d.ts +1 -1
- package/dist/types.d.ts +2 -6
- package/package.json +6 -8
- package/dist/server/https.d.ts +0 -4
- 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
|
|
23
|
+
return {
|
|
24
|
+
'process.env': env,
|
|
25
|
+
...define,
|
|
26
|
+
};
|
|
33
27
|
}
|
|
34
28
|
exports.resolveDefine = resolveDefine;
|
|
35
|
-
function addDefinePlugin(opts) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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 =
|
|
46
|
+
this.options = {
|
|
47
|
+
...this.options,
|
|
48
|
+
...options,
|
|
49
|
+
};
|
|
56
50
|
}
|
|
57
51
|
apply(compiler) {
|
|
58
52
|
if (!this.options.context) {
|
|
59
|
-
this.options =
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
38
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
srcRules.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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;
|