@umijs/bundler-webpack 4.0.0-beta.7 → 4.0.0-canary.202200505.1
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/autoprefixer/browserslist/index.d.ts +13 -7
- package/compiled/autoprefixer/index.js +3 -3
- package/compiled/autoprefixer/postcss/lib/at-rule.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/comment.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/container.d.ts +2 -2
- package/compiled/autoprefixer/postcss/lib/css-syntax-error.d.ts +55 -8
- package/compiled/autoprefixer/postcss/lib/declaration.d.ts +2 -2
- package/compiled/autoprefixer/postcss/lib/input.d.ts +26 -6
- package/compiled/autoprefixer/postcss/lib/lazy-result.d.ts +11 -10
- package/compiled/autoprefixer/postcss/lib/no-work-result.d.ts +37 -0
- package/compiled/autoprefixer/postcss/lib/node.d.ts +38 -4
- package/compiled/autoprefixer/postcss/lib/postcss.d.ts +31 -30
- package/compiled/autoprefixer/postcss/lib/processor.d.ts +5 -4
- package/compiled/autoprefixer/postcss/lib/result.d.ts +3 -2
- package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/warning.d.ts +37 -3
- package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
- package/compiled/babel-loader/index.js +2 -2
- package/compiled/copy-webpack-plugin/939.index.js +1171 -0
- package/compiled/copy-webpack-plugin/index.js +16 -10
- package/compiled/copy-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/index.js +8 -2
- package/compiled/css-minimizer-webpack-plugin/minify.js +25 -11
- package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/utils.js +225 -28
- package/compiled/cssnano/index.js +12 -11
- package/compiled/cssnano/package.json +1 -1
- package/compiled/express.d.ts +2 -0
- package/compiled/fork-ts-checker-webpack-plugin/LICENSE +21 -0
- package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
- package/compiled/fork-ts-checker-webpack-plugin/index.js +42 -0
- package/compiled/fork-ts-checker-webpack-plugin/package.json +1 -0
- package/compiled/http-proxy-middleware/dist/types.d.ts +5 -5
- package/compiled/http-proxy-middleware/http-proxy/index.d.ts +1 -1
- package/compiled/http-proxy-middleware/index.js +10 -10
- package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +60 -8
- package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +13 -1
- package/compiled/mini-css-extract-plugin/index.js +7970 -7445
- package/compiled/mini-css-extract-plugin/loader.js +179 -54
- package/compiled/mini-css-extract-plugin/package.json +1 -1
- package/compiled/mini-css-extract-plugin/utils.js +85 -24
- package/compiled/postcss-loader/index.js +1 -1
- package/compiled/react-refresh/LICENSE +21 -0
- package/compiled/react-refresh/index.js +9 -7
- package/compiled/react-refresh/package.json +1 -0
- package/compiled/sass-loader/index.js +1 -1
- package/compiled/schema-utils/ajv/dist/ajv.d.ts +16 -0
- package/compiled/schema-utils/ajv/dist/compile/codegen/code.d.ts +39 -0
- package/compiled/schema-utils/ajv/dist/compile/codegen/index.d.ts +79 -0
- package/compiled/schema-utils/ajv/dist/compile/codegen/scope.d.ts +79 -0
- package/compiled/schema-utils/ajv/dist/compile/errors.d.ts +13 -0
- package/compiled/schema-utils/ajv/dist/compile/index.d.ts +80 -0
- package/compiled/schema-utils/ajv/dist/compile/ref_error.d.ts +5 -0
- package/compiled/schema-utils/ajv/dist/compile/resolve.d.ts +12 -0
- package/compiled/schema-utils/ajv/dist/compile/rules.d.ts +28 -0
- package/compiled/schema-utils/ajv/dist/compile/util.d.ts +40 -0
- package/compiled/schema-utils/ajv/dist/compile/validate/index.d.ts +42 -0
- package/compiled/schema-utils/ajv/dist/compile/validate/subschema.d.ts +47 -0
- package/compiled/schema-utils/ajv/dist/core.d.ts +171 -0
- package/compiled/schema-utils/ajv/dist/runtime/validation_error.d.ts +7 -0
- package/compiled/schema-utils/ajv/dist/types/index.d.ts +177 -0
- package/compiled/schema-utils/ajv/dist/types/json-schema.d.ts +124 -0
- package/compiled/schema-utils/ajv/dist/types/jtd-schema.d.ts +168 -0
- package/compiled/schema-utils/declarations/validate.d.ts +4 -4
- package/compiled/schema-utils/index.js +8 -2
- package/compiled/schema-utils/uri-js/dist/es5/uri.all.d.ts +59 -0
- package/compiled/style-loader/index.js +1 -1
- package/compiled/terser/index.js +1 -1
- package/compiled/terser-webpack-plugin/index.js +393 -517
- package/compiled/terser-webpack-plugin/jest-worker/build/types.d.ts +1 -0
- package/compiled/terser-webpack-plugin/minify.js +10 -3
- package/compiled/terser-webpack-plugin/package.json +1 -1
- package/compiled/terser-webpack-plugin/types/index.d.ts +183 -149
- package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
- package/compiled/terser-webpack-plugin/types/utils.d.ts +10 -15
- package/compiled/terser-webpack-plugin/utils.js +118 -25
- 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 +13409 -5746
- package/compiled/webpack/types.d.ts +606 -171
- package/compiled/webpack-dev-middleware/index.js +11 -5
- package/compiled/webpack-dev-middleware/package.json +1 -1
- package/compiled/{tapable → webpack-manifest-plugin}/LICENSE +2 -2
- package/compiled/webpack-manifest-plugin/index.js +1 -0
- package/compiled/webpack-manifest-plugin/package.json +1 -0
- package/compiled/webpack-sources/index.js +1 -1
- package/compiled/ws/index.d.ts +1 -2
- package/compiled/ws/index.js +1 -1
- package/dist/build.d.ts +6 -3
- package/dist/build.js +48 -56
- package/dist/cli.js +10 -22
- package/dist/client/client.js +57 -51
- package/dist/config/_sampleFeature.js +6 -17
- package/dist/config/assetRules.js +44 -51
- package/dist/config/bundleAnalyzerPlugin.js +12 -23
- package/dist/config/compressPlugin.js +70 -64
- package/dist/config/config.d.ts +9 -2
- package/dist/config/config.js +184 -144
- package/dist/config/copyPlugin.js +29 -40
- package/dist/config/cssRules.js +93 -83
- package/dist/config/definePlugin.js +11 -19
- package/dist/config/detectDeadCode.d.ts +12 -0
- package/dist/config/detectDeadCode.js +120 -0
- package/dist/config/detectDeadCodePlugin.d.ts +9 -0
- package/dist/config/detectDeadCodePlugin.js +70 -0
- package/dist/config/fastRefreshPlugin.js +11 -22
- package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
- package/dist/config/forkTSCheckerPlugin.js +23 -0
- package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
- package/dist/config/harmonyLinkingErrorPlugin.js +31 -0
- package/dist/config/ignorePlugin.js +10 -21
- package/dist/config/javaScriptRules.d.ts +2 -0
- package/dist/config/javaScriptRules.js +153 -131
- package/dist/config/manifestPlugin.d.ts +11 -0
- package/dist/config/manifestPlugin.js +17 -0
- package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
- package/dist/config/miniCSSExtractPlugin.js +12 -24
- 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/svgRules.d.ts +1 -0
- package/dist/config/svgRules.js +45 -48
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +10 -1
- package/dist/dev.d.ts +8 -2
- package/dist/dev.js +117 -66
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -1
- package/dist/loader/svgr.d.ts +4 -0
- package/dist/loader/svgr.js +58 -0
- package/dist/loader/swc.d.ts +4 -0
- package/dist/loader/swc.js +74 -0
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +23 -36
- package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.js +73 -0
- package/dist/plugins/ProgressPlugin.js +2 -2
- package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
- package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
- package/dist/requireHook.js +1 -1
- package/dist/schema.js +23 -11
- package/dist/server/server.d.ts +2 -1
- package/dist/server/server.js +165 -130
- package/dist/server/ws.d.ts +6 -3
- package/dist/server/ws.js +1 -1
- package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
- package/dist/swcPlugins/autoCSSModules.js +16 -17
- package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
- package/dist/swcPlugins/changeImportFromString.js +10 -0
- package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
- package/dist/swcPlugins/lockCoreJS.js +24 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.js +1 -0
- package/dist/utils/depMatch.js +1 -1
- package/dist/utils/getEsBuildTarget.d.ts +5 -0
- package/dist/utils/getEsBuildTarget.js +12 -0
- package/package.json +68 -67
- package/compiled/@svgr/webpack/.svgo.yml +0 -75
- package/compiled/@svgr/webpack/LICENSE +0 -7
- package/compiled/@svgr/webpack/index.js +0 -343
- package/compiled/@svgr/webpack/package.json +0 -1
- package/compiled/css-loader/LICENSE +0 -20
- package/compiled/css-loader/api.js +0 -102
- package/compiled/css-loader/getUrl.js +0 -29
- package/compiled/css-loader/index.js +0 -2
- package/compiled/css-loader/noSourceMaps.js +0 -5
- package/compiled/css-loader/package.json +0 -1
- package/compiled/css-loader/sourceMaps.js +0 -22
- package/compiled/express/LICENSE +0 -24
- package/compiled/express/body-parser/index.d.ts +0 -104
- package/compiled/express/connect/index.d.ts +0 -93
- package/compiled/express/express-serve-static-core/index.d.ts +0 -1252
- package/compiled/express/index.d.ts +0 -133
- package/compiled/express/index.js +0 -338
- package/compiled/express/mime/index.d.ts +0 -35
- package/compiled/express/package.json +0 -1
- package/compiled/express/qs/index.d.ts +0 -62
- package/compiled/express/range-parser/index.d.ts +0 -35
- package/compiled/express/serve-static/index.d.ts +0 -108
- package/compiled/less/index.js +0 -31
- package/compiled/less/package.json +0 -1
- package/compiled/swc-loader/LICENSE +0 -25
- package/compiled/swc-loader/index.js +0 -1
- package/compiled/swc-loader/package.json +0 -1
- package/compiled/tapable/index.js +0 -1
- package/compiled/tapable/package.json +0 -1
- package/compiled/tapable/tapable.d.ts +0 -116
|
@@ -1,155 +1,177 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.addJavaScriptRules = void 0;
|
|
4
|
+
const mfsu_1 = require("@umijs/mfsu");
|
|
16
5
|
const utils_1 = require("@umijs/utils");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const webpack_1 = require("../../compiled/webpack");
|
|
17
8
|
const constants_1 = require("../constants");
|
|
18
|
-
const autoCSSModules_1 = __importDefault(require("../swcPlugins/autoCSSModules"));
|
|
19
9
|
const types_1 = require("../types");
|
|
20
10
|
const depMatch_1 = require("../utils/depMatch");
|
|
21
|
-
function addJavaScriptRules(opts) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
11
|
+
async function addJavaScriptRules(opts) {
|
|
12
|
+
var _a, _b;
|
|
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
|
|
45
42
|
try {
|
|
46
|
-
if (
|
|
47
|
-
return
|
|
48
|
-
|
|
43
|
+
if (p.startsWith('./')) {
|
|
44
|
+
return require.resolve(p, { paths: [cwd] });
|
|
45
|
+
}
|
|
46
|
+
return (0, path_1.dirname)(require.resolve(`${p}/package.json`, { paths: [cwd] }));
|
|
49
47
|
}
|
|
50
48
|
catch (e) {
|
|
51
|
-
|
|
49
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
|
50
|
+
throw new Error('Cannot resolve extraBabelIncludes: ' + p);
|
|
51
|
+
}
|
|
52
52
|
throw e;
|
|
53
53
|
}
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const depRules = [
|
|
58
|
-
config.module
|
|
59
|
-
.rule('dep')
|
|
60
|
-
.test(/\.(js|mjs)$/)
|
|
61
|
-
.include.add(/node_modules/)
|
|
62
|
-
.end()
|
|
63
|
-
.exclude.add((path) => {
|
|
54
|
+
}),
|
|
55
|
+
// support es5ImcompatibleVersions
|
|
56
|
+
(path) => {
|
|
64
57
|
try {
|
|
58
|
+
// do src transform for bundler-webpack/client/client/client.js
|
|
59
|
+
if (path.includes('client/client/client'))
|
|
60
|
+
return true;
|
|
65
61
|
return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
|
|
66
62
|
}
|
|
67
63
|
catch (e) {
|
|
68
64
|
console.error(utils_1.chalk.red(e));
|
|
69
65
|
throw e;
|
|
70
66
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
srcRules.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// process.env.BABEL_CACHE !== 'none'
|
|
88
|
-
// ? join(cwd, `.umi/.cache/babel-loader`)
|
|
89
|
-
// : false,
|
|
90
|
-
targets: userConfig.targets,
|
|
91
|
-
presets: [
|
|
92
|
-
opts.babelPreset || [
|
|
93
|
-
require.resolve('@umijs/babel-preset-umi'),
|
|
94
|
-
{
|
|
95
|
-
presetEnv: {},
|
|
96
|
-
presetReact: {},
|
|
97
|
-
presetTypeScript: {},
|
|
98
|
-
pluginTransformRuntime: {},
|
|
99
|
-
pluginLockCoreJS: {},
|
|
100
|
-
pluginDynamicImportNode: false,
|
|
101
|
-
pluginAutoCSSModules: userConfig.autoCSSModules,
|
|
102
|
-
},
|
|
103
|
-
],
|
|
104
|
-
...opts.extraBabelPresets,
|
|
105
|
-
...(userConfig.extraBabelPresets || []).filter(Boolean),
|
|
106
|
-
],
|
|
107
|
-
plugins: [
|
|
108
|
-
useFastRefresh && require.resolve('react-refresh/babel'),
|
|
109
|
-
...opts.extraBabelPlugins,
|
|
110
|
-
...(userConfig.extraBabelPlugins || []),
|
|
111
|
-
].filter(Boolean),
|
|
112
|
-
});
|
|
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 });
|
|
113
83
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
.use('swc-loader')
|
|
118
|
-
.loader(require.resolve('../../compiled/swc-loader'))
|
|
119
|
-
.options({
|
|
120
|
-
jsc: {
|
|
121
|
-
parser: {
|
|
122
|
-
syntax: 'typescript',
|
|
123
|
-
dynamicImport: true,
|
|
124
|
-
tsx: true,
|
|
125
|
-
},
|
|
126
|
-
transform: {
|
|
127
|
-
react: {
|
|
128
|
-
runtime: 'automatic',
|
|
129
|
-
pragma: 'React.createElement',
|
|
130
|
-
pragmaFrag: 'React.Fragment',
|
|
131
|
-
throwIfNamespace: true,
|
|
132
|
-
development: env === types_1.Env.development,
|
|
133
|
-
useBuiltins: true,
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
plugin: (m) => new autoCSSModules_1.default().visitProgram(m),
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
throw new Error(`Unsupported srcTranspiler ${srcTranspiler}.`);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
const depTranspiler = userConfig.depTranspiler || types_1.Transpiler.none;
|
|
145
|
-
depRules.forEach((_rule) => {
|
|
146
|
-
if (depTranspiler === types_1.Transpiler.none) {
|
|
147
|
-
// noop
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
throw new Error(`Unsupported depTranspiler ${depTranspiler}.`);
|
|
84
|
+
catch (e) {
|
|
85
|
+
console.error(utils_1.chalk.red(e));
|
|
86
|
+
throw e;
|
|
151
87
|
}
|
|
152
|
-
})
|
|
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}.`);
|
|
174
|
+
}
|
|
153
175
|
});
|
|
154
176
|
}
|
|
155
177
|
exports.addJavaScriptRules = addJavaScriptRules;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
+
import { Env, IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
name?: string;
|
|
5
|
+
config: Config;
|
|
6
|
+
userConfig: IConfig;
|
|
7
|
+
cwd: string;
|
|
8
|
+
env: Env;
|
|
9
|
+
}
|
|
10
|
+
export declare function addManifestPlugin(opts: IOpts): Promise<void>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addManifestPlugin = void 0;
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
const webpack_manifest_plugin_1 = require("@umijs/bundler-webpack/compiled/webpack-manifest-plugin");
|
|
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
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.addManifestPlugin = addManifestPlugin;
|
|
@@ -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,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
6
|
exports.addMiniCSSExtractPlugin = void 0;
|
|
16
7
|
// @ts-ignore
|
|
17
8
|
const mini_css_extract_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/mini-css-extract-plugin"));
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
]);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
9
|
+
async function addMiniCSSExtractPlugin(opts) {
|
|
10
|
+
const { config, userConfig, useHash } = opts;
|
|
11
|
+
const hash = useHash ? '.[contenthash:8]' : '';
|
|
12
|
+
if (!userConfig.styleLoader) {
|
|
13
|
+
config.plugin('mini-css-extract-plugin').use(mini_css_extract_plugin_1.default, [
|
|
14
|
+
{
|
|
15
|
+
filename: `[name]${hash}.css`,
|
|
16
|
+
chunkFilename: `[name]${hash}.chunk.css`,
|
|
17
|
+
ignoreOrder: true,
|
|
18
|
+
},
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
33
21
|
}
|
|
34
22
|
exports.addMiniCSSExtractPlugin = addMiniCSSExtractPlugin;
|
|
@@ -1,26 +1,18 @@
|
|
|
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.addNodePolyfill = void 0;
|
|
13
4
|
const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
|
|
14
|
-
function addNodePolyfill(opts) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
async function addNodePolyfill(opts) {
|
|
6
|
+
const { config } = opts;
|
|
7
|
+
const nodeLibs = require('node-libs-browser');
|
|
8
|
+
config.plugin('node-polyfill-provider').use(webpack_1.ProvidePlugin, [
|
|
9
|
+
{
|
|
10
|
+
Buffer: ['buffer', 'Buffer'],
|
|
11
|
+
process: nodeLibs['process'],
|
|
12
|
+
},
|
|
13
|
+
]);
|
|
14
|
+
config.resolve.fallback.merge({
|
|
15
|
+
...Object.keys(nodeLibs).reduce((memo, key) => {
|
|
24
16
|
if (nodeLibs[key]) {
|
|
25
17
|
memo[key] = nodeLibs[key];
|
|
26
18
|
}
|
|
@@ -28,7 +20,9 @@ function addNodePolyfill(opts) {
|
|
|
28
20
|
memo[key] = false;
|
|
29
21
|
}
|
|
30
22
|
return memo;
|
|
31
|
-
}, {})
|
|
23
|
+
}, {}),
|
|
24
|
+
http: false,
|
|
25
|
+
https: false,
|
|
32
26
|
});
|
|
33
27
|
}
|
|
34
28
|
exports.addNodePolyfill = addNodePolyfill;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
+
import { Env, IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
name?: string;
|
|
5
|
+
config: Config;
|
|
6
|
+
userConfig: IConfig;
|
|
7
|
+
cwd: string;
|
|
8
|
+
env: Env;
|
|
9
|
+
}
|
|
10
|
+
export declare function addNodePrefixPlugin(opts: IOpts): Promise<void>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addNodePrefixPlugin = void 0;
|
|
4
|
+
const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
|
|
5
|
+
async function addNodePrefixPlugin(opts) {
|
|
6
|
+
const { config } = opts;
|
|
7
|
+
config.plugin('node-prefix-plugin').use(webpack_1.NormalModuleReplacementPlugin, [
|
|
8
|
+
/^node:/,
|
|
9
|
+
(resource) => {
|
|
10
|
+
resource.request = resource.request.replace(/^node:/, '');
|
|
11
|
+
},
|
|
12
|
+
]);
|
|
13
|
+
}
|
|
14
|
+
exports.addNodePrefixPlugin = addNodePrefixPlugin;
|
|
@@ -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
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
exports.addProgressPlugin = void 0;
|
|
16
7
|
const ProgressPlugin_1 = __importDefault(require("../plugins/ProgressPlugin"));
|
|
17
|
-
function addProgressPlugin(opts) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
]);
|
|
25
|
-
});
|
|
8
|
+
async function addProgressPlugin(opts) {
|
|
9
|
+
const { config, name } = opts;
|
|
10
|
+
config.plugin('progress-plugin').use(ProgressPlugin_1.default, [
|
|
11
|
+
{
|
|
12
|
+
name,
|
|
13
|
+
},
|
|
14
|
+
]);
|
|
26
15
|
}
|
|
27
16
|
exports.addProgressPlugin = addProgressPlugin;
|
|
@@ -1,32 +1,21 @@
|
|
|
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.applyPurgeCSSWebpackPlugin = void 0;
|
|
13
4
|
const types_1 = require("../types");
|
|
14
|
-
function applyPurgeCSSWebpackPlugin(opts) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
});
|
|
5
|
+
async function applyPurgeCSSWebpackPlugin(opts) {
|
|
6
|
+
const { config, userConfig, cwd, env } = opts;
|
|
7
|
+
config;
|
|
8
|
+
userConfig;
|
|
9
|
+
cwd;
|
|
10
|
+
env;
|
|
11
|
+
if (userConfig.purgeCSS && env === types_1.Env.production) {
|
|
12
|
+
config
|
|
13
|
+
.plugin('purgecss-webpack-plugin')
|
|
14
|
+
.use(require('@umijs/bundler-webpack/compiled/purgecss-webpack-plugin'), [
|
|
15
|
+
{
|
|
16
|
+
paths: [],
|
|
17
|
+
},
|
|
18
|
+
]);
|
|
19
|
+
}
|
|
31
20
|
}
|
|
32
21
|
exports.applyPurgeCSSWebpackPlugin = applyPurgeCSSWebpackPlugin;
|
|
@@ -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,19 +7,17 @@ exports.addSpeedMeasureWebpackPlugin = void 0;
|
|
|
16
7
|
// @ts-ignore
|
|
17
8
|
const speed_measure_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/speed-measure-webpack-plugin"));
|
|
18
9
|
const path_1 = require("path");
|
|
19
|
-
function addSpeedMeasureWebpackPlugin(opts) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return webpackConfig;
|
|
32
|
-
});
|
|
10
|
+
async function addSpeedMeasureWebpackPlugin(opts) {
|
|
11
|
+
let webpackConfig = opts.webpackConfig;
|
|
12
|
+
if (process.env.SPEED_MEASURE) {
|
|
13
|
+
const smpOption = process.env.SPEED_MEASURE === 'JSON'
|
|
14
|
+
? {
|
|
15
|
+
outputFormat: 'json',
|
|
16
|
+
outputTarget: (0, path_1.join)(process.cwd(), 'SPEED_MEASURE.json'),
|
|
17
|
+
}
|
|
18
|
+
: { outputFormat: 'human', outputTarget: console.log };
|
|
19
|
+
webpackConfig = new speed_measure_webpack_plugin_1.default(smpOption).wrap(webpackConfig);
|
|
20
|
+
}
|
|
21
|
+
return webpackConfig;
|
|
33
22
|
}
|
|
34
23
|
exports.addSpeedMeasureWebpackPlugin = addSpeedMeasureWebpackPlugin;
|