@umijs/bundler-webpack 4.2.6-alpha.6 → 4.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build.d.ts +22 -0
- package/dist/build.js +151 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +96 -0
- package/dist/config/_sampleFeature.d.ts +10 -0
- package/dist/config/_sampleFeature.js +35 -0
- package/dist/config/assetRules.d.ts +11 -0
- package/dist/config/assetRules.js +48 -0
- package/dist/config/bundleAnalyzerPlugin.d.ts +10 -0
- package/dist/config/bundleAnalyzerPlugin.js +43 -0
- package/dist/config/compressPlugin.d.ts +10 -0
- package/dist/config/compressPlugin.js +128 -0
- package/dist/config/config.d.ts +31 -0
- package/dist/config/config.js +243 -0
- package/dist/config/copyPlugin.d.ts +10 -0
- package/dist/config/copyPlugin.js +63 -0
- package/dist/config/cssRules.d.ts +11 -0
- package/dist/config/cssRules.js +165 -0
- package/dist/config/definePlugin.d.ts +15 -0
- package/dist/config/definePlugin.js +79 -0
- package/dist/config/detectCssModulesInDependence.d.ts +10 -0
- package/dist/config/detectCssModulesInDependence.js +151 -0
- package/dist/config/detectDeadCode.d.ts +12 -0
- package/dist/config/detectDeadCode.js +191 -0
- package/dist/config/detectDeadCodePlugin.d.ts +9 -0
- package/dist/config/detectDeadCodePlugin.js +82 -0
- package/dist/config/fastRefreshPlugin.d.ts +12 -0
- package/dist/config/fastRefreshPlugin.js +49 -0
- package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
- package/dist/config/forkTSCheckerPlugin.js +49 -0
- package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
- package/dist/config/harmonyLinkingErrorPlugin.js +53 -0
- package/dist/config/ignorePlugin.d.ts +10 -0
- package/dist/config/ignorePlugin.js +40 -0
- package/dist/config/javaScriptRules.d.ts +16 -0
- package/dist/config/javaScriptRules.js +191 -0
- package/dist/config/manifestPlugin.d.ts +11 -0
- package/dist/config/manifestPlugin.js +40 -0
- package/dist/config/miniCSSExtractPlugin.d.ts +11 -0
- package/dist/config/miniCSSExtractPlugin.js +55 -0
- package/dist/config/nodePolyfill.d.ts +10 -0
- package/dist/config/nodePolyfill.js +51 -0
- package/dist/config/nodePrefixPlugin.d.ts +11 -0
- package/dist/config/nodePrefixPlugin.js +38 -0
- package/dist/config/progressPlugin.d.ts +11 -0
- package/dist/config/progressPlugin.js +53 -0
- package/dist/config/purgecssWebpackPlugin.d.ts +10 -0
- package/dist/config/purgecssWebpackPlugin.js +43 -0
- package/dist/config/speedMeasureWebpackPlugin.d.ts +6 -0
- package/dist/config/speedMeasureWebpackPlugin.js +59 -0
- package/dist/config/ssrPlugin.d.ts +11 -0
- package/dist/config/ssrPlugin.js +98 -0
- package/dist/config/svgRules.d.ts +12 -0
- package/dist/config/svgRules.js +70 -0
- package/dist/constants.d.ts +15 -0
- package/dist/constants.js +59 -0
- package/dist/dev.d.ts +40 -0
- package/dist/dev.js +208 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +32 -0
- package/dist/loader/svgr.d.ts +4 -0
- package/dist/loader/svgr.js +84 -0
- package/dist/loader/swc.d.ts +4 -0
- package/dist/loader/swc.js +149 -0
- package/dist/parcelCSS.d.ts +2 -0
- package/dist/parcelCSS.js +39 -0
- package/dist/plugins/EsbuildMinifyFix.d.ts +8 -0
- package/dist/plugins/EsbuildMinifyFix.js +136 -0
- package/dist/plugins/ProgressPlugin.d.ts +15 -0
- package/dist/plugins/ProgressPlugin.js +69 -0
- package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
- package/dist/plugins/RuntimePublicPathPlugin.js +45 -0
- package/dist/plugins/_SamplePlugin.d.ts +9 -0
- package/dist/plugins/_SamplePlugin.js +37 -0
- package/dist/requireHook.d.ts +1 -0
- package/dist/requireHook.js +49 -0
- package/dist/schema.d.ts +4 -0
- package/dist/schema.js +178 -0
- package/dist/server/server.d.ts +17 -0
- package/dist/server/server.js +223 -0
- package/dist/server/ws.d.ts +13 -0
- package/dist/server/ws.js +76 -0
- package/dist/swcPlugins/autoCSSModules.d.ts +17 -0
- package/dist/swcPlugins/autoCSSModules.js +63 -0
- package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
- package/dist/swcPlugins/changeImportFromString.js +32 -0
- package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
- package/dist/swcPlugins/lockCoreJS.js +56 -0
- package/dist/types.d.ts +144 -0
- package/dist/types.js +61 -0
- package/dist/utils/browsersList.d.ts +5 -0
- package/dist/utils/browsersList.js +33 -0
- package/dist/utils/depMatch.d.ts +6 -0
- package/dist/utils/depMatch.js +72 -0
- package/dist/utils/formatWebpackMessages.d.ts +12 -0
- package/dist/utils/formatWebpackMessages.js +128 -0
- package/dist/utils/getEsBuildTarget.d.ts +7 -0
- package/dist/utils/getEsBuildTarget.js +46 -0
- package/dist/utils/pkgUpContainsName.d.ts +1 -0
- package/dist/utils/pkgUpContainsName.js +50 -0
- package/package.json +5 -5
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import webpack from '../compiled/webpack';
|
|
2
|
+
import type { IOpts as IConfigOpts } from './config/config';
|
|
3
|
+
import { IConfig } from './types';
|
|
4
|
+
declare type IOpts = {
|
|
5
|
+
cwd: string;
|
|
6
|
+
rootDir?: string;
|
|
7
|
+
entry: Record<string, string>;
|
|
8
|
+
config: IConfig;
|
|
9
|
+
onBuildComplete?: Function;
|
|
10
|
+
babelPreset?: any;
|
|
11
|
+
chainWebpack?: Function;
|
|
12
|
+
modifyWebpackConfig?: Function;
|
|
13
|
+
beforeBabelPlugins?: any[];
|
|
14
|
+
beforeBabelPresets?: any[];
|
|
15
|
+
extraBabelPlugins?: any[];
|
|
16
|
+
extraBabelPresets?: any[];
|
|
17
|
+
clean?: boolean;
|
|
18
|
+
watch?: boolean;
|
|
19
|
+
disableCopy?: boolean;
|
|
20
|
+
} & Pick<IConfigOpts, 'cache' | 'pkg'>;
|
|
21
|
+
export declare function build(opts: IOpts): Promise<webpack.Stats>;
|
|
22
|
+
export {};
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/build.ts
|
|
30
|
+
var build_exports = {};
|
|
31
|
+
__export(build_exports, {
|
|
32
|
+
build: () => build
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(build_exports);
|
|
35
|
+
var import_utils = require("@umijs/utils");
|
|
36
|
+
var import_path = require("path");
|
|
37
|
+
var import_webpack = __toESM(require("../compiled/webpack"));
|
|
38
|
+
var import_types = require("./types");
|
|
39
|
+
var configModule = (0, import_utils.importLazy)(
|
|
40
|
+
require.resolve("./config/config")
|
|
41
|
+
);
|
|
42
|
+
async function build(opts) {
|
|
43
|
+
const cacheDirectoryPath = (0, import_path.resolve)(
|
|
44
|
+
opts.rootDir || opts.cwd,
|
|
45
|
+
opts.config.cacheDirectoryPath || "node_modules/.cache"
|
|
46
|
+
);
|
|
47
|
+
const webpackConfig = await configModule.getConfig({
|
|
48
|
+
cwd: opts.cwd,
|
|
49
|
+
rootDir: opts.rootDir,
|
|
50
|
+
env: import_types.Env.production,
|
|
51
|
+
entry: opts.entry,
|
|
52
|
+
userConfig: opts.config,
|
|
53
|
+
analyze: process.env.ANALYZE,
|
|
54
|
+
babelPreset: opts.babelPreset,
|
|
55
|
+
extraBabelPlugins: [
|
|
56
|
+
...opts.beforeBabelPlugins || [],
|
|
57
|
+
...opts.extraBabelPlugins || []
|
|
58
|
+
],
|
|
59
|
+
extraBabelPresets: [
|
|
60
|
+
...opts.beforeBabelPresets || [],
|
|
61
|
+
...opts.extraBabelPresets || []
|
|
62
|
+
],
|
|
63
|
+
extraBabelIncludes: opts.config.extraBabelIncludes,
|
|
64
|
+
chainWebpack: opts.chainWebpack,
|
|
65
|
+
modifyWebpackConfig: opts.modifyWebpackConfig,
|
|
66
|
+
cache: opts.cache ? {
|
|
67
|
+
...opts.cache,
|
|
68
|
+
cacheDirectory: (0, import_path.join)(cacheDirectoryPath, "bundler-webpack")
|
|
69
|
+
} : void 0,
|
|
70
|
+
pkg: opts.pkg,
|
|
71
|
+
disableCopy: opts.disableCopy
|
|
72
|
+
});
|
|
73
|
+
let isFirstCompile = true;
|
|
74
|
+
return new Promise((resolve2, reject) => {
|
|
75
|
+
if (opts.clean) {
|
|
76
|
+
import_utils.rimraf.sync(webpackConfig.output.path);
|
|
77
|
+
}
|
|
78
|
+
const compiler = (0, import_webpack.default)(webpackConfig);
|
|
79
|
+
let closeWatching;
|
|
80
|
+
const handler = async (err, stats) => {
|
|
81
|
+
var _a;
|
|
82
|
+
const validErr = err || ((stats == null ? void 0 : stats.hasErrors()) ? new Error(stats.toString("errors-only")) : null);
|
|
83
|
+
await ((_a = opts.onBuildComplete) == null ? void 0 : _a.call(opts, {
|
|
84
|
+
err: validErr,
|
|
85
|
+
stats,
|
|
86
|
+
isFirstCompile,
|
|
87
|
+
time: stats ? stats.endTime - stats.startTime : null,
|
|
88
|
+
// pass close function to close watching
|
|
89
|
+
...opts.watch ? { close: closeWatching } : {}
|
|
90
|
+
}));
|
|
91
|
+
isFirstCompile = false;
|
|
92
|
+
if (validErr) {
|
|
93
|
+
(stats == null ? void 0 : stats.hasErrors()) && esbuildCompressErrorHelper(validErr.toString());
|
|
94
|
+
reject(validErr);
|
|
95
|
+
} else {
|
|
96
|
+
resolve2(stats);
|
|
97
|
+
}
|
|
98
|
+
if (!opts.watch)
|
|
99
|
+
compiler.close(() => {
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
if (opts.watch) {
|
|
103
|
+
const watching = compiler.watch(
|
|
104
|
+
webpackConfig.watchOptions || {},
|
|
105
|
+
handler
|
|
106
|
+
);
|
|
107
|
+
closeWatching = watching.close.bind(watching);
|
|
108
|
+
} else {
|
|
109
|
+
compiler.run(handler);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function esbuildCompressErrorHelper(errorMsg) {
|
|
114
|
+
if (typeof errorMsg !== "string")
|
|
115
|
+
return;
|
|
116
|
+
if (
|
|
117
|
+
// https://github.com/evanw/esbuild/blob/a5f781ecd5edeb3fb6ae8d1045507ab850462614/internal/js_parser/js_parser_lower.go#L18
|
|
118
|
+
errorMsg.includes("configured target environment") && errorMsg.includes("es2015")
|
|
119
|
+
) {
|
|
120
|
+
const terserRecommend = {
|
|
121
|
+
label: import_utils.chalk.green("change jsMinifier"),
|
|
122
|
+
details: import_utils.chalk.cyan(` jsMinifier: 'terser'`)
|
|
123
|
+
};
|
|
124
|
+
const upgradeTargetRecommend = {
|
|
125
|
+
label: import_utils.chalk.green("upgrade target"),
|
|
126
|
+
details: import_utils.chalk.cyan(` jsMinifierOptions: {
|
|
127
|
+
target: ['chrome80', 'es2020']
|
|
128
|
+
}`)
|
|
129
|
+
};
|
|
130
|
+
const ieRecommend = {
|
|
131
|
+
details: `P.S. compatible with legacy browsers: https://umijs.org/blog/legacy-browser`
|
|
132
|
+
};
|
|
133
|
+
console.log();
|
|
134
|
+
console.log(import_utils.chalk.bgRed(" COMPRESSION ERROR "));
|
|
135
|
+
console.log(
|
|
136
|
+
import_utils.chalk.yellow(
|
|
137
|
+
`esbuild minify failed, please ${terserRecommend.label} or ${upgradeTargetRecommend.label}:`
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
console.log("e.g. ");
|
|
141
|
+
console.log(terserRecommend.details);
|
|
142
|
+
console.log(" or");
|
|
143
|
+
console.log(upgradeTargetRecommend.details);
|
|
144
|
+
console.log(ieRecommend.details);
|
|
145
|
+
console.log();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
149
|
+
0 && (module.exports = {
|
|
150
|
+
build
|
|
151
|
+
});
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
|
|
24
|
+
// src/cli.ts
|
|
25
|
+
var import_esbuild = __toESM(require("@umijs/bundler-utils/compiled/esbuild"));
|
|
26
|
+
var import_utils = require("@umijs/utils");
|
|
27
|
+
var import_assert = __toESM(require("assert"));
|
|
28
|
+
var import_fs = require("fs");
|
|
29
|
+
var import_path = require("path");
|
|
30
|
+
var import_build = require("./build");
|
|
31
|
+
var import_dev = require("./dev");
|
|
32
|
+
var args = (0, import_utils.yParser)(process.argv.slice(2), {});
|
|
33
|
+
var command = args._[0];
|
|
34
|
+
var cwd = process.cwd();
|
|
35
|
+
var entry = (0, import_utils.tryPaths)([
|
|
36
|
+
(0, import_path.join)(cwd, "src/index.tsx"),
|
|
37
|
+
(0, import_path.join)(cwd, "src/index.ts"),
|
|
38
|
+
(0, import_path.join)(cwd, "index.tsx"),
|
|
39
|
+
(0, import_path.join)(cwd, "index.ts")
|
|
40
|
+
]);
|
|
41
|
+
var config = {};
|
|
42
|
+
var configFile = (0, import_path.resolve)(cwd, args.config || "config.ts");
|
|
43
|
+
import_utils.register.register({
|
|
44
|
+
implementor: import_esbuild.default
|
|
45
|
+
});
|
|
46
|
+
import_utils.register.clearFiles();
|
|
47
|
+
if ((0, import_fs.existsSync)(configFile)) {
|
|
48
|
+
require("./requireHook");
|
|
49
|
+
config = require(configFile).default;
|
|
50
|
+
}
|
|
51
|
+
Object.assign(config, args);
|
|
52
|
+
if (command === "build") {
|
|
53
|
+
(async () => {
|
|
54
|
+
process.env.NODE_ENV = "production";
|
|
55
|
+
(0, import_assert.default)(entry, `Build failed: entry not found.`);
|
|
56
|
+
try {
|
|
57
|
+
await (0, import_build.build)({
|
|
58
|
+
config,
|
|
59
|
+
cwd,
|
|
60
|
+
entry: {
|
|
61
|
+
[getEntryKey(entry)]: entry
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.error(e);
|
|
66
|
+
}
|
|
67
|
+
})();
|
|
68
|
+
} else if (command === "dev") {
|
|
69
|
+
(async () => {
|
|
70
|
+
process.env.NODE_ENV = "development";
|
|
71
|
+
try {
|
|
72
|
+
(0, import_assert.default)(entry, `Build failed: entry not found.`);
|
|
73
|
+
await (0, import_dev.dev)({
|
|
74
|
+
config,
|
|
75
|
+
cwd,
|
|
76
|
+
port: process.env.PORT,
|
|
77
|
+
entry: {
|
|
78
|
+
[getEntryKey(entry)]: entry
|
|
79
|
+
},
|
|
80
|
+
cache: {
|
|
81
|
+
buildDependencies: [].filter(Boolean)
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
} catch (e) {
|
|
85
|
+
console.error(e);
|
|
86
|
+
}
|
|
87
|
+
})();
|
|
88
|
+
} else {
|
|
89
|
+
error(`Unsupported command ${command}.`);
|
|
90
|
+
}
|
|
91
|
+
function error(msg) {
|
|
92
|
+
console.error(import_utils.chalk.red(msg));
|
|
93
|
+
}
|
|
94
|
+
function getEntryKey(path) {
|
|
95
|
+
return (0, import_path.basename)(path, (0, import_path.extname)(path));
|
|
96
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 addSampleFeature(opts: IOpts): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/config/_sampleFeature.ts
|
|
20
|
+
var sampleFeature_exports = {};
|
|
21
|
+
__export(sampleFeature_exports, {
|
|
22
|
+
addSampleFeature: () => addSampleFeature
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(sampleFeature_exports);
|
|
25
|
+
async function addSampleFeature(opts) {
|
|
26
|
+
const { config, userConfig, cwd, env } = opts;
|
|
27
|
+
config;
|
|
28
|
+
userConfig;
|
|
29
|
+
cwd;
|
|
30
|
+
env;
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
addSampleFeature
|
|
35
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
staticPathPrefix: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function addAssetRules(opts: IOpts): Promise<void>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/config/assetRules.ts
|
|
20
|
+
var assetRules_exports = {};
|
|
21
|
+
__export(assetRules_exports, {
|
|
22
|
+
addAssetRules: () => addAssetRules
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(assetRules_exports);
|
|
25
|
+
async function addAssetRules(opts) {
|
|
26
|
+
const { config, userConfig } = opts;
|
|
27
|
+
const inlineLimit = userConfig.inlineLimit;
|
|
28
|
+
const rule = config.module.rule("asset");
|
|
29
|
+
rule.oneOf("avif").test(/\.avif$/).type("asset").mimetype("image/avif").parser({
|
|
30
|
+
dataUrlCondition: {
|
|
31
|
+
maxSize: inlineLimit
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
rule.oneOf("image").test(/\.(bmp|gif|jpg|jpeg|png)$/).type("asset").parser({
|
|
35
|
+
dataUrlCondition: {
|
|
36
|
+
maxSize: inlineLimit
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const fallback = rule.oneOf("fallback").exclude.add(/^$/).add(/\.(js|mjs|cjs|jsx|ts|tsx)$/).add(/\.(css|less|sass|scss|styl|stylus)$/).add(/\.html$/).add(/\.json$/);
|
|
40
|
+
if (userConfig.mdx) {
|
|
41
|
+
fallback.add(/\.mdx?$/);
|
|
42
|
+
}
|
|
43
|
+
fallback.end().type("asset/resource");
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
addAssetRules
|
|
48
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
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 addBundleAnalyzerPlugin(opts: IOpts): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/config/bundleAnalyzerPlugin.ts
|
|
20
|
+
var bundleAnalyzerPlugin_exports = {};
|
|
21
|
+
__export(bundleAnalyzerPlugin_exports, {
|
|
22
|
+
addBundleAnalyzerPlugin: () => addBundleAnalyzerPlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(bundleAnalyzerPlugin_exports);
|
|
25
|
+
var import_webpack_bundle_analyzer = require("@umijs/bundler-webpack/compiled/webpack-bundle-analyzer");
|
|
26
|
+
async function addBundleAnalyzerPlugin(opts) {
|
|
27
|
+
const { config } = opts;
|
|
28
|
+
config.plugin("webpack-bundle-analyzer").use(import_webpack_bundle_analyzer.BundleAnalyzerPlugin, [
|
|
29
|
+
// https://github.com/webpack-contrib/webpack-bundle-analyzer
|
|
30
|
+
{
|
|
31
|
+
analyzerMode: "server",
|
|
32
|
+
analyzerPort: process.env.ANALYZE_PORT || 8888,
|
|
33
|
+
openAnalyzer: false,
|
|
34
|
+
logLevel: "info",
|
|
35
|
+
defaultSizes: "parsed",
|
|
36
|
+
...opts.userConfig.analyze
|
|
37
|
+
}
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
addBundleAnalyzerPlugin
|
|
43
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
}
|
|
9
|
+
export declare function addCompressPlugin(opts: IOpts): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/config/compressPlugin.ts
|
|
30
|
+
var compressPlugin_exports = {};
|
|
31
|
+
__export(compressPlugin_exports, {
|
|
32
|
+
addCompressPlugin: () => addCompressPlugin
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(compressPlugin_exports);
|
|
35
|
+
var import_css_minimizer_webpack_plugin = __toESM(require("@umijs/bundler-webpack/compiled/css-minimizer-webpack-plugin"));
|
|
36
|
+
var import_terser_webpack_plugin = __toESM(require("../../compiled/terser-webpack-plugin"));
|
|
37
|
+
var import_EsbuildMinifyFix = require("../plugins/EsbuildMinifyFix");
|
|
38
|
+
var import_types = require("../types");
|
|
39
|
+
var import_getEsBuildTarget = require("../utils/getEsBuildTarget");
|
|
40
|
+
async function addCompressPlugin(opts) {
|
|
41
|
+
const { config, userConfig, env } = opts;
|
|
42
|
+
const jsMinifier = userConfig.jsMinifier || import_types.JSMinifier.esbuild;
|
|
43
|
+
const cssMinifier = userConfig.cssMinifier || import_types.CSSMinifier.esbuild;
|
|
44
|
+
if (env === import_types.Env.development || process.env.COMPRESS === "none" || jsMinifier === import_types.JSMinifier.none && cssMinifier === import_types.CSSMinifier.none) {
|
|
45
|
+
config.optimization.minimize(false);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
config.optimization.minimize(true);
|
|
49
|
+
const esbuildTarget = (0, import_getEsBuildTarget.getEsBuildTarget)({
|
|
50
|
+
targets: userConfig.targets || {},
|
|
51
|
+
jsMinifier
|
|
52
|
+
});
|
|
53
|
+
if (!esbuildTarget.includes("es2015")) {
|
|
54
|
+
esbuildTarget.push("es2015");
|
|
55
|
+
}
|
|
56
|
+
let minify;
|
|
57
|
+
let terserOptions;
|
|
58
|
+
if (jsMinifier === import_types.JSMinifier.esbuild) {
|
|
59
|
+
minify = import_terser_webpack_plugin.default.esbuildMinify;
|
|
60
|
+
terserOptions = {
|
|
61
|
+
target: esbuildTarget,
|
|
62
|
+
// remove all comments
|
|
63
|
+
legalComments: "none"
|
|
64
|
+
};
|
|
65
|
+
if (userConfig.esbuildMinifyIIFE) {
|
|
66
|
+
config.plugin("EsbuildMinifyFix").use(import_EsbuildMinifyFix.EsbuildMinifyFix);
|
|
67
|
+
}
|
|
68
|
+
} else if (jsMinifier === import_types.JSMinifier.terser) {
|
|
69
|
+
minify = import_terser_webpack_plugin.default.terserMinify;
|
|
70
|
+
terserOptions = {
|
|
71
|
+
format: {
|
|
72
|
+
comments: false
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
} else if (jsMinifier === import_types.JSMinifier.swc) {
|
|
76
|
+
minify = import_terser_webpack_plugin.default.swcMinify;
|
|
77
|
+
} else if (jsMinifier === import_types.JSMinifier.uglifyJs) {
|
|
78
|
+
minify = import_terser_webpack_plugin.default.uglifyJsMinify;
|
|
79
|
+
terserOptions = {
|
|
80
|
+
output: {
|
|
81
|
+
comments: false
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
} else if (jsMinifier !== import_types.JSMinifier.none) {
|
|
85
|
+
throw new Error(`Unsupported jsMinifier ${userConfig.jsMinifier}.`);
|
|
86
|
+
}
|
|
87
|
+
terserOptions = {
|
|
88
|
+
...terserOptions,
|
|
89
|
+
...userConfig.jsMinifierOptions
|
|
90
|
+
};
|
|
91
|
+
if (jsMinifier !== import_types.JSMinifier.none) {
|
|
92
|
+
config.optimization.minimizer(`js-${jsMinifier}`).use(import_terser_webpack_plugin.default, [
|
|
93
|
+
{
|
|
94
|
+
extractComments: false,
|
|
95
|
+
minify,
|
|
96
|
+
terserOptions
|
|
97
|
+
}
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
let cssMinify;
|
|
101
|
+
let minimizerOptions;
|
|
102
|
+
if (cssMinifier === import_types.CSSMinifier.esbuild) {
|
|
103
|
+
cssMinify = import_css_minimizer_webpack_plugin.default.esbuildMinify;
|
|
104
|
+
minimizerOptions = {
|
|
105
|
+
target: esbuildTarget
|
|
106
|
+
};
|
|
107
|
+
} else if (cssMinifier === import_types.CSSMinifier.cssnano) {
|
|
108
|
+
cssMinify = import_css_minimizer_webpack_plugin.default.cssnanoMinify;
|
|
109
|
+
} else if (cssMinifier === import_types.CSSMinifier.parcelCSS) {
|
|
110
|
+
cssMinify = import_css_minimizer_webpack_plugin.default.lightningCssMinify;
|
|
111
|
+
} else if (cssMinifier !== import_types.CSSMinifier.none) {
|
|
112
|
+
throw new Error(`Unsupported cssMinifier ${userConfig.cssMinifier}.`);
|
|
113
|
+
}
|
|
114
|
+
minimizerOptions = {
|
|
115
|
+
...minimizerOptions,
|
|
116
|
+
...userConfig.cssMinifierOptions
|
|
117
|
+
};
|
|
118
|
+
config.optimization.minimizer(`css-${cssMinifier}`).use(import_css_minimizer_webpack_plugin.default, [
|
|
119
|
+
{
|
|
120
|
+
minify: cssMinify,
|
|
121
|
+
minimizerOptions
|
|
122
|
+
}
|
|
123
|
+
]);
|
|
124
|
+
}
|
|
125
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
126
|
+
0 && (module.exports = {
|
|
127
|
+
addCompressPlugin
|
|
128
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Configuration } from '../../compiled/webpack';
|
|
2
|
+
import { Env, IConfig } from '../types';
|
|
3
|
+
export interface IOpts {
|
|
4
|
+
cwd: string;
|
|
5
|
+
rootDir?: string;
|
|
6
|
+
env: Env;
|
|
7
|
+
entry: Record<string, string>;
|
|
8
|
+
extraBabelPresets?: any[];
|
|
9
|
+
extraBabelPlugins?: any[];
|
|
10
|
+
extraBabelIncludes?: Array<string | RegExp>;
|
|
11
|
+
extraEsbuildLoaderHandler?: any[];
|
|
12
|
+
babelPreset?: any;
|
|
13
|
+
chainWebpack?: Function;
|
|
14
|
+
modifyWebpackConfig?: Function;
|
|
15
|
+
hash?: boolean;
|
|
16
|
+
hmr?: boolean;
|
|
17
|
+
staticPathPrefix?: string;
|
|
18
|
+
userConfig: IConfig;
|
|
19
|
+
analyze?: any;
|
|
20
|
+
name?: string;
|
|
21
|
+
cache?: {
|
|
22
|
+
absNodeModulesPath?: string;
|
|
23
|
+
buildDependencies?: string[];
|
|
24
|
+
cacheDirectory?: string;
|
|
25
|
+
};
|
|
26
|
+
pkg?: Record<string, any>;
|
|
27
|
+
disableCopy?: boolean;
|
|
28
|
+
host?: string;
|
|
29
|
+
port?: number;
|
|
30
|
+
}
|
|
31
|
+
export declare function getConfig(opts: IOpts): Promise<Configuration>;
|