@umijs/bundler-webpack 4.2.6-alpha.6 → 4.2.6-alpha.7
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 +16 -0
- package/dist/config/definePlugin.js +80 -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
|
@@ -0,0 +1,243 @@
|
|
|
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/config.ts
|
|
30
|
+
var config_exports = {};
|
|
31
|
+
__export(config_exports, {
|
|
32
|
+
getConfig: () => getConfig
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(config_exports);
|
|
35
|
+
var import_case_sensitive_paths_webpack_plugin = __toESM(require("@umijs/case-sensitive-paths-webpack-plugin"));
|
|
36
|
+
var import_utils = require("@umijs/utils");
|
|
37
|
+
var import_path = require("path");
|
|
38
|
+
var import_webpack = __toESM(require("../../compiled/webpack"));
|
|
39
|
+
var import_webpack_5_chain = __toESM(require("../../compiled/webpack-5-chain"));
|
|
40
|
+
var import_constants = require("../constants");
|
|
41
|
+
var import_RuntimePublicPathPlugin = require("../plugins/RuntimePublicPathPlugin");
|
|
42
|
+
var import_types = require("../types");
|
|
43
|
+
var import_browsersList = require("../utils/browsersList");
|
|
44
|
+
var import_assetRules = require("./assetRules");
|
|
45
|
+
var import_bundleAnalyzerPlugin = require("./bundleAnalyzerPlugin");
|
|
46
|
+
var import_compressPlugin = require("./compressPlugin");
|
|
47
|
+
var import_copyPlugin = require("./copyPlugin");
|
|
48
|
+
var import_cssRules = require("./cssRules");
|
|
49
|
+
var import_definePlugin = require("./definePlugin");
|
|
50
|
+
var import_detectCssModulesInDependence = require("./detectCssModulesInDependence");
|
|
51
|
+
var import_detectDeadCodePlugin = require("./detectDeadCodePlugin");
|
|
52
|
+
var import_fastRefreshPlugin = require("./fastRefreshPlugin");
|
|
53
|
+
var import_forkTSCheckerPlugin = require("./forkTSCheckerPlugin");
|
|
54
|
+
var import_harmonyLinkingErrorPlugin = require("./harmonyLinkingErrorPlugin");
|
|
55
|
+
var import_ignorePlugin = require("./ignorePlugin");
|
|
56
|
+
var import_javaScriptRules = require("./javaScriptRules");
|
|
57
|
+
var import_manifestPlugin = require("./manifestPlugin");
|
|
58
|
+
var import_miniCSSExtractPlugin = require("./miniCSSExtractPlugin");
|
|
59
|
+
var import_nodePolyfill = require("./nodePolyfill");
|
|
60
|
+
var import_progressPlugin = require("./progressPlugin");
|
|
61
|
+
var import_speedMeasureWebpackPlugin = require("./speedMeasureWebpackPlugin");
|
|
62
|
+
var import_ssrPlugin = __toESM(require("./ssrPlugin"));
|
|
63
|
+
var import_svgRules = require("./svgRules");
|
|
64
|
+
async function getConfig(opts) {
|
|
65
|
+
var _a, _b, _c;
|
|
66
|
+
const { userConfig } = opts;
|
|
67
|
+
const isDev = opts.env === import_types.Env.development;
|
|
68
|
+
const config = new import_webpack_5_chain.default();
|
|
69
|
+
userConfig.targets || (userConfig.targets = import_constants.DEFAULT_BROWSER_TARGETS);
|
|
70
|
+
userConfig.inlineLimit = parseInt(userConfig.inlineLimit || "10000", 10);
|
|
71
|
+
const useHash = !!(opts.hash || userConfig.hash && !isDev);
|
|
72
|
+
const applyOpts = {
|
|
73
|
+
name: opts.name,
|
|
74
|
+
config,
|
|
75
|
+
userConfig,
|
|
76
|
+
cwd: opts.cwd,
|
|
77
|
+
env: opts.env,
|
|
78
|
+
babelPreset: opts.babelPreset,
|
|
79
|
+
extraBabelPlugins: opts.extraBabelPlugins || [],
|
|
80
|
+
extraBabelPresets: opts.extraBabelPresets || [],
|
|
81
|
+
extraBabelIncludes: opts.extraBabelIncludes || [],
|
|
82
|
+
extraEsbuildLoaderHandler: opts.extraEsbuildLoaderHandler || [],
|
|
83
|
+
browsers: (0, import_browsersList.getBrowsersList)({
|
|
84
|
+
targets: userConfig.targets
|
|
85
|
+
}),
|
|
86
|
+
useHash,
|
|
87
|
+
staticPathPrefix: opts.staticPathPrefix !== void 0 ? opts.staticPathPrefix : "static/",
|
|
88
|
+
port: opts.port,
|
|
89
|
+
host: opts.host
|
|
90
|
+
};
|
|
91
|
+
config.name(opts.name);
|
|
92
|
+
config.mode(opts.env);
|
|
93
|
+
config.stats("none");
|
|
94
|
+
Object.keys(opts.entry).forEach((key) => {
|
|
95
|
+
const entry = config.entry(key);
|
|
96
|
+
if (isDev && opts.hmr) {
|
|
97
|
+
entry.add(require.resolve("../../client/client/client"));
|
|
98
|
+
}
|
|
99
|
+
entry.add(opts.entry[key]);
|
|
100
|
+
});
|
|
101
|
+
config.devtool(
|
|
102
|
+
isDev ? userConfig.devtool === false ? false : userConfig.devtool || import_constants.DEFAULT_DEVTOOL : userConfig.devtool
|
|
103
|
+
);
|
|
104
|
+
const absOutputPath = (0, import_path.resolve)(
|
|
105
|
+
opts.cwd,
|
|
106
|
+
userConfig.outputPath || import_constants.DEFAULT_OUTPUT_PATH
|
|
107
|
+
);
|
|
108
|
+
const disableCompress = process.env.COMPRESS === "none";
|
|
109
|
+
config.output.path(absOutputPath).filename(useHash ? `[name].[contenthash:8].js` : `[name].js`).chunkFilename(
|
|
110
|
+
useHash ? `[name].[contenthash:8].async.js` : `[name].async.js`
|
|
111
|
+
).publicPath(userConfig.publicPath || "auto").pathinfo(isDev || disableCompress).set(
|
|
112
|
+
"assetModuleFilename",
|
|
113
|
+
`${applyOpts.staticPathPrefix}[name].[hash:8][ext]`
|
|
114
|
+
).set("hashFunction", "xxhash64");
|
|
115
|
+
config.resolve.set("symlinks", true).modules.add("node_modules").end().alias.merge(userConfig.alias || {}).end().extensions.merge([
|
|
116
|
+
".ts",
|
|
117
|
+
".tsx",
|
|
118
|
+
".js",
|
|
119
|
+
".jsx",
|
|
120
|
+
".mjs",
|
|
121
|
+
".cjs",
|
|
122
|
+
".json",
|
|
123
|
+
".wasm"
|
|
124
|
+
]).end();
|
|
125
|
+
config.externals(userConfig.externals || []);
|
|
126
|
+
config.target(["web", "es5"]);
|
|
127
|
+
config.experiments({
|
|
128
|
+
topLevelAwait: true,
|
|
129
|
+
outputModule: !!userConfig.esm
|
|
130
|
+
});
|
|
131
|
+
await (0, import_nodePolyfill.addNodePolyfill)(applyOpts);
|
|
132
|
+
await (0, import_javaScriptRules.addJavaScriptRules)(applyOpts);
|
|
133
|
+
await (0, import_cssRules.addCSSRules)(applyOpts);
|
|
134
|
+
await (0, import_assetRules.addAssetRules)(applyOpts);
|
|
135
|
+
await (0, import_svgRules.addSVGRules)(applyOpts);
|
|
136
|
+
await (0, import_miniCSSExtractPlugin.addMiniCSSExtractPlugin)(applyOpts);
|
|
137
|
+
await (0, import_ignorePlugin.addIgnorePlugin)(applyOpts);
|
|
138
|
+
await (0, import_definePlugin.addDefinePlugin)(applyOpts);
|
|
139
|
+
await (0, import_fastRefreshPlugin.addFastRefreshPlugin)(applyOpts);
|
|
140
|
+
await (0, import_progressPlugin.addProgressPlugin)(applyOpts);
|
|
141
|
+
await (0, import_detectDeadCodePlugin.addDetectDeadCodePlugin)(applyOpts);
|
|
142
|
+
await (0, import_forkTSCheckerPlugin.addForkTSCheckerPlugin)(applyOpts);
|
|
143
|
+
if (!opts.disableCopy) {
|
|
144
|
+
await (0, import_copyPlugin.addCopyPlugin)(applyOpts);
|
|
145
|
+
}
|
|
146
|
+
await (0, import_manifestPlugin.addManifestPlugin)(applyOpts);
|
|
147
|
+
if (isDev && opts.hmr) {
|
|
148
|
+
config.plugin("hmr").use(import_webpack.default.HotModuleReplacementPlugin);
|
|
149
|
+
}
|
|
150
|
+
await (0, import_ssrPlugin.default)(applyOpts);
|
|
151
|
+
await (0, import_compressPlugin.addCompressPlugin)(applyOpts);
|
|
152
|
+
await (0, import_harmonyLinkingErrorPlugin.addHarmonyLinkingErrorPlugin)(applyOpts);
|
|
153
|
+
await (0, import_detectCssModulesInDependence.addDependenceCssModulesDetector)(applyOpts);
|
|
154
|
+
if (userConfig.runtimePublicPath) {
|
|
155
|
+
config.plugin("runtimePublicPath").use(import_RuntimePublicPathPlugin.RuntimePublicPathPlugin);
|
|
156
|
+
}
|
|
157
|
+
config.plugin("case-sensitive-paths").use(import_case_sensitive_paths_webpack_plugin.default);
|
|
158
|
+
if (opts.cache) {
|
|
159
|
+
config.cache({
|
|
160
|
+
type: "filesystem",
|
|
161
|
+
version: require("../../package.json").version,
|
|
162
|
+
buildDependencies: {
|
|
163
|
+
config: opts.cache.buildDependencies || []
|
|
164
|
+
},
|
|
165
|
+
cacheDirectory: opts.cache.cacheDirectory || // 使用 rootDir 是在有 APP_ROOT 时,把 cache 目录放在根目录下
|
|
166
|
+
(0, import_path.join)(
|
|
167
|
+
opts.rootDir || opts.cwd,
|
|
168
|
+
"node_modules",
|
|
169
|
+
".cache",
|
|
170
|
+
"bundler-webpack"
|
|
171
|
+
)
|
|
172
|
+
});
|
|
173
|
+
if (require.resolve("@umijs/utils/package").includes("_@umijs_utils@")) {
|
|
174
|
+
const nodeModulesPath = opts.cache.absNodeModulesPath || (0, import_path.join)(opts.rootDir || opts.cwd, "node_modules");
|
|
175
|
+
const localLinkedNodeModules = Object.keys(
|
|
176
|
+
Object.assign(
|
|
177
|
+
{},
|
|
178
|
+
(_a = opts.pkg) == null ? void 0 : _a.dependencies,
|
|
179
|
+
(_b = opts.pkg) == null ? void 0 : _b.peerDependencies,
|
|
180
|
+
(_c = opts.pkg) == null ? void 0 : _c.devDependencies
|
|
181
|
+
)
|
|
182
|
+
).map((pkg) => {
|
|
183
|
+
try {
|
|
184
|
+
return (0, import_path.resolve)(
|
|
185
|
+
import_utils.resolve.sync(`${pkg}/package.json`, {
|
|
186
|
+
basedir: opts.rootDir || opts.cwd,
|
|
187
|
+
preserveSymlinks: false
|
|
188
|
+
}),
|
|
189
|
+
"../node_modules"
|
|
190
|
+
);
|
|
191
|
+
} catch {
|
|
192
|
+
return opts.rootDir || opts.cwd;
|
|
193
|
+
}
|
|
194
|
+
}).filter((pkg) => !pkg.startsWith(opts.rootDir || opts.cwd));
|
|
195
|
+
if (localLinkedNodeModules.length) {
|
|
196
|
+
import_utils.logger.info(
|
|
197
|
+
`Detected local linked tnpm node_modules, to avoid oom, they will be treated as immutablePaths & managedPaths in webpack snapshot:`
|
|
198
|
+
);
|
|
199
|
+
localLinkedNodeModules.forEach((p) => import_utils.logger.info(` ${p}`));
|
|
200
|
+
}
|
|
201
|
+
config.snapshot({
|
|
202
|
+
immutablePaths: [nodeModulesPath, ...localLinkedNodeModules],
|
|
203
|
+
managedPaths: [nodeModulesPath, ...localLinkedNodeModules]
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
config.infrastructureLogging({
|
|
207
|
+
level: "error",
|
|
208
|
+
...process.env.WEBPACK_FS_CACHE_DEBUG ? {
|
|
209
|
+
debug: /webpack\.cache/
|
|
210
|
+
} : {}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
if (opts.analyze) {
|
|
214
|
+
await (0, import_bundleAnalyzerPlugin.addBundleAnalyzerPlugin)(applyOpts);
|
|
215
|
+
}
|
|
216
|
+
if (opts.chainWebpack) {
|
|
217
|
+
await opts.chainWebpack(config, {
|
|
218
|
+
env: opts.env,
|
|
219
|
+
webpack: import_webpack.default
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (userConfig.chainWebpack) {
|
|
223
|
+
await userConfig.chainWebpack(config, {
|
|
224
|
+
env: opts.env,
|
|
225
|
+
webpack: import_webpack.default
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
let webpackConfig = config.toConfig();
|
|
229
|
+
webpackConfig = await (0, import_speedMeasureWebpackPlugin.addSpeedMeasureWebpackPlugin)({
|
|
230
|
+
webpackConfig
|
|
231
|
+
});
|
|
232
|
+
if (opts.modifyWebpackConfig) {
|
|
233
|
+
webpackConfig = await opts.modifyWebpackConfig(webpackConfig, {
|
|
234
|
+
env: opts.env,
|
|
235
|
+
webpack: import_webpack.default
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return webpackConfig;
|
|
239
|
+
}
|
|
240
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
241
|
+
0 && (module.exports = {
|
|
242
|
+
getConfig
|
|
243
|
+
});
|
|
@@ -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 addCopyPlugin(opts: IOpts): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
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/copyPlugin.ts
|
|
20
|
+
var copyPlugin_exports = {};
|
|
21
|
+
__export(copyPlugin_exports, {
|
|
22
|
+
addCopyPlugin: () => addCopyPlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(copyPlugin_exports);
|
|
25
|
+
var import_fs = require("fs");
|
|
26
|
+
var import_path = require("path");
|
|
27
|
+
async function addCopyPlugin(opts) {
|
|
28
|
+
var _a;
|
|
29
|
+
const { config, userConfig, cwd } = opts;
|
|
30
|
+
const publicDir = (0, import_path.join)(cwd, "public");
|
|
31
|
+
const copyPatterns = [
|
|
32
|
+
(0, import_fs.existsSync)(publicDir) && (0, import_fs.readdirSync)(publicDir).length && {
|
|
33
|
+
from: publicDir,
|
|
34
|
+
// ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
|
|
35
|
+
// Set minimized so terser will not do minimize
|
|
36
|
+
info: { minimized: true }
|
|
37
|
+
},
|
|
38
|
+
...userConfig.copy ? (_a = userConfig.copy) == null ? void 0 : _a.map((pattern) => {
|
|
39
|
+
if (typeof pattern === "string") {
|
|
40
|
+
return {
|
|
41
|
+
from: (0, import_path.resolve)(cwd, pattern),
|
|
42
|
+
info: { minimized: true }
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
from: (0, import_path.resolve)(cwd, pattern.from),
|
|
47
|
+
to: (0, import_path.resolve)(cwd, pattern.to),
|
|
48
|
+
info: { minimized: true }
|
|
49
|
+
};
|
|
50
|
+
}) : []
|
|
51
|
+
].filter(Boolean);
|
|
52
|
+
if (copyPatterns.length) {
|
|
53
|
+
config.plugin("copy").use(require("@umijs/bundler-webpack/compiled/copy-webpack-plugin"), [
|
|
54
|
+
{
|
|
55
|
+
patterns: copyPatterns
|
|
56
|
+
}
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
addCopyPlugin
|
|
63
|
+
});
|
|
@@ -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
|
+
browsers: any;
|
|
9
|
+
}
|
|
10
|
+
export declare function addCSSRules(opts: IOpts): Promise<void>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
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/cssRules.ts
|
|
30
|
+
var cssRules_exports = {};
|
|
31
|
+
__export(cssRules_exports, {
|
|
32
|
+
addCSSRules: () => addCSSRules
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(cssRules_exports);
|
|
35
|
+
var import_utils = require("@umijs/utils");
|
|
36
|
+
async function addCSSRules(opts) {
|
|
37
|
+
const { config, userConfig } = opts;
|
|
38
|
+
const rulesConfig = [
|
|
39
|
+
{ name: "css", test: /\.css(\?.*)?$/ },
|
|
40
|
+
{
|
|
41
|
+
name: "less",
|
|
42
|
+
test: /\.less(\?.*)?$/,
|
|
43
|
+
loader: require.resolve("@umijs/bundler-webpack/compiled/less-loader"),
|
|
44
|
+
loaderOptions: {
|
|
45
|
+
implementation: require.resolve("@umijs/bundler-utils/compiled/less"),
|
|
46
|
+
lessOptions: {
|
|
47
|
+
modifyVars: userConfig.theme,
|
|
48
|
+
javascriptEnabled: true,
|
|
49
|
+
...userConfig.lessLoader
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "sass",
|
|
55
|
+
test: /\.(sass|scss)(\?.*)?$/,
|
|
56
|
+
loader: require.resolve("@umijs/bundler-webpack/compiled/sass-loader"),
|
|
57
|
+
loaderOptions: userConfig.sassLoader || {}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "stylus",
|
|
61
|
+
test: /\.(styl|stylus)(\?.*)?$/,
|
|
62
|
+
loader: require.resolve("@umijs/bundler-webpack/compiled/stylus-loader"),
|
|
63
|
+
loaderOptions: userConfig.stylusLoader || {}
|
|
64
|
+
}
|
|
65
|
+
];
|
|
66
|
+
const cssPublicPath = userConfig.cssPublicPath || "./";
|
|
67
|
+
for (const { name, test, loader, loaderOptions } of rulesConfig) {
|
|
68
|
+
const rule = config.module.rule(name);
|
|
69
|
+
const nestRulesConfig = [
|
|
70
|
+
userConfig.autoCSSModules && {
|
|
71
|
+
rule: rule.test(test).oneOf("css-modules").resourceQuery(/modules/),
|
|
72
|
+
isAutoCSSModuleRule: true
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
rule: rule.test(test).oneOf("css").sideEffects(true),
|
|
76
|
+
isAutoCSSModuleRule: false
|
|
77
|
+
}
|
|
78
|
+
].filter(Boolean);
|
|
79
|
+
for (const { rule: rule2, isAutoCSSModuleRule } of nestRulesConfig) {
|
|
80
|
+
if (userConfig.styleLoader) {
|
|
81
|
+
rule2.use("style-loader").loader(
|
|
82
|
+
require.resolve("@umijs/bundler-webpack/compiled/style-loader")
|
|
83
|
+
).options({ base: 0, esModule: true, ...userConfig.styleLoader });
|
|
84
|
+
} else {
|
|
85
|
+
rule2.use("mini-css-extract-plugin").loader(
|
|
86
|
+
require.resolve("@umijs/bundler-webpack/compiled/mini-css-extract-plugin/loader")
|
|
87
|
+
).options({
|
|
88
|
+
publicPath: cssPublicPath,
|
|
89
|
+
emit: true,
|
|
90
|
+
esModule: true
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const getLocalIdent = userConfig.ssr && userConfig.ssr.compiler === "esbuild" ? getLocalIdentForSSR : void 0;
|
|
94
|
+
const localIdentName = "[local]___[hash:base64:5]";
|
|
95
|
+
let cssLoaderModulesConfig;
|
|
96
|
+
if (isAutoCSSModuleRule) {
|
|
97
|
+
cssLoaderModulesConfig = {
|
|
98
|
+
localIdentName,
|
|
99
|
+
...userConfig.cssLoaderModules,
|
|
100
|
+
getLocalIdent
|
|
101
|
+
};
|
|
102
|
+
} else if (userConfig.normalCSSLoaderModules) {
|
|
103
|
+
cssLoaderModulesConfig = {
|
|
104
|
+
localIdentName,
|
|
105
|
+
auto: true,
|
|
106
|
+
...userConfig.normalCSSLoaderModules,
|
|
107
|
+
getLocalIdent
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
rule2.use("css-loader").loader(require.resolve("css-loader")).options({
|
|
111
|
+
importLoaders: 1,
|
|
112
|
+
esModule: true,
|
|
113
|
+
url: {
|
|
114
|
+
filter: (url) => {
|
|
115
|
+
if (url.startsWith("/"))
|
|
116
|
+
return false;
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
import: true,
|
|
121
|
+
modules: cssLoaderModulesConfig,
|
|
122
|
+
...userConfig.cssLoader
|
|
123
|
+
});
|
|
124
|
+
rule2.use("postcss-loader").loader(
|
|
125
|
+
require.resolve("@umijs/bundler-webpack/compiled/postcss-loader")
|
|
126
|
+
).options({
|
|
127
|
+
postcssOptions: {
|
|
128
|
+
ident: "postcss",
|
|
129
|
+
plugins: [
|
|
130
|
+
require("@umijs/bundler-webpack/compiled/postcss-flexbugs-fixes"),
|
|
131
|
+
require("postcss-preset-env")({
|
|
132
|
+
browsers: opts.browsers,
|
|
133
|
+
autoprefixer: {
|
|
134
|
+
flexbox: "no-2009",
|
|
135
|
+
...userConfig.autoprefixer
|
|
136
|
+
},
|
|
137
|
+
stage: 3
|
|
138
|
+
})
|
|
139
|
+
].concat(userConfig.extraPostCSSPlugins || []),
|
|
140
|
+
...userConfig.postcssLoader
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
if (loader) {
|
|
144
|
+
rule2.use(`${name}-loader`).loader(loader).options(loaderOptions || {});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function ensureLastSlash(path) {
|
|
150
|
+
return path.endsWith("/") ? path : path + "/";
|
|
151
|
+
}
|
|
152
|
+
function getLocalIdentForSSR(context, localIdentName, localName, opt) {
|
|
153
|
+
const classIdent = ((0, import_utils.winPath)(context.resourcePath).replace(
|
|
154
|
+
(0, import_utils.winPath)(ensureLastSlash(opt.context)),
|
|
155
|
+
""
|
|
156
|
+
) + "@" + localName).trim();
|
|
157
|
+
let hash = Buffer.from(classIdent).toString("base64").replace(/=/g, "");
|
|
158
|
+
hash = hash.substring(hash.length - 5);
|
|
159
|
+
const result = localIdentName.replace(/\[local]/g, localName).replace(/\[hash[^\[]*?]/g, hash);
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
163
|
+
0 && (module.exports = {
|
|
164
|
+
addCSSRules
|
|
165
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
+
import type { Env, IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
config: Config;
|
|
5
|
+
userConfig: IConfig;
|
|
6
|
+
cwd: string;
|
|
7
|
+
env: Env;
|
|
8
|
+
host?: string;
|
|
9
|
+
port?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function resolveDefine(opts: IOpts): {
|
|
12
|
+
'process.env': Record<string, any>;
|
|
13
|
+
'process.env.SSR_MANIFEST': string;
|
|
14
|
+
};
|
|
15
|
+
export declare function addDefinePlugin(opts: IOpts): Promise<void>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
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/definePlugin.ts
|
|
20
|
+
var definePlugin_exports = {};
|
|
21
|
+
__export(definePlugin_exports, {
|
|
22
|
+
addDefinePlugin: () => addDefinePlugin,
|
|
23
|
+
resolveDefine: () => resolveDefine
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(definePlugin_exports);
|
|
26
|
+
var import_webpack = require("@umijs/bundler-webpack/compiled/webpack");
|
|
27
|
+
var prefixRE = /^UMI_APP_/;
|
|
28
|
+
var ENV_SHOULD_PASS = ["NODE_ENV", "HMR", "SOCKET_SERVER", "ERROR_OVERLAY"];
|
|
29
|
+
var SOCKET_IGNORE_HOSTS = ["0.0.0.0", "127.0.0.1", "localhost"];
|
|
30
|
+
var CUSTOM_ENV_GETTER = {
|
|
31
|
+
SOCKET_SERVER: (opts) => {
|
|
32
|
+
const { userConfig, host, port } = opts;
|
|
33
|
+
const socketServer = process.env.SOCKET_SERVER;
|
|
34
|
+
if (socketServer) {
|
|
35
|
+
return socketServer;
|
|
36
|
+
}
|
|
37
|
+
if (host && !SOCKET_IGNORE_HOSTS.includes(host)) {
|
|
38
|
+
const protocol = userConfig.https ? "https:" : "http:";
|
|
39
|
+
return `${protocol}//${host}:${port || 8e3}`;
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
function resolveDefine(opts) {
|
|
45
|
+
const { userConfig } = opts;
|
|
46
|
+
const env = {};
|
|
47
|
+
ENV_SHOULD_PASS.concat(
|
|
48
|
+
Object.keys(process.env).filter((k) => prefixRE.test(k))
|
|
49
|
+
).forEach((key) => {
|
|
50
|
+
const envValue = CUSTOM_ENV_GETTER[key] ? CUSTOM_ENV_GETTER[key](opts) : process.env[key];
|
|
51
|
+
if (typeof envValue === "undefined") {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
env[key] = envValue;
|
|
55
|
+
});
|
|
56
|
+
env.PUBLIC_PATH = userConfig.publicPath || "/";
|
|
57
|
+
for (const key in env) {
|
|
58
|
+
env[key] = JSON.stringify(env[key]);
|
|
59
|
+
}
|
|
60
|
+
const define = {};
|
|
61
|
+
if (userConfig.define) {
|
|
62
|
+
for (const key in userConfig.define) {
|
|
63
|
+
define[key] = JSON.stringify(userConfig.define[key]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
"process.env": env,
|
|
68
|
+
"process.env.SSR_MANIFEST": "process.env.SSR_MANIFEST",
|
|
69
|
+
...define
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async function addDefinePlugin(opts) {
|
|
73
|
+
const { config } = opts;
|
|
74
|
+
config.plugin("define").use(import_webpack.DefinePlugin, [resolveDefine(opts)]);
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
addDefinePlugin,
|
|
79
|
+
resolveDefine
|
|
80
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
+
import { IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
userConfig: IConfig;
|
|
5
|
+
config: Config;
|
|
6
|
+
cwd: string;
|
|
7
|
+
extraBabelIncludes: Array<string | RegExp>;
|
|
8
|
+
}
|
|
9
|
+
export declare function addDependenceCssModulesDetector(opts: IOpts): Promise<void>;
|
|
10
|
+
export {};
|