@umijs/bundler-webpack 4.0.0-canary.20220428.1 → 4.0.0-canary.20220429.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/package.json +6 -8
- package/dist/build.d.ts +0 -20
- package/dist/build.js +0 -75
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -90
- package/dist/client/client.d.ts +0 -1
- package/dist/client/client.js +0 -258
- package/dist/config/_sampleFeature.d.ts +0 -10
- package/dist/config/_sampleFeature.js +0 -22
- package/dist/config/assetRules.d.ts +0 -11
- package/dist/config/assetRules.js +0 -61
- package/dist/config/bundleAnalyzerPlugin.d.ts +0 -10
- package/dist/config/bundleAnalyzerPlugin.js +0 -30
- package/dist/config/compressPlugin.d.ts +0 -10
- package/dist/config/compressPlugin.js +0 -91
- package/dist/config/config.d.ts +0 -27
- package/dist/config/config.js +0 -226
- package/dist/config/copyPlugin.d.ts +0 -10
- package/dist/config/copyPlugin.js +0 -49
- package/dist/config/cssRules.d.ts +0 -11
- package/dist/config/cssRules.js +0 -98
- package/dist/config/definePlugin.d.ts +0 -15
- package/dist/config/definePlugin.js +0 -45
- package/dist/config/detectDeadCode.d.ts +0 -12
- package/dist/config/detectDeadCode.js +0 -120
- package/dist/config/detectDeadCodePlugin.d.ts +0 -9
- package/dist/config/detectDeadCodePlugin.js +0 -75
- package/dist/config/fastRefreshPlugin.d.ts +0 -12
- package/dist/config/fastRefreshPlugin.js +0 -34
- package/dist/config/forkTSCheckerPlugin.d.ts +0 -11
- package/dist/config/forkTSCheckerPlugin.js +0 -34
- package/dist/config/harmonyLinkingErrorPlugin.d.ts +0 -6
- package/dist/config/harmonyLinkingErrorPlugin.js +0 -42
- package/dist/config/ignorePlugin.d.ts +0 -10
- package/dist/config/ignorePlugin.js +0 -27
- package/dist/config/javaScriptRules.d.ts +0 -16
- package/dist/config/javaScriptRules.js +0 -188
- package/dist/config/manifestPlugin.d.ts +0 -11
- package/dist/config/manifestPlugin.js +0 -25
- package/dist/config/miniCSSExtractPlugin.d.ts +0 -11
- package/dist/config/miniCSSExtractPlugin.js +0 -33
- package/dist/config/nodePolyfill.d.ts +0 -10
- package/dist/config/nodePolyfill.js +0 -35
- package/dist/config/nodePrefixPlugin.d.ts +0 -11
- package/dist/config/nodePrefixPlugin.js +0 -25
- package/dist/config/progressPlugin.d.ts +0 -11
- package/dist/config/progressPlugin.js +0 -27
- package/dist/config/purgecssWebpackPlugin.d.ts +0 -10
- package/dist/config/purgecssWebpackPlugin.js +0 -32
- package/dist/config/speedMeasureWebpackPlugin.d.ts +0 -6
- package/dist/config/speedMeasureWebpackPlugin.js +0 -34
- package/dist/config/svgRules.d.ts +0 -12
- package/dist/config/svgRules.js +0 -57
- package/dist/constants.d.ts +0 -15
- package/dist/constants.js +0 -24
- package/dist/dev.d.ts +0 -25
- package/dist/dev.js +0 -145
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -20
- package/dist/loader/svgr.d.ts +0 -4
- package/dist/loader/svgr.js +0 -67
- package/dist/loader/swc.d.ts +0 -4
- package/dist/loader/swc.js +0 -79
- package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +0 -11
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +0 -63
- package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +0 -10
- package/dist/plugins/ParcelCSSMinifyPlugin.js +0 -75
- package/dist/plugins/ProgressPlugin.d.ts +0 -15
- package/dist/plugins/ProgressPlugin.js +0 -44
- package/dist/plugins/RuntimePublicPathPlugin.d.ts +0 -4
- package/dist/plugins/RuntimePublicPathPlugin.js +0 -20
- package/dist/plugins/_SamplePlugin.d.ts +0 -9
- package/dist/plugins/_SamplePlugin.js +0 -14
- package/dist/requireHook.d.ts +0 -1
- package/dist/requireHook.js +0 -31
- package/dist/schema.d.ts +0 -3
- package/dist/schema.js +0 -84
- package/dist/server/https.d.ts +0 -4
- package/dist/server/https.js +0 -74
- package/dist/server/server.d.ts +0 -17
- package/dist/server/server.js +0 -202
- package/dist/server/ws.d.ts +0 -11
- package/dist/server/ws.js +0 -42
- package/dist/swcPlugins/autoCSSModules.d.ts +0 -13
- package/dist/swcPlugins/autoCSSModules.js +0 -34
- package/dist/swcPlugins/changeImportFromString.d.ts +0 -2
- package/dist/swcPlugins/changeImportFromString.js +0 -10
- package/dist/swcPlugins/lockCoreJS.d.ts +0 -6
- package/dist/swcPlugins/lockCoreJS.js +0 -24
- package/dist/types.d.ts +0 -123
- package/dist/types.js +0 -30
- package/dist/utils/browsersList.d.ts +0 -5
- package/dist/utils/browsersList.js +0 -10
- package/dist/utils/depMatch.d.ts +0 -6
- package/dist/utils/depMatch.js +0 -46
- package/dist/utils/formatWebpackMessages.d.ts +0 -12
- package/dist/utils/formatWebpackMessages.js +0 -100
- package/dist/utils/getEsBuildTarget.d.ts +0 -5
- package/dist/utils/getEsBuildTarget.js +0 -12
|
@@ -1,120 +0,0 @@
|
|
|
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;
|
|
@@ -1,9 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,75 +0,0 @@
|
|
|
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;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
-
import { Env, IConfig } from '../types';
|
|
3
|
-
interface IOpts {
|
|
4
|
-
config: Config;
|
|
5
|
-
userConfig: IConfig;
|
|
6
|
-
cwd: string;
|
|
7
|
-
env: Env;
|
|
8
|
-
browsers: any;
|
|
9
|
-
name?: string;
|
|
10
|
-
}
|
|
11
|
-
export declare function addFastRefreshPlugin(opts: IOpts): Promise<void>;
|
|
12
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.addFastRefreshPlugin = void 0;
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
const lib_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin/lib"));
|
|
18
|
-
const constants_1 = require("../constants");
|
|
19
|
-
const types_1 = require("../types");
|
|
20
|
-
function addFastRefreshPlugin(opts) {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const { config, userConfig, name } = opts;
|
|
23
|
-
const isDev = opts.env === types_1.Env.development;
|
|
24
|
-
const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
|
|
25
|
-
// TODO: Should only run in react csr
|
|
26
|
-
if (useFastRefresh) {
|
|
27
|
-
config
|
|
28
|
-
.plugin('fastRefresh')
|
|
29
|
-
.after('hmr')
|
|
30
|
-
.use(lib_1.default, [{ overlay: false }]);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
exports.addFastRefreshPlugin = addFastRefreshPlugin;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
-
import { Env, IConfig } from '../types';
|
|
3
|
-
interface IOpts {
|
|
4
|
-
name?: string;
|
|
5
|
-
config: Config;
|
|
6
|
-
userConfig: IConfig;
|
|
7
|
-
cwd: string;
|
|
8
|
-
env: Env;
|
|
9
|
-
}
|
|
10
|
-
export declare function addForkTSCheckerPlugin(opts: IOpts): Promise<void>;
|
|
11
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.addForkTSCheckerPlugin = void 0;
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/fork-ts-checker-webpack-plugin"));
|
|
18
|
-
function addForkTSCheckerPlugin(opts) {
|
|
19
|
-
var _a;
|
|
20
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const { config, userConfig } = opts;
|
|
22
|
-
if (userConfig.forkTSChecker) {
|
|
23
|
-
// use user's typescript
|
|
24
|
-
if ((_a = userConfig.forkTSChecker.typescript) === null || _a === void 0 ? void 0 : _a.enable) {
|
|
25
|
-
userConfig.forkTSChecker.typescript.typescriptPath =
|
|
26
|
-
require.resolve('typescript');
|
|
27
|
-
}
|
|
28
|
-
config
|
|
29
|
-
.plugin('fork-ts-checker-plugin')
|
|
30
|
-
.use(fork_ts_checker_webpack_plugin_1.default, [userConfig.forkTSChecker]);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
exports.addForkTSCheckerPlugin = addForkTSCheckerPlugin;
|
|
@@ -1,42 +0,0 @@
|
|
|
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.addHarmonyLinkingErrorPlugin = void 0;
|
|
13
|
-
// ref: https://github.com/webpack/webpack/blob/ccecc17c01af96edddb931a76e7a3b21ef2969d8/lib/dependencies/HarmonyImportDependency.js#L164
|
|
14
|
-
const LINKING_ERROR_TAG = 'was not found in';
|
|
15
|
-
// build 时会出现 css modules 的引用警告,但这应该是需要忽略的
|
|
16
|
-
const CSS_NO_EXPORTS = /\.(css|sass|scss|styl|less)' \(module has no exports\)/;
|
|
17
|
-
class HarmonyLinkingErrorPlugin {
|
|
18
|
-
apply(compiler) {
|
|
19
|
-
compiler.hooks.afterCompile.tap('HarmonyLinkingErrorPlugin', (compilation) => {
|
|
20
|
-
if (!compilation.warnings.length) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const harmonyLinkingErrors = compilation.warnings.filter((w) => {
|
|
24
|
-
return (w.name === 'ModuleDependencyWarning' &&
|
|
25
|
-
!w.module.resource.includes('node_modules') &&
|
|
26
|
-
w.message.includes(LINKING_ERROR_TAG) &&
|
|
27
|
-
!CSS_NO_EXPORTS.test(w.message));
|
|
28
|
-
});
|
|
29
|
-
if (!harmonyLinkingErrors.length) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
compilation.errors.push(...harmonyLinkingErrors);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function addHarmonyLinkingErrorPlugin(opts) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const { config } = opts;
|
|
39
|
-
config.plugin('harmony-linking-error-plugin').use(HarmonyLinkingErrorPlugin);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
exports.addHarmonyLinkingErrorPlugin = addHarmonyLinkingErrorPlugin;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
-
import { Env, IConfig } from '../types';
|
|
3
|
-
interface IOpts {
|
|
4
|
-
config: Config;
|
|
5
|
-
userConfig: IConfig;
|
|
6
|
-
cwd: string;
|
|
7
|
-
env: Env;
|
|
8
|
-
}
|
|
9
|
-
export declare function addIgnorePlugin(opts: IOpts): Promise<void>;
|
|
10
|
-
export {};
|
|
@@ -1,27 +0,0 @@
|
|
|
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.addIgnorePlugin = void 0;
|
|
13
|
-
const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
|
|
14
|
-
function addIgnorePlugin(opts) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const { config, userConfig } = opts;
|
|
17
|
-
if (userConfig.ignoreMomentLocale) {
|
|
18
|
-
config.plugin('ignore-moment-locale').use(webpack_1.IgnorePlugin, [
|
|
19
|
-
{
|
|
20
|
-
resourceRegExp: /^\.\/locale$/,
|
|
21
|
-
contextRegExp: /moment$/,
|
|
22
|
-
},
|
|
23
|
-
]);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
exports.addIgnorePlugin = addIgnorePlugin;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import Config from '../../compiled/webpack-5-chain';
|
|
2
|
-
import { Env, IConfig } from '../types';
|
|
3
|
-
interface IOpts {
|
|
4
|
-
config: Config;
|
|
5
|
-
userConfig: IConfig;
|
|
6
|
-
cwd: string;
|
|
7
|
-
env: Env;
|
|
8
|
-
extraBabelPlugins: any[];
|
|
9
|
-
extraBabelPresets: any[];
|
|
10
|
-
extraBabelIncludes: string[];
|
|
11
|
-
extraEsbuildLoaderHandler: any[];
|
|
12
|
-
babelPreset: any;
|
|
13
|
-
name?: string;
|
|
14
|
-
}
|
|
15
|
-
export declare function addJavaScriptRules(opts: IOpts): Promise<void>;
|
|
16
|
-
export {};
|
|
@@ -1,188 +0,0 @@
|
|
|
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.addJavaScriptRules = void 0;
|
|
13
|
-
const mfsu_1 = require("@umijs/mfsu");
|
|
14
|
-
const utils_1 = require("@umijs/utils");
|
|
15
|
-
const path_1 = require("path");
|
|
16
|
-
const webpack_1 = require("../../compiled/webpack");
|
|
17
|
-
const constants_1 = require("../constants");
|
|
18
|
-
const types_1 = require("../types");
|
|
19
|
-
const depMatch_1 = require("../utils/depMatch");
|
|
20
|
-
function addJavaScriptRules(opts) {
|
|
21
|
-
var _a, _b;
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const { config, userConfig, cwd, name } = opts;
|
|
24
|
-
const isDev = opts.env === types_1.Env.development;
|
|
25
|
-
const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
|
|
26
|
-
const depPkgs = Object.assign({}, (0, depMatch_1.es5ImcompatibleVersionsToPkg)());
|
|
27
|
-
const srcRules = [
|
|
28
|
-
config.module
|
|
29
|
-
.rule('src')
|
|
30
|
-
.test(/\.(js|mjs)$/)
|
|
31
|
-
.include.add([
|
|
32
|
-
cwd,
|
|
33
|
-
// import module out of cwd using APP_ROOT
|
|
34
|
-
// issue: https://github.com/umijs/umi/issues/5594
|
|
35
|
-
...(process.env.APP_ROOT ? [process.cwd()] : []),
|
|
36
|
-
])
|
|
37
|
-
.end()
|
|
38
|
-
.exclude.add(/node_modules/)
|
|
39
|
-
.end(),
|
|
40
|
-
config.module.rule('jsx-ts-tsx').test(/\.(jsx|ts|tsx)$/),
|
|
41
|
-
config.module
|
|
42
|
-
.rule('extra-src')
|
|
43
|
-
.test(/\.(js|mjs)$/)
|
|
44
|
-
.include.add([
|
|
45
|
-
// support extraBabelIncludes
|
|
46
|
-
...opts.extraBabelIncludes.map((p) => {
|
|
47
|
-
// handle absolute path
|
|
48
|
-
if ((0, path_1.isAbsolute)(p)) {
|
|
49
|
-
return p;
|
|
50
|
-
}
|
|
51
|
-
// resolve npm package name
|
|
52
|
-
try {
|
|
53
|
-
if (p.startsWith('./')) {
|
|
54
|
-
return require.resolve(p, { paths: [cwd] });
|
|
55
|
-
}
|
|
56
|
-
return (0, path_1.dirname)(require.resolve(`${p}/package.json`, { paths: [cwd] }));
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
if (e.code === 'MODULE_NOT_FOUND') {
|
|
60
|
-
throw new Error('Cannot resolve extraBabelIncludes: ' + p);
|
|
61
|
-
}
|
|
62
|
-
throw e;
|
|
63
|
-
}
|
|
64
|
-
}),
|
|
65
|
-
// support es5ImcompatibleVersions
|
|
66
|
-
(path) => {
|
|
67
|
-
try {
|
|
68
|
-
// do src transform for bundler-webpack/client/client/client.js
|
|
69
|
-
if (path.includes('client/client/client'))
|
|
70
|
-
return true;
|
|
71
|
-
return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
console.error(utils_1.chalk.red(e));
|
|
75
|
-
throw e;
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
])
|
|
79
|
-
.end(),
|
|
80
|
-
];
|
|
81
|
-
if (userConfig.mdx) {
|
|
82
|
-
srcRules.push(config.module.rule('markdown').test(/\.mdx?$/));
|
|
83
|
-
}
|
|
84
|
-
const depRules = [
|
|
85
|
-
config.module
|
|
86
|
-
.rule('dep')
|
|
87
|
-
.test(/\.(js|mjs)$/)
|
|
88
|
-
.include.add(/node_modules/)
|
|
89
|
-
.end()
|
|
90
|
-
.exclude.add((path) => {
|
|
91
|
-
try {
|
|
92
|
-
return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
|
|
93
|
-
}
|
|
94
|
-
catch (e) {
|
|
95
|
-
console.error(utils_1.chalk.red(e));
|
|
96
|
-
throw e;
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
.end(),
|
|
100
|
-
];
|
|
101
|
-
// const prefix = existsSync(join(cwd, 'src')) ? join(cwd, 'src') : cwd;
|
|
102
|
-
const srcTranspiler = userConfig.srcTranspiler || types_1.Transpiler.babel;
|
|
103
|
-
srcRules.forEach((rule) => {
|
|
104
|
-
if (srcTranspiler === types_1.Transpiler.babel) {
|
|
105
|
-
rule
|
|
106
|
-
.use('babel-loader')
|
|
107
|
-
.loader(require.resolve('../../compiled/babel-loader'))
|
|
108
|
-
.options({
|
|
109
|
-
// Tell babel to guess the type, instead assuming all files are modules
|
|
110
|
-
// https://github.com/webpack/webpack/issues/4039#issuecomment-419284940
|
|
111
|
-
sourceType: 'unambiguous',
|
|
112
|
-
babelrc: false,
|
|
113
|
-
cacheDirectory: false,
|
|
114
|
-
// process.env.BABEL_CACHE !== 'none'
|
|
115
|
-
// ? join(cwd, `.umi/.cache/babel-loader`)
|
|
116
|
-
// : false,
|
|
117
|
-
targets: userConfig.targets,
|
|
118
|
-
presets: [
|
|
119
|
-
opts.babelPreset || [
|
|
120
|
-
require.resolve('@umijs/babel-preset-umi'),
|
|
121
|
-
{
|
|
122
|
-
presetEnv: {},
|
|
123
|
-
presetReact: {},
|
|
124
|
-
presetTypeScript: {},
|
|
125
|
-
pluginTransformRuntime: {},
|
|
126
|
-
pluginLockCoreJS: {},
|
|
127
|
-
pluginDynamicImportNode: false,
|
|
128
|
-
pluginAutoCSSModules: userConfig.autoCSSModules,
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
...opts.extraBabelPresets,
|
|
132
|
-
...(userConfig.extraBabelPresets || []).filter(Boolean),
|
|
133
|
-
],
|
|
134
|
-
plugins: [
|
|
135
|
-
useFastRefresh && require.resolve('react-refresh/babel'),
|
|
136
|
-
...opts.extraBabelPlugins,
|
|
137
|
-
...(userConfig.extraBabelPlugins || []),
|
|
138
|
-
].filter(Boolean),
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
else if (srcTranspiler === types_1.Transpiler.swc) {
|
|
142
|
-
const AutoCSSModule = require('../swcPlugins/autoCSSModules').default;
|
|
143
|
-
rule
|
|
144
|
-
.use('swc-loader')
|
|
145
|
-
.loader(require.resolve('../loader/swc'))
|
|
146
|
-
.options({
|
|
147
|
-
plugin: (m) => new AutoCSSModule().visitProgram(m),
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
else if (srcTranspiler === types_1.Transpiler.esbuild) {
|
|
151
|
-
rule
|
|
152
|
-
.use('esbuild-loader')
|
|
153
|
-
.loader(mfsu_1.esbuildLoader)
|
|
154
|
-
.options({
|
|
155
|
-
target: isDev ? 'esnext' : 'es2015',
|
|
156
|
-
handler: [mfsu_1.autoCssModulesHandler, ...opts.extraEsbuildLoaderHandler],
|
|
157
|
-
});
|
|
158
|
-
// esbuild loader can not auto import `React`
|
|
159
|
-
config.plugin('react-provide-plugin').use(webpack_1.ProvidePlugin, [
|
|
160
|
-
{
|
|
161
|
-
React: 'react',
|
|
162
|
-
},
|
|
163
|
-
]);
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
throw new Error(`Unsupported srcTranspiler ${srcTranspiler}.`);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
if (userConfig.mdx) {
|
|
170
|
-
config.module
|
|
171
|
-
.rule('mdx')
|
|
172
|
-
.test(/\.mdx?$/)
|
|
173
|
-
.use('mdx-loader')
|
|
174
|
-
.loader((_a = userConfig.mdx) === null || _a === void 0 ? void 0 : _a.loader)
|
|
175
|
-
.options((_b = userConfig.mdx) === null || _b === void 0 ? void 0 : _b.loaderOptions);
|
|
176
|
-
}
|
|
177
|
-
const depTranspiler = userConfig.depTranspiler || types_1.Transpiler.none;
|
|
178
|
-
depRules.forEach((_rule) => {
|
|
179
|
-
if (depTranspiler === types_1.Transpiler.none) {
|
|
180
|
-
// noop
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
throw new Error(`Unsupported depTranspiler ${depTranspiler}.`);
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
exports.addJavaScriptRules = addJavaScriptRules;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
-
import { Env, IConfig } from '../types';
|
|
3
|
-
interface IOpts {
|
|
4
|
-
name?: string;
|
|
5
|
-
config: Config;
|
|
6
|
-
userConfig: IConfig;
|
|
7
|
-
cwd: string;
|
|
8
|
-
env: Env;
|
|
9
|
-
}
|
|
10
|
-
export declare function addManifestPlugin(opts: IOpts): Promise<void>;
|
|
11
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
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.addManifestPlugin = void 0;
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
const webpack_manifest_plugin_1 = require("@umijs/bundler-webpack/compiled/webpack-manifest-plugin");
|
|
15
|
-
function addManifestPlugin(opts) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const { config, userConfig } = opts;
|
|
18
|
-
if (userConfig.manifest) {
|
|
19
|
-
config.plugin('manifest-plugin').use(webpack_manifest_plugin_1.WebpackManifestPlugin, [
|
|
20
|
-
Object.assign({ fileName: 'asset-manifest.json' }, userConfig.manifest),
|
|
21
|
-
]);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
exports.addManifestPlugin = addManifestPlugin;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
-
import { Env, IConfig } from '../types';
|
|
3
|
-
interface IOpts {
|
|
4
|
-
config: Config;
|
|
5
|
-
userConfig: IConfig;
|
|
6
|
-
cwd: string;
|
|
7
|
-
env: Env;
|
|
8
|
-
useHash: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare function addMiniCSSExtractPlugin(opts: IOpts): Promise<void>;
|
|
11
|
-
export {};
|