@umijs/bundler-webpack 4.0.0-rc.1 → 4.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/client/client.js +49 -35
- package/client/constants.js +3 -0
- package/compiled/autoprefixer/browserslist/index.d.ts +6 -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 +2 -2
- package/compiled/autoprefixer/postcss/lib/node.d.ts +2 -2
- package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
- package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
- package/compiled/babel-loader/index.js +2 -2
- package/compiled/copy-webpack-plugin/939.index.js +1171 -0
- package/compiled/copy-webpack-plugin/index.js +16 -10
- package/compiled/copy-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/index.js +8 -2
- package/compiled/css-minimizer-webpack-plugin/minify.js +25 -11
- package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/utils.js +225 -28
- package/compiled/cssnano/index.js +12 -11
- package/compiled/cssnano/package.json +1 -1
- package/compiled/express.d.ts +2 -0
- package/compiled/fork-ts-checker-webpack-plugin/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 +4523 -4036
- package/compiled/mini-css-extract-plugin/loader.js +179 -54
- package/compiled/mini-css-extract-plugin/package.json +1 -1
- package/compiled/mini-css-extract-plugin/utils.js +79 -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 +9855 -4185
- 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 +7 -2
- package/dist/config/compressPlugin.js +6 -0
- package/dist/config/config.js +4 -3
- package/dist/config/cssRules.js +1 -1
- 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 +7 -12
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +4 -1
- package/dist/dev.d.ts +1 -0
- package/dist/dev.js +13 -5
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -1
- package/dist/loader/swc.js +14 -18
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +1 -3
- package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.js +75 -0
- package/dist/plugins/ProgressPlugin.js +2 -2
- package/dist/plugins/RuntimePublicPathPlugin.js +1 -1
- package/dist/requireHook.js +1 -1
- package/dist/schema.js +10 -6
- package/dist/server/server.d.ts +1 -2
- package/dist/server/server.js +27 -11
- package/dist/server/ws.d.ts +3 -2
- package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
- package/dist/swcPlugins/autoCSSModules.js +14 -17
- package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
- package/dist/swcPlugins/changeImportFromString.js +10 -0
- package/dist/swcPlugins/lockCoreJS.d.ts +1 -1
- package/dist/swcPlugins/lockCoreJS.js +3 -2
- package/dist/types.d.ts +16 -12
- package/dist/types.js +1 -0
- package/dist/utils/depMatch.js +1 -1
- package/dist/utils/server.d.ts +5 -0
- package/dist/utils/server.js +93 -0
- package/package.json +38 -41
- package/compiled/css-loader/LICENSE +0 -20
- package/compiled/css-loader/api.js +0 -102
- package/compiled/css-loader/getUrl.js +0 -29
- package/compiled/css-loader/index.js +0 -2
- package/compiled/css-loader/noSourceMaps.js +0 -5
- package/compiled/css-loader/package.json +0 -1
- package/compiled/css-loader/sourceMaps.js +0 -22
- package/compiled/express/LICENSE +0 -24
- package/compiled/express/body-parser/index.d.ts +0 -104
- package/compiled/express/connect/index.d.ts +0 -93
- package/compiled/express/express-serve-static-core/index.d.ts +0 -1252
- package/compiled/express/index.d.ts +0 -133
- package/compiled/express/index.js +0 -338
- package/compiled/express/mime/index.d.ts +0 -35
- package/compiled/express/package.json +0 -1
- package/compiled/express/qs/index.d.ts +0 -62
- package/compiled/express/range-parser/index.d.ts +0 -35
- package/compiled/express/serve-static/index.d.ts +0 -108
- package/compiled/less/index.js +0 -31
- package/compiled/less/package.json +0 -1
- package/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;
|
|
@@ -8,17 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.addJavaScriptRules = void 0;
|
|
13
|
+
const mfsu_1 = require("@umijs/mfsu");
|
|
16
14
|
const utils_1 = require("@umijs/utils");
|
|
17
15
|
const webpack_1 = require("../../compiled/webpack");
|
|
18
16
|
const constants_1 = require("../constants");
|
|
19
|
-
const autoCssModules_1 = __importDefault(require("../esbuildHandler/autoCssModules"));
|
|
20
|
-
const esbuild_1 = require("../loader/esbuild");
|
|
21
|
-
const autoCSSModules_1 = __importDefault(require("../swcPlugins/autoCSSModules"));
|
|
22
17
|
const types_1 = require("../types");
|
|
23
18
|
const depMatch_1 = require("../utils/depMatch");
|
|
24
19
|
function addJavaScriptRules(opts) {
|
|
@@ -47,7 +42,8 @@ function addJavaScriptRules(opts) {
|
|
|
47
42
|
.test(/\.(js|mjs)$/)
|
|
48
43
|
.include.add((path) => {
|
|
49
44
|
try {
|
|
50
|
-
|
|
45
|
+
// do src transform for bundler-webpack/client/client/client.js
|
|
46
|
+
if (path.includes('client/client/client'))
|
|
51
47
|
return true;
|
|
52
48
|
return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
|
|
53
49
|
}
|
|
@@ -119,22 +115,21 @@ function addJavaScriptRules(opts) {
|
|
|
119
115
|
});
|
|
120
116
|
}
|
|
121
117
|
else if (srcTranspiler === types_1.Transpiler.swc) {
|
|
122
|
-
|
|
118
|
+
const AutoCSSModule = require('../swcPlugins/autoCSSModules').default;
|
|
123
119
|
rule
|
|
124
120
|
.use('swc-loader')
|
|
125
121
|
.loader(require.resolve('../loader/swc'))
|
|
126
122
|
.options({
|
|
127
|
-
plugin: (m) => new
|
|
128
|
-
targets: userConfig.targets,
|
|
123
|
+
plugin: (m) => new AutoCSSModule().visitProgram(m),
|
|
129
124
|
});
|
|
130
125
|
}
|
|
131
126
|
else if (srcTranspiler === types_1.Transpiler.esbuild) {
|
|
132
127
|
rule
|
|
133
128
|
.use('esbuild-loader')
|
|
134
|
-
.loader(
|
|
129
|
+
.loader(mfsu_1.esbuildLoader)
|
|
135
130
|
.options({
|
|
136
131
|
target: isDev ? 'esnext' : 'es2015',
|
|
137
|
-
handler: [
|
|
132
|
+
handler: [mfsu_1.autoCssModulesHandler, ...opts.extraEsbuildLoaderHandler],
|
|
138
133
|
});
|
|
139
134
|
// esbuild loader can not auto import `React`
|
|
140
135
|
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, _f;
|
|
26
|
+
var _g;
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
const enableMFSU = opts.config.mfsu !== false;
|
|
29
29
|
let mfsu = null;
|
|
@@ -39,12 +39,18 @@ 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 {
|
|
46
47
|
version: require('../package.json').version,
|
|
47
48
|
esbuildMode: !!((_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild),
|
|
49
|
+
alias: opts.config.alias,
|
|
50
|
+
externals: opts.config.externals,
|
|
51
|
+
theme: opts.config.theme,
|
|
52
|
+
runtimePublicPath: opts.config.runtimePublicPath,
|
|
53
|
+
publicPath: opts.config.publicPath,
|
|
48
54
|
};
|
|
49
55
|
},
|
|
50
56
|
});
|
|
@@ -54,6 +60,7 @@ function dev(opts) {
|
|
|
54
60
|
env: types_1.Env.development,
|
|
55
61
|
entry: opts.entry,
|
|
56
62
|
userConfig: opts.config,
|
|
63
|
+
babelPreset: opts.babelPreset,
|
|
57
64
|
extraBabelPlugins: [
|
|
58
65
|
...(opts.beforeBabelPlugins || []),
|
|
59
66
|
...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getBabelPlugins()) || []),
|
|
@@ -78,12 +85,13 @@ function dev(opts) {
|
|
|
78
85
|
hash: true,
|
|
79
86
|
staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
|
|
80
87
|
name: constants_1.MFSU_NAME,
|
|
88
|
+
chainWebpack: (_e = opts.config.mfsu) === null || _e === void 0 ? void 0 : _e.chainWebpack,
|
|
81
89
|
cache: {
|
|
82
|
-
buildDependencies: (
|
|
90
|
+
buildDependencies: (_f = opts.cache) === null || _f === void 0 ? void 0 : _f.buildDependencies,
|
|
83
91
|
cacheDirectory: (0, path_1.join)(opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
|
|
84
92
|
},
|
|
85
93
|
});
|
|
86
|
-
(
|
|
94
|
+
(_g = webpackConfig.resolve).alias || (_g.alias = {});
|
|
87
95
|
// TODO: REMOVE ME
|
|
88
96
|
['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
|
|
89
97
|
// @ts-ignore
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import type webpack from '../compiled/webpack';
|
|
2
|
+
export type { RequestHandler } from '@umijs/bundler-utils/compiled/express';
|
|
3
|
+
export type { Compiler, Stats } from '../compiled/webpack';
|
|
2
4
|
export * from './build';
|
|
3
5
|
export * from './config/config';
|
|
4
6
|
export * from './dev';
|
|
5
7
|
export * from './schema';
|
|
8
|
+
export { webpack };
|
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) {
|
|
@@ -38,9 +38,7 @@ class ESBuildCSSMinifyPlugin {
|
|
|
38
38
|
transformAssets(compilation) {
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
40
|
const { options: { devtool }, } = compilation.compiler;
|
|
41
|
-
const sourcemap = this.options.sourcemap === undefined
|
|
42
|
-
? devtool && devtool
|
|
43
|
-
: this.options.sourcemap;
|
|
41
|
+
const sourcemap = this.options.sourcemap === undefined ? !!devtool : this.options.sourcemap;
|
|
44
42
|
const assets = compilation.getAssets().filter((asset) => {
|
|
45
43
|
return !asset.info.minimized && RE_CSS_FILE.test(asset.name);
|
|
46
44
|
});
|
|
@@ -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,75 @@
|
|
|
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 utils_1 = require("@umijs/utils");
|
|
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 { transform } = (0, utils_1.importLazy)('@parcel/css');
|
|
64
|
+
const result = yield transform(Object.assign({ filename: asset.name, code, minify: true, sourceMap: sourcemap }, this.options));
|
|
65
|
+
const codeString = result.code.toString();
|
|
66
|
+
compilation.updateAsset(asset.name,
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
sourcemap
|
|
69
|
+
? new webpack_sources_1.SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, true)
|
|
70
|
+
: new webpack_sources_1.RawSource(codeString), Object.assign(Object.assign({}, asset.info), { minimized: true }));
|
|
71
|
+
})));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
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
|
}
|
|
@@ -11,7 +11,7 @@ class RuntimePublicPathPlugin {
|
|
|
11
11
|
// https://github.com/webpack/webpack/blob/master/lib/runtime/PublicPathRuntimeModule.js
|
|
12
12
|
if (module.constructor.name === 'PublicPathRuntimeModule') {
|
|
13
13
|
// @ts-ignore
|
|
14
|
-
module._cachedGeneratedCode = `__webpack_require__.p = window.publicPath;`;
|
|
14
|
+
module._cachedGeneratedCode = `__webpack_require__.p = (globalThis || window).publicPath;`;
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
17
|
});
|
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,18 +32,21 @@ 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
|
+
deadCode: (Joi) => Joi.object(),
|
|
37
38
|
define: (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()),
|
|
41
|
+
esm: (Joi) => Joi.object(),
|
|
40
42
|
externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
|
|
41
|
-
extraBabelPlugins: (Joi) => Joi.
|
|
42
|
-
extraBabelPresets: (Joi) => Joi.
|
|
43
|
+
extraBabelPlugins: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
|
|
44
|
+
extraBabelPresets: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
|
|
43
45
|
extraPostCSSPlugins: (Joi) => Joi.array(),
|
|
44
46
|
fastRefresh: (Joi) => Joi.boolean(),
|
|
45
47
|
forkTSChecker: (Joi) => Joi.object(),
|
|
46
48
|
hash: (Joi) => Joi.boolean(),
|
|
49
|
+
https: (Joi) => Joi.object(),
|
|
47
50
|
ignoreMomentLocale: (Joi) => Joi.boolean(),
|
|
48
51
|
inlineLimit: (Joi) => Joi.number(),
|
|
49
52
|
jsMinifier: (Joi) => Joi.string().valid(types_1.JSMinifier.esbuild, types_1.JSMinifier.swc, types_1.JSMinifier.terser, types_1.JSMinifier.uglifyJs, types_1.JSMinifier.none),
|
|
@@ -55,6 +58,8 @@ function getSchemas() {
|
|
|
55
58
|
loaderOptions: Joi.object(),
|
|
56
59
|
}),
|
|
57
60
|
mfsu: (Joi) => Joi.alternatives(Joi.object({
|
|
61
|
+
cacheDirectory: Joi.string(),
|
|
62
|
+
chainWebpack: Joi.function(),
|
|
58
63
|
esbuild: Joi.boolean(),
|
|
59
64
|
mfName: Joi.string(),
|
|
60
65
|
}), Joi.boolean()),
|
|
@@ -67,12 +72,11 @@ function getSchemas() {
|
|
|
67
72
|
sassLoader: (Joi) => Joi.object(),
|
|
68
73
|
srcTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
|
|
69
74
|
styleLoader: (Joi) => Joi.object(),
|
|
70
|
-
svgr: (Joi) => Joi.object(),
|
|
71
75
|
svgo: (Joi) => Joi.alternatives().try(Joi.object(), Joi.boolean()),
|
|
76
|
+
svgr: (Joi) => Joi.object(),
|
|
72
77
|
targets: (Joi) => Joi.object(),
|
|
73
|
-
writeToDisk: (Joi) => Joi.boolean(),
|
|
74
|
-
esm: (Joi) => Joi.object(),
|
|
75
78
|
theme: (Joi) => Joi.object(),
|
|
79
|
+
writeToDisk: (Joi) => Joi.boolean(),
|
|
76
80
|
};
|
|
77
81
|
}
|
|
78
82
|
exports.getSchemas = getSchemas;
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Configuration } from '@umijs/bundler-webpack/compiled/webpack';
|
|
3
|
-
import http from 'http';
|
|
4
3
|
import { IConfig } from '../types';
|
|
5
4
|
interface IOpts {
|
|
6
5
|
cwd: string;
|
|
@@ -12,5 +11,5 @@ interface IOpts {
|
|
|
12
11
|
afterMiddlewares?: any[];
|
|
13
12
|
onDevCompileDone?: Function;
|
|
14
13
|
}
|
|
15
|
-
export declare function createServer(opts: IOpts): Promise<http.Server>;
|
|
14
|
+
export declare function createServer(opts: IOpts): Promise<import("http").Server | import("https").Server | null>;
|
|
16
15
|
export {};
|