@umijs/bundler-webpack 4.0.15 → 4.0.16
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/config/config.js +1 -1
- package/dist/config/detectDeadCode.d.ts +1 -1
- package/dist/config/detectDeadCode.js +40 -15
- package/dist/config/detectDeadCodePlugin.js +1 -1
- package/dist/dev.d.ts +3 -0
- package/dist/dev.js +2 -1
- package/dist/server/server.js +1 -1
- package/dist/types.d.ts +11 -3
- package/package.json +5 -5
package/dist/config/config.js
CHANGED
|
@@ -103,7 +103,7 @@ async function getConfig(opts) {
|
|
|
103
103
|
config.devtool(isDev ? userConfig.devtool === false ? false : userConfig.devtool || import_constants.DEFAULT_DEVTOOL : userConfig.devtool);
|
|
104
104
|
const absOutputPath = (0, import_path.resolve)(opts.cwd, userConfig.outputPath || import_constants.DEFAULT_OUTPUT_PATH);
|
|
105
105
|
const disableCompress = process.env.COMPRESS === "none";
|
|
106
|
-
config.output.path(absOutputPath).filename(useHash ? `[name].[contenthash:8].js` : `[name].js`).chunkFilename(useHash ? `[name].[contenthash:8].async.js` : `[name].async.js`).publicPath(userConfig.publicPath || "auto").pathinfo(isDev || disableCompress).set("assetModuleFilename", `${applyOpts.staticPathPrefix}[name].[hash:8][ext]`);
|
|
106
|
+
config.output.path(absOutputPath).filename(useHash ? `[name].[contenthash:8].js` : `[name].js`).chunkFilename(useHash ? `[name].[contenthash:8].async.js` : `[name].async.js`).publicPath(userConfig.publicPath || "auto").pathinfo(isDev || disableCompress).set("assetModuleFilename", `${applyOpts.staticPathPrefix}[name].[hash:8][ext]`).set("hashFunction", "xxhash64");
|
|
107
107
|
config.resolve.set("symlinks", true).modules.add("node_modules").end().alias.merge(userConfig.alias || {}).end().extensions.merge([
|
|
108
108
|
".wasm",
|
|
109
109
|
".mjs",
|
|
@@ -7,6 +7,6 @@ export interface Options extends DeadCodeParams {
|
|
|
7
7
|
detectUnusedFiles: boolean;
|
|
8
8
|
detectUnusedExport: boolean;
|
|
9
9
|
}
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const ignores: string[];
|
|
11
11
|
declare const detectDeadCode: (compilation: Compilation, options: Options) => void;
|
|
12
12
|
export default detectDeadCode;
|
|
@@ -23,22 +23,37 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
23
23
|
var detectDeadCode_exports = {};
|
|
24
24
|
__export(detectDeadCode_exports, {
|
|
25
25
|
default: () => detectDeadCode_default,
|
|
26
|
-
|
|
26
|
+
ignores: () => ignores
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(detectDeadCode_exports);
|
|
29
29
|
var import_webpack = require("@umijs/bundler-webpack/compiled/webpack");
|
|
30
30
|
var import_utils = require("@umijs/utils");
|
|
31
31
|
var import_path = __toESM(require("path"));
|
|
32
|
-
var
|
|
33
|
-
"node_modules",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
32
|
+
var ignores = [
|
|
33
|
+
"**/node_modules/**",
|
|
34
|
+
"**/.umi/**",
|
|
35
|
+
"**/.umi-production/**",
|
|
36
|
+
"**/.umi-test/**",
|
|
37
|
+
"coverage/**",
|
|
38
|
+
"dist/**",
|
|
39
|
+
"config/**",
|
|
40
|
+
"public/**",
|
|
41
|
+
"mock/**"
|
|
37
42
|
];
|
|
38
43
|
var detectDeadCode = (compilation, options) => {
|
|
39
44
|
const assets = getWebpackAssets(compilation);
|
|
40
45
|
const compiledFilesDictionary = convertFilesToDict(assets);
|
|
41
|
-
const
|
|
46
|
+
const context = options.context;
|
|
47
|
+
if (!options.patterns.length) {
|
|
48
|
+
options.patterns = getDefaultSourcePattern({ cwd: context });
|
|
49
|
+
}
|
|
50
|
+
const includedFiles = options.patterns.map((pattern) => {
|
|
51
|
+
return import_utils.glob.sync(pattern, {
|
|
52
|
+
ignore: [...ignores, ...options.exclude],
|
|
53
|
+
cwd: context,
|
|
54
|
+
absolute: true
|
|
55
|
+
});
|
|
56
|
+
}).flat();
|
|
42
57
|
const unusedFiles = options.detectUnusedFiles ? includedFiles.filter((file) => !compiledFilesDictionary[file]) : [];
|
|
43
58
|
const unusedExportMap = options.detectUnusedExport ? getUnusedExportMap(convertFilesToDict(includedFiles), compilation) : {};
|
|
44
59
|
logUnusedFiles(unusedFiles);
|
|
@@ -48,9 +63,6 @@ var detectDeadCode = (compilation, options) => {
|
|
|
48
63
|
process.exit(2);
|
|
49
64
|
}
|
|
50
65
|
};
|
|
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);
|
|
53
|
-
};
|
|
54
66
|
var getUnusedExportMap = (includedFileMap, compilation) => {
|
|
55
67
|
const unusedExportMap = {};
|
|
56
68
|
compilation.chunks.forEach((chunk) => {
|
|
@@ -64,7 +76,7 @@ var outputUnusedExportMap = (compilation, chunk, module2, includedFileMap, unuse
|
|
|
64
76
|
if (!(module2 instanceof import_webpack.NormalModule) || !module2.resource) {
|
|
65
77
|
return;
|
|
66
78
|
}
|
|
67
|
-
const path2 =
|
|
79
|
+
const path2 = (0, import_utils.winPath)(module2.resource);
|
|
68
80
|
if (!/^((?!(node_modules)).)*$/.test(path2))
|
|
69
81
|
return;
|
|
70
82
|
const providedExports = compilation.chunkGraph.moduleGraph.getProvidedExports(module2);
|
|
@@ -111,8 +123,8 @@ var getWebpackAssets = (compilation) => {
|
|
|
111
123
|
return assets;
|
|
112
124
|
};
|
|
113
125
|
var convertFilesToDict = (assets) => {
|
|
114
|
-
return assets.filter((
|
|
115
|
-
const unixFile =
|
|
126
|
+
return assets.filter((path2) => !/(node_modules|(\.umi))/.test(path2) && Boolean(path2)).reduce((fileDictionary, file) => {
|
|
127
|
+
const unixFile = (0, import_utils.winPath)(file);
|
|
116
128
|
fileDictionary[unixFile] = true;
|
|
117
129
|
return fileDictionary;
|
|
118
130
|
}, {});
|
|
@@ -124,9 +136,22 @@ var logUnusedFiles = (unusedFiles) => {
|
|
|
124
136
|
console.log(import_utils.chalk.yellow.bold("\nWarning:"), import_utils.chalk.yellow(`There are ${unusedFiles.length} unused files:`), ...unusedFiles.map((file, index) => `
|
|
125
137
|
${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"));
|
|
126
138
|
};
|
|
127
|
-
|
|
139
|
+
function isDirExist(p) {
|
|
140
|
+
return import_utils.fsExtra.existsSync(p) && import_utils.fsExtra.statSync(p).isDirectory();
|
|
141
|
+
}
|
|
142
|
+
function getDefaultSourcePattern(opts) {
|
|
143
|
+
const { cwd } = opts;
|
|
144
|
+
const srcPath = import_path.default.join(cwd, "src");
|
|
145
|
+
if (isDirExist(srcPath)) {
|
|
146
|
+
return ["src/**/*"];
|
|
147
|
+
}
|
|
148
|
+
const dirs = import_utils.fsExtra.readdirSync(cwd).filter((p) => {
|
|
149
|
+
return !p.startsWith(".") && isDirExist(p);
|
|
150
|
+
});
|
|
151
|
+
return dirs.map((dir) => `${dir}/**/*`);
|
|
152
|
+
}
|
|
128
153
|
var detectDeadCode_default = detectDeadCode;
|
|
129
154
|
// Annotate the CommonJS export names for ESM import in node:
|
|
130
155
|
0 && (module.exports = {
|
|
131
|
-
|
|
156
|
+
ignores
|
|
132
157
|
});
|
|
@@ -45,7 +45,7 @@ module.exports = __toCommonJS(detectDeadCodePlugin_exports);
|
|
|
45
45
|
var import_types = require("../types");
|
|
46
46
|
var import_detectDeadCode = __toESM(require("./detectDeadCode"));
|
|
47
47
|
var defaultOptions = {
|
|
48
|
-
patterns: [
|
|
48
|
+
patterns: [],
|
|
49
49
|
exclude: [],
|
|
50
50
|
failOnHint: false,
|
|
51
51
|
detectUnusedFiles: true,
|
package/dist/dev.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Worker } from 'worker_threads';
|
|
1
3
|
import { IOpts as IConfigOpts } from './config/config';
|
|
2
4
|
import { IConfig } from './types';
|
|
3
5
|
declare type IOpts = {
|
|
@@ -24,6 +26,7 @@ declare type IOpts = {
|
|
|
24
26
|
mfsuInclude?: string[];
|
|
25
27
|
mfsuServerBase?: string;
|
|
26
28
|
srcCodeCache?: any;
|
|
29
|
+
startBuildWorker?: (deps: any[]) => Worker;
|
|
27
30
|
} & Pick<IConfigOpts, 'cache' | 'pkg'>;
|
|
28
31
|
export declare function stripUndefined(obj: any): any;
|
|
29
32
|
export declare function dev(opts: IOpts): Promise<void>;
|
package/dist/dev.js
CHANGED
|
@@ -97,7 +97,8 @@ async function dev(opts) {
|
|
|
97
97
|
publicPath: opts.config.publicPath
|
|
98
98
|
});
|
|
99
99
|
},
|
|
100
|
-
serverBase: opts.mfsuServerBase
|
|
100
|
+
serverBase: opts.mfsuServerBase,
|
|
101
|
+
startBuildWorker: opts.startBuildWorker
|
|
101
102
|
});
|
|
102
103
|
}
|
|
103
104
|
const webpackConfig = await (0, import_config.getConfig)({
|
package/dist/server/server.js
CHANGED
|
@@ -169,7 +169,7 @@ async function createServer(opts) {
|
|
|
169
169
|
if (proxyReq.getHeader("origin")) {
|
|
170
170
|
proxyReq.setHeader("origin", ((_a = new URL(proxy2.target)) == null ? void 0 : _a.href) || "");
|
|
171
171
|
}
|
|
172
|
-
(_b = proxy2.onProxyReq) == null ? void 0 : _b.call(proxy2, proxyReq, req, res);
|
|
172
|
+
(_b = proxy2.onProxyReq) == null ? void 0 : _b.call(proxy2, proxyReq, req, res, proxy2);
|
|
173
173
|
},
|
|
174
174
|
onProxyRes(proxyRes, req, res) {
|
|
175
175
|
var _a, _b;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Config as SwcConfig } from '@swc/core';
|
|
2
2
|
import type { HttpsServerOptions } from '@umijs/bundler-utils';
|
|
3
|
-
import type { Options as
|
|
3
|
+
import type { Options as HPMOptions } from '../compiled/http-proxy-middleware';
|
|
4
4
|
import { Configuration } from '../compiled/webpack';
|
|
5
5
|
import Config from '../compiled/webpack-5-chain';
|
|
6
6
|
export declare enum Env {
|
|
@@ -33,7 +33,9 @@ export interface ICopy {
|
|
|
33
33
|
declare type WebpackConfig = Required<Configuration>;
|
|
34
34
|
declare type IBabelPlugin = Function | string | [string, {
|
|
35
35
|
[key: string]: any;
|
|
36
|
-
}]
|
|
36
|
+
}] | [string, {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}, string];
|
|
37
39
|
export interface DeadCodeParams {
|
|
38
40
|
patterns?: string[];
|
|
39
41
|
exclude?: string[];
|
|
@@ -42,6 +44,12 @@ export interface DeadCodeParams {
|
|
|
42
44
|
detectUnusedExport?: boolean;
|
|
43
45
|
context?: string;
|
|
44
46
|
}
|
|
47
|
+
declare type HPMFnArgs = Parameters<NonNullable<HPMOptions['onProxyReq']>>;
|
|
48
|
+
export interface ProxyOptions extends HPMOptions {
|
|
49
|
+
target?: string;
|
|
50
|
+
context?: string | string[];
|
|
51
|
+
bypass?: (...args: [HPMFnArgs[1], HPMFnArgs[2], HPMFnArgs[3]]) => string | boolean | null | void;
|
|
52
|
+
}
|
|
45
53
|
export interface IConfig {
|
|
46
54
|
alias?: Record<string, string>;
|
|
47
55
|
autoCSSModules?: boolean;
|
|
@@ -88,7 +96,7 @@ export interface IConfig {
|
|
|
88
96
|
};
|
|
89
97
|
proxy?: {
|
|
90
98
|
[key: string]: ProxyOptions;
|
|
91
|
-
};
|
|
99
|
+
} | ProxyOptions[];
|
|
92
100
|
publicPath?: string;
|
|
93
101
|
purgeCSS?: {
|
|
94
102
|
[key: string]: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/bundler-webpack",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.16",
|
|
4
4
|
"description": "@umijs/bundler-webpack",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/bundler-webpack#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"@svgr/plugin-jsx": "^6.2.1",
|
|
35
35
|
"@svgr/plugin-svgo": "^6.2.0",
|
|
36
36
|
"@types/hapi__joi": "17.1.8",
|
|
37
|
-
"@umijs/babel-preset-umi": "4.0.
|
|
38
|
-
"@umijs/bundler-utils": "4.0.
|
|
37
|
+
"@umijs/babel-preset-umi": "4.0.16",
|
|
38
|
+
"@umijs/bundler-utils": "4.0.16",
|
|
39
39
|
"@umijs/case-sensitive-paths-webpack-plugin": "^1.0.1",
|
|
40
|
-
"@umijs/mfsu": "4.0.
|
|
41
|
-
"@umijs/utils": "4.0.
|
|
40
|
+
"@umijs/mfsu": "4.0.16",
|
|
41
|
+
"@umijs/utils": "4.0.16",
|
|
42
42
|
"cors": "^2.8.5",
|
|
43
43
|
"css-loader": "6.7.1",
|
|
44
44
|
"es5-imcompatible-versions": "^0.1.73",
|