@umijs/bundler-webpack 4.0.0-rc.1 → 4.0.0-rc.4
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/cssnano/package.json +1 -1
- 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/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/client/client.js +5 -1
- package/dist/config/compressPlugin.js +6 -0
- 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 +75 -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/index.js +5 -1
- package/dist/loader/swc.js +14 -18
- package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.js +74 -0
- package/dist/plugins/ProgressPlugin.js +2 -2
- package/dist/requireHook.js +1 -1
- package/dist/schema.js +3 -1
- package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
- package/dist/swcPlugins/autoCSSModules.js +11 -16
- package/dist/swcPlugins/lockCoreJS.d.ts +1 -1
- package/dist/types.d.ts +10 -12
- package/dist/types.js +1 -0
- package/dist/utils/depMatch.js +1 -1
- package/package.json +33 -32
- 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:`), ...unusedFiles.map((file, index) => `\n${index + 1}. ${utils_1.chalk.yellow(file)}`), utils_1.chalk.red.bold('\nPlease 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,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.addDetectDeadCodePlugin = void 0;
|
|
36
|
+
const types_1 = require("../types");
|
|
37
|
+
const detectDeadCode_1 = __importStar(require("./detectDeadCode"));
|
|
38
|
+
const defaultOptions = {
|
|
39
|
+
patterns: [`!(${detectDeadCode_1.disabledFolders.join('|')})/**/*.*`],
|
|
40
|
+
exclude: [],
|
|
41
|
+
failOnHint: false,
|
|
42
|
+
detectUnusedFiles: true,
|
|
43
|
+
detectUnusedExport: true,
|
|
44
|
+
};
|
|
45
|
+
class DetectDeadCodePlugin {
|
|
46
|
+
constructor(options) {
|
|
47
|
+
this.options = defaultOptions;
|
|
48
|
+
this.handleAfterEmit = (compilation, callback) => {
|
|
49
|
+
(0, detectDeadCode_1.default)(compilation, this.options);
|
|
50
|
+
callback();
|
|
51
|
+
};
|
|
52
|
+
if (!options) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this.options = Object.assign(Object.assign({}, this.options), options);
|
|
56
|
+
}
|
|
57
|
+
apply(compiler) {
|
|
58
|
+
if (!this.options.context) {
|
|
59
|
+
this.options = Object.assign(Object.assign({}, this.options), { context: compiler.context });
|
|
60
|
+
}
|
|
61
|
+
compiler.hooks.afterEmit.tapAsync('DetectDeadCodePlugin', this.handleAfterEmit);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function addDetectDeadCodePlugin(opts) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const { config, userConfig } = opts;
|
|
67
|
+
const isDev = opts.env === types_1.Env.development;
|
|
68
|
+
if (userConfig.deadCode && !isDev) {
|
|
69
|
+
config
|
|
70
|
+
.plugin('detect-dead-code-plugin')
|
|
71
|
+
.use(DetectDeadCodePlugin, [userConfig.deadCode]);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
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/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
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) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type TransformOptions } from '@parcel/css';
|
|
2
|
+
import type { Compiler } from '../../compiled/webpack/types';
|
|
3
|
+
declare type MinifyPluginOpts = Omit<TransformOptions, 'filename' | 'code' | 'minify'>;
|
|
4
|
+
export declare class ParcelCSSMinifyPlugin {
|
|
5
|
+
private readonly options;
|
|
6
|
+
constructor(opts?: MinifyPluginOpts);
|
|
7
|
+
apply(compiler: Compiler): void;
|
|
8
|
+
private transformAssets;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ParcelCSSMinifyPlugin = void 0;
|
|
13
|
+
const css_1 = require("@parcel/css");
|
|
14
|
+
const buffer_1 = require("buffer");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const webpack_sources_1 = require("../../compiled/webpack-sources");
|
|
17
|
+
const pkgPath = (0, path_1.join)(__dirname, '../../package.json');
|
|
18
|
+
const pkg = require(pkgPath);
|
|
19
|
+
const PLUGIN_NAME = 'parcel-css-minify-plugin';
|
|
20
|
+
const CSS_FILE_REG = /\.css(?:\?.*)?$/i;
|
|
21
|
+
class ParcelCSSMinifyPlugin {
|
|
22
|
+
constructor(opts = {}) {
|
|
23
|
+
this.options = opts;
|
|
24
|
+
}
|
|
25
|
+
apply(compiler) {
|
|
26
|
+
const meta = JSON.stringify({
|
|
27
|
+
name: pkg.name,
|
|
28
|
+
version: pkg.version,
|
|
29
|
+
options: this.options,
|
|
30
|
+
});
|
|
31
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
32
|
+
compilation.hooks.chunkHash.tap(PLUGIN_NAME, (_, hash) => hash.update(meta));
|
|
33
|
+
compilation.hooks.processAssets.tapPromise({
|
|
34
|
+
name: PLUGIN_NAME,
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
|
|
37
|
+
additionalAssets: true,
|
|
38
|
+
}, () => __awaiter(this, void 0, void 0, function* () { return yield this.transformAssets(compilation); }));
|
|
39
|
+
compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (statsPrinter) => {
|
|
40
|
+
statsPrinter.hooks.print
|
|
41
|
+
.for('asset.info.minimized')
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
.tap(PLUGIN_NAME, (minimized, { green, formatFlag }) => {
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
return minimized ? green(formatFlag('minimized')) : undefined;
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
transformAssets(compilation) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const { options: { devtool }, } = compilation.compiler;
|
|
53
|
+
const sourcemap = this.options.sourceMap === undefined
|
|
54
|
+
? (devtool && devtool.includes('source-map'))
|
|
55
|
+
: this.options.sourceMap;
|
|
56
|
+
const assets = compilation.getAssets().filter((asset) => {
|
|
57
|
+
return !asset.info.minimized && CSS_FILE_REG.test(asset.name);
|
|
58
|
+
});
|
|
59
|
+
yield Promise.all(assets.map((asset) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const { source, map } = asset.source.sourceAndMap();
|
|
61
|
+
const sourceAsString = source.toString();
|
|
62
|
+
const code = typeof source === 'string' ? buffer_1.Buffer.from(source) : source;
|
|
63
|
+
const result = yield (0, css_1.transform)(Object.assign({ filename: asset.name, code, minify: true, sourceMap: sourcemap }, this.options));
|
|
64
|
+
const codeString = result.code.toString();
|
|
65
|
+
compilation.updateAsset(asset.name,
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
sourcemap
|
|
68
|
+
? new webpack_sources_1.SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, true)
|
|
69
|
+
: new webpack_sources_1.RawSource(codeString), Object.assign(Object.assign({}, asset.info), { minimized: true }));
|
|
70
|
+
})));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.ParcelCSSMinifyPlugin = ParcelCSSMinifyPlugin;
|
|
@@ -13,7 +13,7 @@ class UmiProgressPlugin extends webpack_1.ProgressPlugin {
|
|
|
13
13
|
}
|
|
14
14
|
apply(compiler) {
|
|
15
15
|
compiler.hooks.invalid.tap(PLUGIN_NAME, () => {
|
|
16
|
-
utils_1.logger.wait('
|
|
16
|
+
utils_1.logger.wait('Compiling...');
|
|
17
17
|
});
|
|
18
18
|
compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
|
|
19
19
|
const { errors, warnings } = stats.toJson({
|
|
@@ -33,7 +33,7 @@ class UmiProgressPlugin extends webpack_1.ProgressPlugin {
|
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
const prefix = this.options.name ? `${this.options.name} ` : '';
|
|
36
|
-
utils_1.logger.event(`${prefix}
|
|
36
|
+
utils_1.logger.event(`${prefix}Compiled successfully in ${stats.endTime - stats.startTime} ms (${stats.compilation.modules.size} modules)`);
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
}
|
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
|
@@ -32,9 +32,10 @@ function getSchemas() {
|
|
|
32
32
|
}), Joi.string())),
|
|
33
33
|
cssLoader: (Joi) => Joi.object(),
|
|
34
34
|
cssLoaderModules: (Joi) => Joi.object(),
|
|
35
|
-
cssMinifier: (Joi) => Joi.string().valid(types_1.CSSMinifier.cssnano, types_1.CSSMinifier.esbuild, types_1.CSSMinifier.none),
|
|
35
|
+
cssMinifier: (Joi) => Joi.string().valid(types_1.CSSMinifier.cssnano, types_1.CSSMinifier.esbuild, types_1.CSSMinifier.parcelCSS, 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';
|
|
@@ -24,6 +22,7 @@ export declare enum JSMinifier {
|
|
|
24
22
|
export declare enum CSSMinifier {
|
|
25
23
|
esbuild = "esbuild",
|
|
26
24
|
cssnano = "cssnano",
|
|
25
|
+
parcelCSS = "parcelCSS",
|
|
27
26
|
none = "none"
|
|
28
27
|
}
|
|
29
28
|
export interface ICopy {
|
|
@@ -34,6 +33,14 @@ declare type WebpackConfig = Required<Configuration>;
|
|
|
34
33
|
declare type IBabelPlugin = Function | string | [string, {
|
|
35
34
|
[key: string]: any;
|
|
36
35
|
}];
|
|
36
|
+
export interface DeadCodeParams {
|
|
37
|
+
patterns?: string[];
|
|
38
|
+
exclude?: string[];
|
|
39
|
+
failOnHint?: boolean;
|
|
40
|
+
detectUnusedFiles?: boolean;
|
|
41
|
+
detectUnusedExport?: boolean;
|
|
42
|
+
context?: string;
|
|
43
|
+
}
|
|
37
44
|
export interface IConfig {
|
|
38
45
|
alias?: Record<string, string>;
|
|
39
46
|
autoCSSModules?: boolean;
|
|
@@ -55,6 +62,7 @@ export interface IConfig {
|
|
|
55
62
|
};
|
|
56
63
|
depTranspiler?: Transpiler;
|
|
57
64
|
devtool?: Config.DevTool;
|
|
65
|
+
deadCode?: DeadCodeParams;
|
|
58
66
|
externals?: WebpackConfig['externals'];
|
|
59
67
|
esm?: {
|
|
60
68
|
[key: string]: any;
|
|
@@ -104,15 +112,5 @@ export interface IConfig {
|
|
|
104
112
|
export interface SwcOptions extends SwcConfig {
|
|
105
113
|
sync?: boolean;
|
|
106
114
|
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
115
|
}
|
|
118
116
|
export {};
|
package/dist/types.js
CHANGED
|
@@ -25,5 +25,6 @@ var CSSMinifier;
|
|
|
25
25
|
(function (CSSMinifier) {
|
|
26
26
|
CSSMinifier["esbuild"] = "esbuild";
|
|
27
27
|
CSSMinifier["cssnano"] = "cssnano";
|
|
28
|
+
CSSMinifier["parcelCSS"] = "parcelCSS";
|
|
28
29
|
CSSMinifier["none"] = "none";
|
|
29
30
|
})(CSSMinifier = exports.CSSMinifier || (exports.CSSMinifier = {}));
|