@umijs/bundler-webpack 4.0.0-rc.1 → 4.0.0-rc.2
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/compiled/autoprefixer/browserslist/index.d.ts +4 -0
- 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/declaration.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
- package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
- package/compiled/copy-webpack-plugin/576.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/express/index.js +57 -74
- package/compiled/fork-ts-checker-webpack-plugin/index.js +14 -15
- 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 +4427 -3979
- package/compiled/mini-css-extract-plugin/loader.js +177 -54
- package/compiled/mini-css-extract-plugin/package.json +1 -1
- package/compiled/mini-css-extract-plugin/utils.js +77 -23
- package/compiled/sass-loader/index.js +1 -1
- package/compiled/terser-webpack-plugin/index.js +296 -297
- package/compiled/terser-webpack-plugin/minify.js +4 -2
- package/compiled/terser-webpack-plugin/package.json +1 -1
- package/compiled/terser-webpack-plugin/types/index.d.ts +180 -146
- package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
- package/compiled/terser-webpack-plugin/types/utils.d.ts +1 -3
- package/compiled/terser-webpack-plugin/utils.js +9 -12
- package/compiled/webpack/index.js +8652 -3904
- package/compiled/webpack-dev-middleware/index.js +7 -7
- package/compiled/webpack-dev-middleware/package.json +1 -1
- package/compiled/webpack-manifest-plugin/index.js +1 -1
- 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 +2 -1
- package/dist/build.js +1 -1
- package/dist/config/config.js +4 -3
- 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 +71 -0
- package/dist/config/javaScriptRules.js +3 -6
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +4 -1
- package/dist/dev.d.ts +1 -0
- package/dist/dev.js +7 -5
- package/dist/loader/swc.js +14 -18
- package/dist/requireHook.js +1 -1
- package/dist/schema.js +2 -0
- package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
- package/dist/swcPlugins/autoCSSModules.js +11 -16
- package/dist/types.d.ts +9 -12
- package/dist/utils/depMatch.js +1 -1
- package/package.json +31 -31
- package/dist/esbuildHandler/autoCssModules.d.ts +0 -2
- package/dist/esbuildHandler/autoCssModules.js +0 -23
- package/dist/loader/esbuild.d.ts +0 -5
- package/dist/loader/esbuild.js +0 -53
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.disabledFolders = void 0;
|
|
7
|
+
const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
|
|
8
|
+
const utils_1 = require("@umijs/utils");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
exports.disabledFolders = [
|
|
11
|
+
'node_modules',
|
|
12
|
+
'.umi',
|
|
13
|
+
'.umi-production',
|
|
14
|
+
'dist',
|
|
15
|
+
];
|
|
16
|
+
const detectDeadCode = (compilation, options) => {
|
|
17
|
+
const assets = getWebpackAssets(compilation);
|
|
18
|
+
const compiledFilesDictionary = convertFilesToDict(assets);
|
|
19
|
+
const includedFiles = getPattern(options)
|
|
20
|
+
.map((pattern) => utils_1.glob.sync(pattern))
|
|
21
|
+
.flat();
|
|
22
|
+
const unusedFiles = options.detectUnusedFiles
|
|
23
|
+
? includedFiles.filter((file) => !compiledFilesDictionary[file])
|
|
24
|
+
: [];
|
|
25
|
+
const unusedExportMap = options.detectUnusedExport
|
|
26
|
+
? getUnusedExportMap(convertFilesToDict(includedFiles), compilation)
|
|
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
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const getPattern = (options) => {
|
|
36
|
+
return options.patterns
|
|
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);
|
|
40
|
+
};
|
|
41
|
+
const getUnusedExportMap = (includedFileMap, compilation) => {
|
|
42
|
+
const unusedExportMap = {};
|
|
43
|
+
compilation.chunks.forEach((chunk) => {
|
|
44
|
+
compilation.chunkGraph.getChunkModules(chunk).forEach((module) => {
|
|
45
|
+
outputUnusedExportMap(compilation, chunk, module, includedFileMap, unusedExportMap);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
return unusedExportMap;
|
|
49
|
+
};
|
|
50
|
+
const outputUnusedExportMap = (compilation, chunk, module, includedFileMap, unusedExportMap) => {
|
|
51
|
+
if (!(module instanceof webpack_1.NormalModule) || !module.resource) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const path = convertToUnixPath(module.resource);
|
|
55
|
+
if (!/^((?!(node_modules)).)*$/.test(path))
|
|
56
|
+
return;
|
|
57
|
+
const providedExports = compilation.chunkGraph.moduleGraph.getProvidedExports(module);
|
|
58
|
+
const usedExports = compilation.chunkGraph.moduleGraph.getUsedExports(module, chunk.runtime);
|
|
59
|
+
if (usedExports !== true &&
|
|
60
|
+
providedExports !== true &&
|
|
61
|
+
includedFileMap[path]) {
|
|
62
|
+
if (usedExports === false) {
|
|
63
|
+
if (providedExports === null || providedExports === void 0 ? void 0 : providedExports.length) {
|
|
64
|
+
unusedExportMap[path] = providedExports;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (providedExports instanceof Array) {
|
|
68
|
+
const unusedExports = providedExports.filter((item) => usedExports && !usedExports.has(item));
|
|
69
|
+
if (unusedExports.length) {
|
|
70
|
+
unusedExportMap[path] = unusedExports;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const logUnusedExportMap = (unusedExportMap) => {
|
|
76
|
+
if (!Object.keys(unusedExportMap).length) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
let numberOfUnusedExport = 0;
|
|
80
|
+
let logStr = '';
|
|
81
|
+
Object.keys(unusedExportMap).forEach((filePath, fileIndex) => {
|
|
82
|
+
const unusedExports = unusedExportMap[filePath];
|
|
83
|
+
logStr += [
|
|
84
|
+
`\n${fileIndex + 1}. `,
|
|
85
|
+
utils_1.chalk.yellow(`${filePath}\n`),
|
|
86
|
+
' >>> ',
|
|
87
|
+
utils_1.chalk.yellow(`${unusedExports.join(', ')}`),
|
|
88
|
+
].join('');
|
|
89
|
+
numberOfUnusedExport += unusedExports.length;
|
|
90
|
+
});
|
|
91
|
+
console.log(utils_1.chalk.yellow.bold('\nWarning:'), utils_1.chalk.yellow(`There are ${numberOfUnusedExport} unused exports in ${Object.keys(unusedExportMap).length} files:`), logStr, utils_1.chalk.red.bold('\nPlease be careful if you want to remove them (¬º-°)¬.\n'));
|
|
92
|
+
};
|
|
93
|
+
const getWebpackAssets = (compilation) => {
|
|
94
|
+
const outputPath = compilation.getPath(compilation.compiler.outputPath);
|
|
95
|
+
const assets = [
|
|
96
|
+
...Array.from(compilation.fileDependencies),
|
|
97
|
+
...compilation
|
|
98
|
+
.getAssets()
|
|
99
|
+
.map((asset) => path_1.default.join(outputPath, asset.name)),
|
|
100
|
+
];
|
|
101
|
+
return assets;
|
|
102
|
+
};
|
|
103
|
+
const convertFilesToDict = (assets) => {
|
|
104
|
+
return assets
|
|
105
|
+
.filter((file) => Boolean(file) &&
|
|
106
|
+
exports.disabledFolders.every((disabledPath) => !file.includes(disabledPath)))
|
|
107
|
+
.reduce((fileDictionary, file) => {
|
|
108
|
+
const unixFile = convertToUnixPath(file);
|
|
109
|
+
fileDictionary[unixFile] = true;
|
|
110
|
+
return fileDictionary;
|
|
111
|
+
}, {});
|
|
112
|
+
};
|
|
113
|
+
const logUnusedFiles = (unusedFiles) => {
|
|
114
|
+
if (!(unusedFiles === null || unusedFiles === void 0 ? void 0 : unusedFiles.length)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
console.log(utils_1.chalk.yellow.bold('\nWarning:'), utils_1.chalk.yellow(`There are ${unusedFiles.length} unused files:\n`), ...unusedFiles.map((file, index) => `${index + 1}. ${utils_1.chalk.yellow(file)}\n`), utils_1.chalk.red.bold('Please be careful if you want to remove them (¬º-°)¬.\n'));
|
|
118
|
+
};
|
|
119
|
+
const convertToUnixPath = (path) => path.replace(/\\+/g, '/');
|
|
120
|
+
exports.default = detectDeadCode;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
+
import { Env, IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
userConfig: IConfig;
|
|
5
|
+
config: Config;
|
|
6
|
+
env: Env;
|
|
7
|
+
}
|
|
8
|
+
export declare function addDetectDeadCodePlugin(opts: IOpts): Promise<void>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.addDetectDeadCodePlugin = void 0;
|
|
32
|
+
const types_1 = require("../types");
|
|
33
|
+
const detectDeadCode_1 = __importStar(require("./detectDeadCode"));
|
|
34
|
+
const defaultOptions = {
|
|
35
|
+
patterns: [`!(${detectDeadCode_1.disabledFolders.join('|')})/**/*.*`],
|
|
36
|
+
exclude: [],
|
|
37
|
+
failOnHint: false,
|
|
38
|
+
detectUnusedFiles: true,
|
|
39
|
+
detectUnusedExport: true,
|
|
40
|
+
};
|
|
41
|
+
class DetectDeadCodePlugin {
|
|
42
|
+
constructor(options) {
|
|
43
|
+
this.options = defaultOptions;
|
|
44
|
+
this.handleAfterEmit = (compilation, callback) => {
|
|
45
|
+
(0, detectDeadCode_1.default)(compilation, this.options);
|
|
46
|
+
callback();
|
|
47
|
+
};
|
|
48
|
+
if (!options) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.options = Object.assign(Object.assign({}, this.options), options);
|
|
52
|
+
}
|
|
53
|
+
apply(compiler) {
|
|
54
|
+
if (!this.options.context) {
|
|
55
|
+
this.options = Object.assign(Object.assign({}, this.options), { context: compiler.context });
|
|
56
|
+
}
|
|
57
|
+
compiler.hooks.afterEmit.tapAsync('DetectDeadCodePlugin', this.handleAfterEmit);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function addDetectDeadCodePlugin(opts) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
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
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
exports.addDetectDeadCodePlugin = addDetectDeadCodePlugin;
|
|
@@ -13,11 +13,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.addJavaScriptRules = void 0;
|
|
16
|
+
const mfsu_1 = require("@umijs/mfsu");
|
|
16
17
|
const utils_1 = require("@umijs/utils");
|
|
17
18
|
const webpack_1 = require("../../compiled/webpack");
|
|
18
19
|
const constants_1 = require("../constants");
|
|
19
|
-
const autoCssModules_1 = __importDefault(require("../esbuildHandler/autoCssModules"));
|
|
20
|
-
const esbuild_1 = require("../loader/esbuild");
|
|
21
20
|
const autoCSSModules_1 = __importDefault(require("../swcPlugins/autoCSSModules"));
|
|
22
21
|
const types_1 = require("../types");
|
|
23
22
|
const depMatch_1 = require("../utils/depMatch");
|
|
@@ -119,22 +118,20 @@ function addJavaScriptRules(opts) {
|
|
|
119
118
|
});
|
|
120
119
|
}
|
|
121
120
|
else if (srcTranspiler === types_1.Transpiler.swc) {
|
|
122
|
-
// TODO: support javascript
|
|
123
121
|
rule
|
|
124
122
|
.use('swc-loader')
|
|
125
123
|
.loader(require.resolve('../loader/swc'))
|
|
126
124
|
.options({
|
|
127
125
|
plugin: (m) => new autoCSSModules_1.default().visitProgram(m),
|
|
128
|
-
targets: userConfig.targets,
|
|
129
126
|
});
|
|
130
127
|
}
|
|
131
128
|
else if (srcTranspiler === types_1.Transpiler.esbuild) {
|
|
132
129
|
rule
|
|
133
130
|
.use('esbuild-loader')
|
|
134
|
-
.loader(
|
|
131
|
+
.loader(mfsu_1.esbuildLoader)
|
|
135
132
|
.options({
|
|
136
133
|
target: isDev ? 'esnext' : 'es2015',
|
|
137
|
-
handler: [
|
|
134
|
+
handler: [mfsu_1.autoCssModulesHandler, ...opts.extraEsbuildLoaderHandler],
|
|
138
135
|
});
|
|
139
136
|
// esbuild loader can not auto import `React`
|
|
140
137
|
config.plugin('react-provide-plugin').use(webpack_1.ProvidePlugin, [
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MESSAGE_TYPE = exports.MFSU_NAME = exports.DEFAULT_OUTPUT_PATH = exports.DEFAULT_DEVTOOL = void 0;
|
|
3
|
+
exports.DEFAULT_BROWSER_TARGETS = exports.MESSAGE_TYPE = exports.MFSU_NAME = exports.DEFAULT_OUTPUT_PATH = exports.DEFAULT_DEVTOOL = void 0;
|
|
4
4
|
exports.DEFAULT_DEVTOOL = 'cheap-module-source-map';
|
|
5
5
|
exports.DEFAULT_OUTPUT_PATH = 'dist';
|
|
6
6
|
exports.MFSU_NAME = 'MFSU';
|
|
@@ -13,3 +13,6 @@ var MESSAGE_TYPE;
|
|
|
13
13
|
MESSAGE_TYPE["stillOk"] = "still-ok";
|
|
14
14
|
MESSAGE_TYPE["invalid"] = "invalid";
|
|
15
15
|
})(MESSAGE_TYPE = exports.MESSAGE_TYPE || (exports.MESSAGE_TYPE = {}));
|
|
16
|
+
exports.DEFAULT_BROWSER_TARGETS = {
|
|
17
|
+
chrome: 80,
|
|
18
|
+
};
|
package/dist/dev.d.ts
CHANGED
package/dist/dev.js
CHANGED
|
@@ -22,8 +22,8 @@ const constants_1 = require("./constants");
|
|
|
22
22
|
const server_1 = require("./server/server");
|
|
23
23
|
const types_1 = require("./types");
|
|
24
24
|
function dev(opts) {
|
|
25
|
-
var _a, _b, _c, _d;
|
|
26
|
-
var
|
|
25
|
+
var _a, _b, _c, _d, _e;
|
|
26
|
+
var _f;
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
const enableMFSU = opts.config.mfsu !== false;
|
|
29
29
|
let mfsu = null;
|
|
@@ -39,7 +39,8 @@ function dev(opts) {
|
|
|
39
39
|
},
|
|
40
40
|
mfName: (_c = opts.config.mfsu) === null || _c === void 0 ? void 0 : _c.mfName,
|
|
41
41
|
runtimePublicPath: opts.config.runtimePublicPath,
|
|
42
|
-
tmpBase: (0
|
|
42
|
+
tmpBase: ((_d = opts.config.mfsu) === null || _d === void 0 ? void 0 : _d.cacheDirectory) ||
|
|
43
|
+
(0, path_1.join)(opts.cwd, 'node_modules/.cache/mfsu'),
|
|
43
44
|
getCacheDependency() {
|
|
44
45
|
var _a;
|
|
45
46
|
return {
|
|
@@ -54,6 +55,7 @@ function dev(opts) {
|
|
|
54
55
|
env: types_1.Env.development,
|
|
55
56
|
entry: opts.entry,
|
|
56
57
|
userConfig: opts.config,
|
|
58
|
+
babelPreset: opts.babelPreset,
|
|
57
59
|
extraBabelPlugins: [
|
|
58
60
|
...(opts.beforeBabelPlugins || []),
|
|
59
61
|
...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getBabelPlugins()) || []),
|
|
@@ -79,11 +81,11 @@ function dev(opts) {
|
|
|
79
81
|
staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
|
|
80
82
|
name: constants_1.MFSU_NAME,
|
|
81
83
|
cache: {
|
|
82
|
-
buildDependencies: (
|
|
84
|
+
buildDependencies: (_e = opts.cache) === null || _e === void 0 ? void 0 : _e.buildDependencies,
|
|
83
85
|
cacheDirectory: (0, path_1.join)(opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
|
|
84
86
|
},
|
|
85
87
|
});
|
|
86
|
-
(
|
|
88
|
+
(_f = webpackConfig.resolve).alias || (_f.alias = {});
|
|
87
89
|
// TODO: REMOVE ME
|
|
88
90
|
['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
|
|
89
91
|
// @ts-ignore
|
package/dist/loader/swc.js
CHANGED
|
@@ -13,27 +13,23 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
const core_1 = require("@swc/core");
|
|
15
15
|
const types_1 = require("../types");
|
|
16
|
-
function getBaseOpts({ filename
|
|
16
|
+
function getBaseOpts({ filename }) {
|
|
17
17
|
const isTSFile = filename.endsWith('.ts');
|
|
18
18
|
const isTypeScript = isTSFile || filename.endsWith('.tsx');
|
|
19
19
|
const isDev = process.env.NODE_ENV === types_1.Env.development;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
coreJs: 3,
|
|
29
|
-
targets,
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
const swcOpts = Object.assign(Object.assign({ module: {
|
|
20
|
+
/**
|
|
21
|
+
* Not use swc auto polyfill , depend on `preset-umi/features/polyfill/polyfill` imported polyfill file
|
|
22
|
+
*
|
|
23
|
+
* @issue https://github.com/swc-project/swc/issues/2607
|
|
24
|
+
* https://github.com/swc-project/swc/issues/1604
|
|
25
|
+
*/
|
|
26
|
+
const swcOpts = {
|
|
27
|
+
module: {
|
|
33
28
|
// @ts-ignore
|
|
34
29
|
type: 'es6',
|
|
35
30
|
ignoreDynamic: true,
|
|
36
|
-
}
|
|
31
|
+
},
|
|
32
|
+
jsc: {
|
|
37
33
|
parser: {
|
|
38
34
|
syntax: isTypeScript ? 'typescript' : 'ecmascript',
|
|
39
35
|
[isTypeScript ? 'tsx' : 'jsx']: !isTSFile,
|
|
@@ -50,18 +46,18 @@ function getBaseOpts({ filename, targets = { chrome: '61' }, }) {
|
|
|
50
46
|
useBuiltins: true,
|
|
51
47
|
},
|
|
52
48
|
},
|
|
53
|
-
}
|
|
49
|
+
},
|
|
50
|
+
};
|
|
54
51
|
return swcOpts;
|
|
55
52
|
}
|
|
56
53
|
function swcLoader(contents) {
|
|
57
54
|
// 启用异步模式
|
|
58
55
|
const callback = this.async();
|
|
59
56
|
const loaderOpts = this.getOptions();
|
|
60
|
-
const { sync = false, parseMap = false
|
|
57
|
+
const { sync = false, parseMap = false } = loaderOpts, otherOpts = __rest(loaderOpts, ["sync", "parseMap"]);
|
|
61
58
|
const filename = this.resourcePath;
|
|
62
59
|
const swcOpts = Object.assign(Object.assign(Object.assign({}, getBaseOpts({
|
|
63
60
|
filename,
|
|
64
|
-
targets,
|
|
65
61
|
})), { filename, sourceMaps: this.sourceMap, sourceFileName: filename }), otherOpts);
|
|
66
62
|
try {
|
|
67
63
|
if (sync) {
|
package/dist/requireHook.js
CHANGED
|
@@ -17,7 +17,7 @@ const hookPropertyMap = new Map([
|
|
|
17
17
|
['webpack/lib/webpack.js', '@umijs/bundler-webpack/compiled/webpack'],
|
|
18
18
|
]);
|
|
19
19
|
deepImports_json_1.default.forEach((item) => {
|
|
20
|
-
const name = item.split('/').
|
|
20
|
+
const name = item.split('/').pop();
|
|
21
21
|
hookPropertyMap.set(item, `@umijs/bundler-webpack/compiled/webpack/${name}`);
|
|
22
22
|
hookPropertyMap.set(`${item}.js`, `@umijs/bundler-webpack/compiled/webpack/${name}`);
|
|
23
23
|
});
|
package/dist/schema.js
CHANGED
|
@@ -35,6 +35,7 @@ function getSchemas() {
|
|
|
35
35
|
cssMinifier: (Joi) => Joi.string().valid(types_1.CSSMinifier.cssnano, types_1.CSSMinifier.esbuild, types_1.CSSMinifier.none),
|
|
36
36
|
cssMinifierOptions: (Joi) => Joi.object(),
|
|
37
37
|
define: (Joi) => Joi.object(),
|
|
38
|
+
deadCode: (Joi) => Joi.object(),
|
|
38
39
|
depTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
|
|
39
40
|
devtool: (Joi) => Joi.alternatives().try(Joi.string().regex(DEVTOOL_REGEX), Joi.boolean()),
|
|
40
41
|
externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
|
|
@@ -55,6 +56,7 @@ function getSchemas() {
|
|
|
55
56
|
loaderOptions: Joi.object(),
|
|
56
57
|
}),
|
|
57
58
|
mfsu: (Joi) => Joi.alternatives(Joi.object({
|
|
59
|
+
cacheDirectory: Joi.string(),
|
|
58
60
|
esbuild: Joi.boolean(),
|
|
59
61
|
mfName: Joi.string(),
|
|
60
62
|
}), Joi.boolean()),
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { ImportDeclaration,
|
|
1
|
+
import type { ImportDeclaration, ModuleItem, TsType } from '@swc/core';
|
|
2
2
|
import Visitor from '@swc/core/Visitor';
|
|
3
3
|
declare class AutoCSSModule extends Visitor {
|
|
4
4
|
visitTsType(expression: TsType): TsType;
|
|
5
|
+
/**
|
|
6
|
+
* call path:
|
|
7
|
+
* visitProgram -> visitModule -> visitModuleItems -> visitModuleItem -> visitImportDeclaration
|
|
8
|
+
* @see https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts#L189
|
|
9
|
+
*/
|
|
10
|
+
visitModuleItem(n: ModuleItem): ImportDeclaration | import("@swc/core").ExportDeclaration | import("@swc/core").ExportNamedDeclaration | import("@swc/core").ExportDefaultDeclaration | import("@swc/core").ExportDefaultExpression | import("@swc/core").ExportAllDeclaration | import("@swc/core").TsImportEqualsDeclaration | import("@swc/core").TsExportAssignment | import("@swc/core").TsNamespaceExportDeclaration | import("@swc/core").ExpressionStatement | import("@swc/core").BlockStatement | import("@swc/core").EmptyStatement | import("@swc/core").DebuggerStatement | import("@swc/core").WithStatement | import("@swc/core").ReturnStatement | import("@swc/core").LabeledStatement | import("@swc/core").BreakStatement | import("@swc/core").ContinueStatement | import("@swc/core").IfStatement | import("@swc/core").SwitchStatement | import("@swc/core").ThrowStatement | import("@swc/core").TryStatement | import("@swc/core").WhileStatement | import("@swc/core").DoWhileStatement | import("@swc/core").ForStatement | import("@swc/core").ForInStatement | import("@swc/core").ForOfStatement | import("@swc/core").ClassDeclaration | import("@swc/core").FunctionDeclaration | import("@swc/core").VariableDeclaration | import("@swc/core").TsInterfaceDeclaration | import("@swc/core").TsTypeAliasDeclaration | import("@swc/core").TsEnumDeclaration | import("@swc/core").TsModuleDeclaration;
|
|
5
11
|
visitImportDeclaration(expression: ImportDeclaration): ImportDeclaration;
|
|
6
|
-
visitVariableDeclaration(expression: VariableDeclaration): VariableDeclaration;
|
|
7
12
|
}
|
|
8
13
|
export default AutoCSSModule;
|
|
@@ -9,6 +9,17 @@ class AutoCSSModule extends Visitor_1.default {
|
|
|
9
9
|
visitTsType(expression) {
|
|
10
10
|
return expression;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* call path:
|
|
14
|
+
* visitProgram -> visitModule -> visitModuleItems -> visitModuleItem -> visitImportDeclaration
|
|
15
|
+
* @see https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts#L189
|
|
16
|
+
*/
|
|
17
|
+
visitModuleItem(n) {
|
|
18
|
+
if (n.type === 'ImportDeclaration') {
|
|
19
|
+
return this.visitImportDeclaration(n);
|
|
20
|
+
}
|
|
21
|
+
return n;
|
|
22
|
+
}
|
|
12
23
|
visitImportDeclaration(expression) {
|
|
13
24
|
const { specifiers, source } = expression;
|
|
14
25
|
const { value } = source;
|
|
@@ -17,21 +28,5 @@ class AutoCSSModule extends Visitor_1.default {
|
|
|
17
28
|
}
|
|
18
29
|
return expression;
|
|
19
30
|
}
|
|
20
|
-
visitVariableDeclaration(expression) {
|
|
21
|
-
const { declarations } = expression;
|
|
22
|
-
if (declarations.length &&
|
|
23
|
-
declarations[0].init &&
|
|
24
|
-
declarations[0].init.type === 'AwaitExpression' &&
|
|
25
|
-
declarations[0].init.argument.type === 'CallExpression' &&
|
|
26
|
-
declarations[0].init.argument.arguments.length &&
|
|
27
|
-
declarations[0].init.argument.arguments[0].expression.type ===
|
|
28
|
-
'StringLiteral' &&
|
|
29
|
-
(0, utils_1.isStyleFile)({
|
|
30
|
-
filename: declarations[0].init.argument.arguments[0].expression.value,
|
|
31
|
-
})) {
|
|
32
|
-
declarations[0].init.argument.arguments[0].expression.value = `${declarations[0].init.argument.arguments[0].expression.value}?modules`;
|
|
33
|
-
}
|
|
34
|
-
return expression;
|
|
35
|
-
}
|
|
36
31
|
}
|
|
37
32
|
exports.default = AutoCSSModule;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { Config as SwcConfig } from '@swc/core';
|
|
2
|
-
import type { ImportSpecifier } from '@umijs/bundler-utils/compiled/es-module-lexer';
|
|
3
|
-
import type { TransformOptions } from '@umijs/bundler-utils/compiled/esbuild';
|
|
4
2
|
import type { Options as ProxyOptions } from '../compiled/http-proxy-middleware';
|
|
5
3
|
import { Configuration } from '../compiled/webpack';
|
|
6
4
|
import Config from '../compiled/webpack-5-chain';
|
|
@@ -34,6 +32,14 @@ declare type WebpackConfig = Required<Configuration>;
|
|
|
34
32
|
declare type IBabelPlugin = Function | string | [string, {
|
|
35
33
|
[key: string]: any;
|
|
36
34
|
}];
|
|
35
|
+
export interface DeadCodeParams {
|
|
36
|
+
patterns?: string[];
|
|
37
|
+
exclude?: string[];
|
|
38
|
+
failOnHint?: boolean;
|
|
39
|
+
detectUnusedFiles?: boolean;
|
|
40
|
+
detectUnusedExport?: boolean;
|
|
41
|
+
context?: string;
|
|
42
|
+
}
|
|
37
43
|
export interface IConfig {
|
|
38
44
|
alias?: Record<string, string>;
|
|
39
45
|
autoCSSModules?: boolean;
|
|
@@ -55,6 +61,7 @@ export interface IConfig {
|
|
|
55
61
|
};
|
|
56
62
|
depTranspiler?: Transpiler;
|
|
57
63
|
devtool?: Config.DevTool;
|
|
64
|
+
deadCode?: DeadCodeParams;
|
|
58
65
|
externals?: WebpackConfig['externals'];
|
|
59
66
|
esm?: {
|
|
60
67
|
[key: string]: any;
|
|
@@ -104,15 +111,5 @@ export interface IConfig {
|
|
|
104
111
|
export interface SwcOptions extends SwcConfig {
|
|
105
112
|
sync?: boolean;
|
|
106
113
|
parseMap?: boolean;
|
|
107
|
-
targets?: Record<string, any>;
|
|
108
|
-
}
|
|
109
|
-
export interface IEsbuildLoaderHandlerParams {
|
|
110
|
-
code: string;
|
|
111
|
-
filePath: string;
|
|
112
|
-
imports: readonly ImportSpecifier[];
|
|
113
|
-
exports: readonly string[];
|
|
114
|
-
}
|
|
115
|
-
export interface IEsbuildLoaderOpts extends Partial<TransformOptions> {
|
|
116
|
-
handler?: Array<(opts: IEsbuildLoaderHandlerParams) => string>;
|
|
117
114
|
}
|
|
118
115
|
export {};
|
package/dist/utils/depMatch.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/bundler-webpack",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.2",
|
|
4
4
|
"description": "@umijs/bundler-webpack",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/bundler-webpack#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -28,60 +28,60 @@
|
|
|
28
28
|
"generate:webpackPackages": "zx ./scripts/generateWebpackPackages.mjs"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@pmmmwh/react-refresh-webpack-plugin": "0.5.
|
|
32
|
-
"@svgr/core": "6.
|
|
33
|
-
"@svgr/plugin-jsx": "^6.1
|
|
34
|
-
"@svgr/plugin-svgo": "^6.
|
|
35
|
-
"@swc/core": "1.2.
|
|
36
|
-
"@types/hapi__joi": "17.1.
|
|
37
|
-
"@umijs/babel-preset-umi": "4.0.0-rc.
|
|
38
|
-
"@umijs/mfsu": "4.0.0-rc.
|
|
39
|
-
"@umijs/utils": "4.0.0-rc.
|
|
40
|
-
"css-loader": "6.
|
|
31
|
+
"@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
|
|
32
|
+
"@svgr/core": "6.2.1",
|
|
33
|
+
"@svgr/plugin-jsx": "^6.2.1",
|
|
34
|
+
"@svgr/plugin-svgo": "^6.2.0",
|
|
35
|
+
"@swc/core": "1.2.141",
|
|
36
|
+
"@types/hapi__joi": "17.1.8",
|
|
37
|
+
"@umijs/babel-preset-umi": "4.0.0-rc.2",
|
|
38
|
+
"@umijs/mfsu": "4.0.0-rc.2",
|
|
39
|
+
"@umijs/utils": "4.0.0-rc.2",
|
|
40
|
+
"css-loader": "6.6.0",
|
|
41
41
|
"es5-imcompatible-versions": "^0.1.73",
|
|
42
|
-
"jest-worker": "27.
|
|
42
|
+
"jest-worker": "27.5.1",
|
|
43
43
|
"node-libs-browser": "2.2.1",
|
|
44
|
-
"postcss": "^8.4.
|
|
45
|
-
"postcss-preset-env": "7.
|
|
44
|
+
"postcss": "^8.4.6",
|
|
45
|
+
"postcss-preset-env": "7.4.1",
|
|
46
46
|
"react-error-overlay": "6.0.9"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/express": "4.17.13",
|
|
50
50
|
"@types/webpack-sources": "3.2.0",
|
|
51
|
-
"@types/ws": "8.2.
|
|
52
|
-
"autoprefixer": "10.4.
|
|
51
|
+
"@types/ws": "8.2.2",
|
|
52
|
+
"autoprefixer": "10.4.2",
|
|
53
53
|
"babel-loader": "8.2.3",
|
|
54
54
|
"compression": "1.7.4",
|
|
55
55
|
"connect-history-api-fallback": "1.6.0",
|
|
56
|
-
"copy-webpack-plugin": "
|
|
57
|
-
"css-minimizer-webpack-plugin": "3.
|
|
58
|
-
"cssnano": "5.0.
|
|
59
|
-
"express": "4.17.
|
|
60
|
-
"fork-ts-checker-webpack-plugin": "
|
|
61
|
-
"http-proxy-middleware": "2.0.
|
|
56
|
+
"copy-webpack-plugin": "10.2.4",
|
|
57
|
+
"css-minimizer-webpack-plugin": "3.4.1",
|
|
58
|
+
"cssnano": "5.0.17",
|
|
59
|
+
"express": "4.17.3",
|
|
60
|
+
"fork-ts-checker-webpack-plugin": "7.2.1",
|
|
61
|
+
"http-proxy-middleware": "2.0.3",
|
|
62
62
|
"less": "4.1.2",
|
|
63
63
|
"less-loader": "10.2.0",
|
|
64
|
-
"mini-css-extract-plugin": "2.
|
|
64
|
+
"mini-css-extract-plugin": "2.5.3",
|
|
65
65
|
"postcss-flexbugs-fixes": "5.0.2",
|
|
66
66
|
"postcss-loader": "6.2.1",
|
|
67
|
-
"purgecss-webpack-plugin": "4.
|
|
67
|
+
"purgecss-webpack-plugin": "4.1.3",
|
|
68
68
|
"react-refresh": "0.11.0",
|
|
69
|
-
"sass-loader": "12.
|
|
69
|
+
"sass-loader": "12.6.0",
|
|
70
70
|
"schema-utils": "4.0.0",
|
|
71
71
|
"speed-measure-webpack-plugin": "1.5.0",
|
|
72
72
|
"style-loader": "3.3.1",
|
|
73
73
|
"svgo-loader": "3.0.0",
|
|
74
74
|
"tapable": "2.2.1",
|
|
75
75
|
"terser": "5.10.0",
|
|
76
|
-
"terser-webpack-plugin": "5.
|
|
76
|
+
"terser-webpack-plugin": "5.3.1",
|
|
77
77
|
"url-loader": "4.1.1",
|
|
78
|
-
"webpack": "5.
|
|
78
|
+
"webpack": "5.69.1",
|
|
79
79
|
"webpack-5-chain": "8.0.0",
|
|
80
80
|
"webpack-bundle-analyzer": "4.5.0",
|
|
81
|
-
"webpack-dev-middleware": "5.
|
|
82
|
-
"webpack-manifest-plugin": "4.
|
|
83
|
-
"webpack-sources": "3.2.
|
|
84
|
-
"ws": "8.
|
|
81
|
+
"webpack-dev-middleware": "5.3.1",
|
|
82
|
+
"webpack-manifest-plugin": "4.1.1",
|
|
83
|
+
"webpack-sources": "3.2.3",
|
|
84
|
+
"ws": "8.5.0"
|
|
85
85
|
},
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"access": "public"
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("@umijs/utils");
|
|
4
|
-
const CSS_MODULES_QUERY = '?modules';
|
|
5
|
-
const QUERY_LENGTH = CSS_MODULES_QUERY.length;
|
|
6
|
-
function autoCssModulesHandler(opts) {
|
|
7
|
-
let { code } = opts;
|
|
8
|
-
let offset = 0;
|
|
9
|
-
opts.imports.forEach((i) => {
|
|
10
|
-
if (i.d < 0 && (0, utils_1.isStyleFile)({ filename: i.n })) {
|
|
11
|
-
// import x from './index.less'
|
|
12
|
-
// => import x from '
|
|
13
|
-
const importSegment = code.substring(i.ss + offset, i.s + offset);
|
|
14
|
-
// is css module
|
|
15
|
-
if (~importSegment.indexOf(' from')) {
|
|
16
|
-
code = `${code.substring(0, i.e + offset)}${CSS_MODULES_QUERY}${code.substring(i.e + offset)}`;
|
|
17
|
-
offset += QUERY_LENGTH;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
return code;
|
|
22
|
-
}
|
|
23
|
-
exports.default = autoCssModulesHandler;
|
package/dist/loader/esbuild.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { LoaderContext } from '../../compiled/webpack';
|
|
2
|
-
import type { IEsbuildLoaderOpts } from '../types';
|
|
3
|
-
declare function esbuildLoader(this: LoaderContext<IEsbuildLoaderOpts>, source: string): Promise<void>;
|
|
4
|
-
export default esbuildLoader;
|
|
5
|
-
export declare const esbuildLoaderPath: string;
|