@umijs/bundler-webpack 4.0.6 → 4.0.9
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 → client}/client/client.d.ts +0 -0
- package/client/client/client.js +295 -194
- package/client/constants.d.ts +15 -0
- package/client/constants.js +28 -19
- package/client/utils/formatWebpackMessages.d.ts +12 -0
- package/client/utils/formatWebpackMessages.js +68 -86
- package/dist/build.d.ts +1 -1
- package/dist/build.js +105 -61
- package/dist/cli.js +77 -69
- package/dist/config/_sampleFeature.js +33 -9
- package/dist/config/assetRules.js +45 -36
- package/dist/config/bundleAnalyzerPlugin.js +39 -17
- package/dist/config/compressPlugin.js +113 -95
- package/dist/config/config.d.ts +1 -0
- package/dist/config/config.js +204 -215
- package/dist/config/copyPlugin.js +59 -40
- package/dist/config/cssRules.js +136 -131
- package/dist/config/definePlugin.d.ts +1 -0
- package/dist/config/definePlugin.js +71 -31
- package/dist/config/detectDeadCode.js +120 -108
- package/dist/config/detectDeadCodePlugin.js +78 -63
- package/dist/config/fastRefreshPlugin.js +39 -20
- package/dist/config/forkTSCheckerPlugin.js +38 -19
- package/dist/config/harmonyLinkingErrorPlugin.js +48 -29
- package/dist/config/ignorePlugin.js +38 -14
- package/dist/config/javaScriptRules.js +147 -173
- package/dist/config/manifestPlugin.js +51 -15
- package/dist/config/miniCSSExtractPlugin.js +42 -22
- package/dist/config/nodePolyfill.js +65 -26
- package/dist/config/nodePrefixPlugin.js +36 -12
- package/dist/config/progressPlugin.js +37 -13
- package/dist/config/purgecssWebpackPlugin.js +41 -19
- package/dist/config/speedMeasureWebpackPlugin.js +41 -20
- package/dist/config/ssrPlugin.js +83 -63
- package/dist/config/svgRules.js +74 -46
- package/dist/constants.js +57 -22
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +170 -129
- package/dist/index.js +22 -20
- package/dist/loader/svgr.js +73 -54
- package/dist/loader/swc.js +110 -69
- package/dist/parcelCSS.js +31 -27
- package/dist/plugins/ProgressPlugin.js +66 -43
- package/dist/plugins/RuntimePublicPathPlugin.js +42 -23
- package/dist/plugins/_SamplePlugin.js +39 -14
- package/dist/requireHook.js +37 -27
- package/dist/schema.js +120 -95
- package/dist/server/server.d.ts +0 -1
- package/dist/server/server.js +214 -184
- package/dist/server/ws.d.ts +0 -2
- package/dist/server/ws.js +63 -38
- package/dist/swcPlugins/autoCSSModules.js +50 -31
- package/dist/swcPlugins/changeImportFromString.js +31 -9
- package/dist/swcPlugins/lockCoreJS.js +44 -20
- package/dist/types.d.ts +2 -1
- package/dist/types.js +61 -30
- package/dist/utils/browsersList.js +31 -8
- package/dist/utils/depMatch.js +63 -39
- package/dist/utils/formatWebpackMessages.js +93 -91
- package/dist/utils/getEsBuildTarget.js +32 -10
- package/package.json +12 -16
- package/compiled/fork-ts-checker-webpack-plugin/LICENSE +0 -21
- package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
- package/compiled/fork-ts-checker-webpack-plugin/index.js +0 -42
- package/compiled/fork-ts-checker-webpack-plugin/package.json +0 -1
- package/compiled/react-refresh/LICENSE +0 -21
- package/compiled/react-refresh/index.js +0 -21
- package/compiled/react-refresh/package.json +0 -1
- package/dist/client/client.js +0 -245
package/dist/config/cssRules.js
CHANGED
|
@@ -1,137 +1,142 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
|
|
39
|
+
// cssRules.ts
|
|
40
|
+
var cssRules_exports = {};
|
|
41
|
+
__export(cssRules_exports, {
|
|
42
|
+
addCSSRules: () => addCSSRules
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(cssRules_exports);
|
|
45
|
+
var import_utils = require("@umijs/utils");
|
|
5
46
|
async function addCSSRules(opts) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
47
|
+
const { config, userConfig } = opts;
|
|
48
|
+
const rulesConfig = [
|
|
49
|
+
{ name: "css", test: /\.css(\?.*)?$/ },
|
|
50
|
+
{
|
|
51
|
+
name: "less",
|
|
52
|
+
test: /\.less(\?.*)?$/,
|
|
53
|
+
loader: require.resolve("@umijs/bundler-webpack/compiled/less-loader"),
|
|
54
|
+
loaderOptions: {
|
|
55
|
+
implementation: require.resolve("@umijs/bundler-utils/compiled/less"),
|
|
56
|
+
lessOptions: __spreadValues({
|
|
57
|
+
modifyVars: userConfig.theme,
|
|
58
|
+
javascriptEnabled: true
|
|
59
|
+
}, userConfig.lessLoader)
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "sass",
|
|
64
|
+
test: /\.(sass|scss)(\?.*)?$/,
|
|
65
|
+
loader: require.resolve("@umijs/bundler-webpack/compiled/sass-loader"),
|
|
66
|
+
loaderOptions: userConfig.sassLoader || {}
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
for (const { name, test, loader, loaderOptions } of rulesConfig) {
|
|
70
|
+
const rule = config.module.rule(name);
|
|
71
|
+
const nestRulesConfig = [
|
|
72
|
+
userConfig.autoCSSModules && {
|
|
73
|
+
rule: rule.test(test).oneOf("css-modules").resourceQuery(/modules/),
|
|
74
|
+
isCSSModules: true
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
rule: rule.test(test).oneOf("css").sideEffects(true),
|
|
78
|
+
isCSSModules: false
|
|
79
|
+
}
|
|
80
|
+
].filter(Boolean);
|
|
81
|
+
for (const { rule: rule2, isCSSModules } of nestRulesConfig) {
|
|
82
|
+
if (userConfig.styleLoader) {
|
|
83
|
+
rule2.use("style-loader").loader(require.resolve("@umijs/bundler-webpack/compiled/style-loader")).options(__spreadValues({ base: 0, esModule: true }, userConfig.styleLoader));
|
|
84
|
+
} else {
|
|
85
|
+
rule2.use("mini-css-extract-plugin").loader(require.resolve("@umijs/bundler-webpack/compiled/mini-css-extract-plugin/loader")).options({
|
|
86
|
+
publicPath: "./",
|
|
87
|
+
emit: true,
|
|
88
|
+
esModule: true
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
rule2.use("css-loader").loader(require.resolve("css-loader")).options(__spreadValues(__spreadValues({
|
|
92
|
+
importLoaders: 1,
|
|
93
|
+
esModule: true,
|
|
94
|
+
url: {
|
|
95
|
+
filter: (url) => {
|
|
96
|
+
if (url.startsWith("/"))
|
|
97
|
+
return false;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
27
100
|
},
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
rule
|
|
63
|
-
.use('css-loader')
|
|
64
|
-
.loader(require.resolve('css-loader'))
|
|
65
|
-
.options({
|
|
66
|
-
importLoaders: 1,
|
|
67
|
-
esModule: true,
|
|
68
|
-
url: {
|
|
69
|
-
filter: (url) => {
|
|
70
|
-
// Don't parse absolute URLs
|
|
71
|
-
// ref: https://github.com/webpack-contrib/css-loader#url
|
|
72
|
-
if (url.startsWith('/'))
|
|
73
|
-
return false;
|
|
74
|
-
return true;
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
import: true,
|
|
78
|
-
...(isCSSModules
|
|
79
|
-
? {
|
|
80
|
-
modules: {
|
|
81
|
-
localIdentName: '[local]___[hash:base64:5]',
|
|
82
|
-
...userConfig.cssLoaderModules,
|
|
83
|
-
// If SSR is enabled, we need to handling the css modules name hashing
|
|
84
|
-
// and save the class names mapping into opts.cssModulesMapping
|
|
85
|
-
// so the esbuild can use it to generate the correct name for the server side
|
|
86
|
-
getLocalIdent: userConfig.ssr &&
|
|
87
|
-
((context, localIdentName, localName, opt) => {
|
|
88
|
-
const classIdent = ((0, utils_1.winPath)(context.resourcePath).replace((0, utils_1.winPath)(ensureLastSlash(opt.context)), '') +
|
|
89
|
-
'@' +
|
|
90
|
-
localName).trim();
|
|
91
|
-
let hash = Buffer.from(classIdent)
|
|
92
|
-
.toString('base64')
|
|
93
|
-
.replace(/=/g, '');
|
|
94
|
-
hash = hash.substring(hash.length - 5);
|
|
95
|
-
const result = localIdentName
|
|
96
|
-
.replace(/\[local]/g, localName)
|
|
97
|
-
.replace(/\[hash[^\[]*?]/g, hash);
|
|
98
|
-
return result;
|
|
99
|
-
}),
|
|
100
|
-
},
|
|
101
|
-
}
|
|
102
|
-
: {}),
|
|
103
|
-
...userConfig.cssLoader,
|
|
104
|
-
});
|
|
105
|
-
rule
|
|
106
|
-
.use('postcss-loader')
|
|
107
|
-
.loader(require.resolve('@umijs/bundler-webpack/compiled/postcss-loader'))
|
|
108
|
-
.options({
|
|
109
|
-
postcssOptions: {
|
|
110
|
-
ident: 'postcss',
|
|
111
|
-
plugins: [
|
|
112
|
-
require('@umijs/bundler-webpack/compiled/postcss-flexbugs-fixes'),
|
|
113
|
-
require('postcss-preset-env')({
|
|
114
|
-
browsers: opts.browsers,
|
|
115
|
-
autoprefixer: {
|
|
116
|
-
flexbox: 'no-2009',
|
|
117
|
-
...userConfig.autoprefixer,
|
|
118
|
-
},
|
|
119
|
-
stage: 3,
|
|
120
|
-
}),
|
|
121
|
-
].concat(userConfig.extraPostCSSPlugins || []),
|
|
122
|
-
...userConfig.postcssLoader,
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
if (loader) {
|
|
126
|
-
rule
|
|
127
|
-
.use(loader)
|
|
128
|
-
.loader(typeof loader === 'string' ? require.resolve(loader) : loader)
|
|
129
|
-
.options(loaderOptions || {});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
101
|
+
import: true
|
|
102
|
+
}, isCSSModules ? {
|
|
103
|
+
modules: __spreadProps(__spreadValues({
|
|
104
|
+
localIdentName: "[local]___[hash:base64:5]"
|
|
105
|
+
}, userConfig.cssLoaderModules), {
|
|
106
|
+
getLocalIdent: userConfig.ssr && ((context, localIdentName, localName, opt) => {
|
|
107
|
+
const classIdent = ((0, import_utils.winPath)(context.resourcePath).replace((0, import_utils.winPath)(ensureLastSlash(opt.context)), "") + "@" + localName).trim();
|
|
108
|
+
let hash = Buffer.from(classIdent).toString("base64").replace(/=/g, "");
|
|
109
|
+
hash = hash.substring(hash.length - 5);
|
|
110
|
+
const result = localIdentName.replace(/\[local]/g, localName).replace(/\[hash[^\[]*?]/g, hash);
|
|
111
|
+
return result;
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
} : {}), userConfig.cssLoader));
|
|
115
|
+
rule2.use("postcss-loader").loader(require.resolve("@umijs/bundler-webpack/compiled/postcss-loader")).options({
|
|
116
|
+
postcssOptions: __spreadValues({
|
|
117
|
+
ident: "postcss",
|
|
118
|
+
plugins: [
|
|
119
|
+
require("@umijs/bundler-webpack/compiled/postcss-flexbugs-fixes"),
|
|
120
|
+
require("postcss-preset-env")({
|
|
121
|
+
browsers: opts.browsers,
|
|
122
|
+
autoprefixer: __spreadValues({
|
|
123
|
+
flexbox: "no-2009"
|
|
124
|
+
}, userConfig.autoprefixer),
|
|
125
|
+
stage: 3
|
|
126
|
+
})
|
|
127
|
+
].concat(userConfig.extraPostCSSPlugins || [])
|
|
128
|
+
}, userConfig.postcssLoader)
|
|
129
|
+
});
|
|
130
|
+
if (loader) {
|
|
131
|
+
rule2.use(loader).loader(typeof loader === "string" ? require.resolve(loader) : loader).options(loaderOptions || {});
|
|
132
|
+
}
|
|
132
133
|
}
|
|
134
|
+
}
|
|
133
135
|
}
|
|
134
|
-
exports.addCSSRules = addCSSRules;
|
|
135
136
|
function ensureLastSlash(path) {
|
|
136
|
-
|
|
137
|
+
return path.endsWith("/") ? path : path + "/";
|
|
137
138
|
}
|
|
139
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
140
|
+
0 && (module.exports = {
|
|
141
|
+
addCSSRules
|
|
142
|
+
});
|
|
@@ -1,37 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
22
|
+
};
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
+
for (let key of __getOwnPropNames(from))
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// definePlugin.ts
|
|
34
|
+
var definePlugin_exports = {};
|
|
35
|
+
__export(definePlugin_exports, {
|
|
36
|
+
addDefinePlugin: () => addDefinePlugin,
|
|
37
|
+
resolveDefine: () => resolveDefine
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(definePlugin_exports);
|
|
40
|
+
var import_webpack = require("@umijs/bundler-webpack/compiled/webpack");
|
|
41
|
+
var prefixRE = /^UMI_APP_/;
|
|
42
|
+
var ENV_SHOULD_PASS = ["NODE_ENV", "HMR", "SOCKET_SERVER", "ERROR_OVERLAY"];
|
|
7
43
|
function resolveDefine(opts) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
for (const key in env) {
|
|
15
|
-
env[key] = JSON.stringify(env[key]);
|
|
44
|
+
const env = {};
|
|
45
|
+
Object.keys(process.env).forEach((key) => {
|
|
46
|
+
if (prefixRE.test(key) || ENV_SHOULD_PASS.includes(key)) {
|
|
47
|
+
env[key] = process.env[key];
|
|
16
48
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
49
|
+
});
|
|
50
|
+
env.PUBLIC_PATH = opts.publicPath || "/";
|
|
51
|
+
for (const key in env) {
|
|
52
|
+
env[key] = JSON.stringify(env[key]);
|
|
53
|
+
}
|
|
54
|
+
const define = {};
|
|
55
|
+
if (opts.define) {
|
|
56
|
+
for (const key in opts.define) {
|
|
57
|
+
define[key] = JSON.stringify(opts.define[key]);
|
|
22
58
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
59
|
+
}
|
|
60
|
+
return __spreadValues({
|
|
61
|
+
"process.env": env
|
|
62
|
+
}, define);
|
|
27
63
|
}
|
|
28
|
-
exports.resolveDefine = resolveDefine;
|
|
29
64
|
async function addDefinePlugin(opts) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
65
|
+
const { config, userConfig } = opts;
|
|
66
|
+
config.plugin("define").use(import_webpack.DefinePlugin, [
|
|
67
|
+
resolveDefine({
|
|
68
|
+
define: userConfig.define || {},
|
|
69
|
+
publicPath: userConfig.publicPath
|
|
70
|
+
})
|
|
71
|
+
]);
|
|
36
72
|
}
|
|
37
|
-
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
addDefinePlugin,
|
|
76
|
+
resolveDefine
|
|
77
|
+
});
|
|
@@ -1,120 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
10
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// detectDeadCode.ts
|
|
23
|
+
var detectDeadCode_exports = {};
|
|
24
|
+
__export(detectDeadCode_exports, {
|
|
25
|
+
default: () => detectDeadCode_default,
|
|
26
|
+
disabledFolders: () => disabledFolders
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(detectDeadCode_exports);
|
|
29
|
+
var import_webpack = require("@umijs/bundler-webpack/compiled/webpack");
|
|
30
|
+
var import_utils = require("@umijs/utils");
|
|
31
|
+
var import_path = __toESM(require("path"));
|
|
32
|
+
var disabledFolders = [
|
|
33
|
+
"node_modules",
|
|
34
|
+
".umi",
|
|
35
|
+
".umi-production",
|
|
36
|
+
"dist"
|
|
15
37
|
];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
logUnusedFiles(unusedFiles);
|
|
29
|
-
logUnusedExportMap(unusedExportMap);
|
|
30
|
-
const hasUnusedThings = unusedFiles.length || Object.keys(unusedExportMap).length;
|
|
31
|
-
if (hasUnusedThings && options.failOnHint) {
|
|
32
|
-
process.exit(2);
|
|
33
|
-
}
|
|
38
|
+
var detectDeadCode = (compilation, options) => {
|
|
39
|
+
const assets = getWebpackAssets(compilation);
|
|
40
|
+
const compiledFilesDictionary = convertFilesToDict(assets);
|
|
41
|
+
const includedFiles = getPattern(options).map((pattern) => import_utils.glob.sync(pattern)).flat();
|
|
42
|
+
const unusedFiles = options.detectUnusedFiles ? includedFiles.filter((file) => !compiledFilesDictionary[file]) : [];
|
|
43
|
+
const unusedExportMap = options.detectUnusedExport ? getUnusedExportMap(convertFilesToDict(includedFiles), compilation) : {};
|
|
44
|
+
logUnusedFiles(unusedFiles);
|
|
45
|
+
logUnusedExportMap(unusedExportMap);
|
|
46
|
+
const hasUnusedThings = unusedFiles.length || Object.keys(unusedExportMap).length;
|
|
47
|
+
if (hasUnusedThings && options.failOnHint) {
|
|
48
|
+
process.exit(2);
|
|
49
|
+
}
|
|
34
50
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.map((pattern) => path_1.default.resolve(options.context || '', pattern))
|
|
38
|
-
.concat(options.exclude.map((pattern) => path_1.default.resolve(options.context || '', `!${pattern}`)))
|
|
39
|
-
.map(convertToUnixPath);
|
|
51
|
+
var getPattern = (options) => {
|
|
52
|
+
return options.patterns.map((pattern) => import_path.default.resolve(options.context || "", pattern)).concat(options.exclude.map((pattern) => import_path.default.resolve(options.context || "", `!${pattern}`))).map(convertToUnixPath);
|
|
40
53
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
54
|
+
var getUnusedExportMap = (includedFileMap, compilation) => {
|
|
55
|
+
const unusedExportMap = {};
|
|
56
|
+
compilation.chunks.forEach((chunk) => {
|
|
57
|
+
compilation.chunkGraph.getChunkModules(chunk).forEach((module2) => {
|
|
58
|
+
outputUnusedExportMap(compilation, chunk, module2, includedFileMap, unusedExportMap);
|
|
47
59
|
});
|
|
48
|
-
|
|
60
|
+
});
|
|
61
|
+
return unusedExportMap;
|
|
49
62
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (unusedExports.length) {
|
|
70
|
-
unusedExportMap[path] = unusedExports;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
63
|
+
var outputUnusedExportMap = (compilation, chunk, module2, includedFileMap, unusedExportMap) => {
|
|
64
|
+
if (!(module2 instanceof import_webpack.NormalModule) || !module2.resource) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const path2 = convertToUnixPath(module2.resource);
|
|
68
|
+
if (!/^((?!(node_modules)).)*$/.test(path2))
|
|
69
|
+
return;
|
|
70
|
+
const providedExports = compilation.chunkGraph.moduleGraph.getProvidedExports(module2);
|
|
71
|
+
const usedExports = compilation.chunkGraph.moduleGraph.getUsedExports(module2, chunk.runtime);
|
|
72
|
+
if (usedExports !== true && providedExports !== true && includedFileMap[path2]) {
|
|
73
|
+
if (usedExports === false) {
|
|
74
|
+
if (providedExports == null ? void 0 : providedExports.length) {
|
|
75
|
+
unusedExportMap[path2] = providedExports;
|
|
76
|
+
}
|
|
77
|
+
} else if (providedExports instanceof Array) {
|
|
78
|
+
const unusedExports = providedExports.filter((item) => usedExports && !usedExports.has(item));
|
|
79
|
+
if (unusedExports.length) {
|
|
80
|
+
unusedExportMap[path2] = unusedExports;
|
|
81
|
+
}
|
|
73
82
|
}
|
|
83
|
+
}
|
|
74
84
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
var logUnusedExportMap = (unusedExportMap) => {
|
|
86
|
+
if (!Object.keys(unusedExportMap).length) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
let numberOfUnusedExport = 0;
|
|
90
|
+
let logStr = "";
|
|
91
|
+
Object.keys(unusedExportMap).forEach((filePath, fileIndex) => {
|
|
92
|
+
const unusedExports = unusedExportMap[filePath];
|
|
93
|
+
logStr += [
|
|
94
|
+
`
|
|
95
|
+
${fileIndex + 1}. `,
|
|
96
|
+
import_utils.chalk.yellow(`${filePath}
|
|
97
|
+
`),
|
|
98
|
+
" >>> ",
|
|
99
|
+
import_utils.chalk.yellow(`${unusedExports.join(", ")}`)
|
|
100
|
+
].join("");
|
|
101
|
+
numberOfUnusedExport += unusedExports.length;
|
|
102
|
+
});
|
|
103
|
+
console.log(import_utils.chalk.yellow.bold("\nWarning:"), import_utils.chalk.yellow(`There are ${numberOfUnusedExport} unused exports in ${Object.keys(unusedExportMap).length} files:`), logStr, import_utils.chalk.red.bold("\nPlease be careful if you want to remove them (\xAC\xBA-\xB0)\xAC.\n"));
|
|
92
104
|
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
];
|
|
101
|
-
return assets;
|
|
105
|
+
var getWebpackAssets = (compilation) => {
|
|
106
|
+
const outputPath = compilation.getPath(compilation.compiler.outputPath);
|
|
107
|
+
const assets = [
|
|
108
|
+
...Array.from(compilation.fileDependencies),
|
|
109
|
+
...compilation.getAssets().map((asset) => import_path.default.join(outputPath, asset.name))
|
|
110
|
+
];
|
|
111
|
+
return assets;
|
|
102
112
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
fileDictionary[unixFile] = true;
|
|
110
|
-
return fileDictionary;
|
|
111
|
-
}, {});
|
|
113
|
+
var convertFilesToDict = (assets) => {
|
|
114
|
+
return assets.filter((file) => Boolean(file) && disabledFolders.every((disabledPath) => !file.includes(disabledPath))).reduce((fileDictionary, file) => {
|
|
115
|
+
const unixFile = convertToUnixPath(file);
|
|
116
|
+
fileDictionary[unixFile] = true;
|
|
117
|
+
return fileDictionary;
|
|
118
|
+
}, {});
|
|
112
119
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
var logUnusedFiles = (unusedFiles) => {
|
|
121
|
+
if (!(unusedFiles == null ? void 0 : unusedFiles.length)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
console.log(import_utils.chalk.yellow.bold("\nWarning:"), import_utils.chalk.yellow(`There are ${unusedFiles.length} unused files:`), ...unusedFiles.map((file, index) => `
|
|
125
|
+
${index + 1}. ${import_utils.chalk.yellow(file)}`), import_utils.chalk.red.bold("\nPlease be careful if you want to remove them (\xAC\xBA-\xB0)\xAC.\n"));
|
|
118
126
|
};
|
|
119
|
-
|
|
120
|
-
|
|
127
|
+
var convertToUnixPath = (path2) => path2.replace(/\\+/g, "/");
|
|
128
|
+
var detectDeadCode_default = detectDeadCode;
|
|
129
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
130
|
+
0 && (module.exports = {
|
|
131
|
+
disabledFolders
|
|
132
|
+
});
|