@umijs/bundler-webpack 4.2.6-alpha.4 → 4.2.6-alpha.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.
Files changed (103) hide show
  1. package/compiled/webpack-5-chain/package.json +1 -1
  2. package/compiled/webpack-5-chain/types/index.d.ts +1 -1
  3. package/package.json +6 -6
  4. package/dist/build.d.ts +0 -22
  5. package/dist/build.js +0 -151
  6. package/dist/cli.d.ts +0 -1
  7. package/dist/cli.js +0 -96
  8. package/dist/config/_sampleFeature.d.ts +0 -10
  9. package/dist/config/_sampleFeature.js +0 -35
  10. package/dist/config/assetRules.d.ts +0 -11
  11. package/dist/config/assetRules.js +0 -48
  12. package/dist/config/bundleAnalyzerPlugin.d.ts +0 -10
  13. package/dist/config/bundleAnalyzerPlugin.js +0 -43
  14. package/dist/config/compressPlugin.d.ts +0 -10
  15. package/dist/config/compressPlugin.js +0 -128
  16. package/dist/config/config.d.ts +0 -29
  17. package/dist/config/config.js +0 -241
  18. package/dist/config/copyPlugin.d.ts +0 -10
  19. package/dist/config/copyPlugin.js +0 -63
  20. package/dist/config/cssRules.d.ts +0 -11
  21. package/dist/config/cssRules.js +0 -165
  22. package/dist/config/definePlugin.d.ts +0 -17
  23. package/dist/config/definePlugin.js +0 -65
  24. package/dist/config/detectCssModulesInDependence.d.ts +0 -10
  25. package/dist/config/detectCssModulesInDependence.js +0 -151
  26. package/dist/config/detectDeadCode.d.ts +0 -12
  27. package/dist/config/detectDeadCode.js +0 -191
  28. package/dist/config/detectDeadCodePlugin.d.ts +0 -9
  29. package/dist/config/detectDeadCodePlugin.js +0 -82
  30. package/dist/config/fastRefreshPlugin.d.ts +0 -12
  31. package/dist/config/fastRefreshPlugin.js +0 -49
  32. package/dist/config/forkTSCheckerPlugin.d.ts +0 -11
  33. package/dist/config/forkTSCheckerPlugin.js +0 -49
  34. package/dist/config/harmonyLinkingErrorPlugin.d.ts +0 -6
  35. package/dist/config/harmonyLinkingErrorPlugin.js +0 -53
  36. package/dist/config/ignorePlugin.d.ts +0 -10
  37. package/dist/config/ignorePlugin.js +0 -40
  38. package/dist/config/javaScriptRules.d.ts +0 -16
  39. package/dist/config/javaScriptRules.js +0 -191
  40. package/dist/config/manifestPlugin.d.ts +0 -11
  41. package/dist/config/manifestPlugin.js +0 -40
  42. package/dist/config/miniCSSExtractPlugin.d.ts +0 -11
  43. package/dist/config/miniCSSExtractPlugin.js +0 -55
  44. package/dist/config/nodePolyfill.d.ts +0 -10
  45. package/dist/config/nodePolyfill.js +0 -51
  46. package/dist/config/nodePrefixPlugin.d.ts +0 -11
  47. package/dist/config/nodePrefixPlugin.js +0 -38
  48. package/dist/config/progressPlugin.d.ts +0 -11
  49. package/dist/config/progressPlugin.js +0 -53
  50. package/dist/config/purgecssWebpackPlugin.d.ts +0 -10
  51. package/dist/config/purgecssWebpackPlugin.js +0 -43
  52. package/dist/config/speedMeasureWebpackPlugin.d.ts +0 -6
  53. package/dist/config/speedMeasureWebpackPlugin.js +0 -59
  54. package/dist/config/ssrPlugin.d.ts +0 -11
  55. package/dist/config/ssrPlugin.js +0 -98
  56. package/dist/config/svgRules.d.ts +0 -12
  57. package/dist/config/svgRules.js +0 -70
  58. package/dist/constants.d.ts +0 -15
  59. package/dist/constants.js +0 -59
  60. package/dist/dev.d.ts +0 -40
  61. package/dist/dev.js +0 -204
  62. package/dist/index.d.ts +0 -10
  63. package/dist/index.js +0 -32
  64. package/dist/loader/svgr.d.ts +0 -4
  65. package/dist/loader/svgr.js +0 -84
  66. package/dist/loader/swc.d.ts +0 -4
  67. package/dist/loader/swc.js +0 -149
  68. package/dist/parcelCSS.d.ts +0 -2
  69. package/dist/parcelCSS.js +0 -39
  70. package/dist/plugins/EsbuildMinifyFix.d.ts +0 -8
  71. package/dist/plugins/EsbuildMinifyFix.js +0 -136
  72. package/dist/plugins/ProgressPlugin.d.ts +0 -15
  73. package/dist/plugins/ProgressPlugin.js +0 -69
  74. package/dist/plugins/RuntimePublicPathPlugin.d.ts +0 -4
  75. package/dist/plugins/RuntimePublicPathPlugin.js +0 -45
  76. package/dist/plugins/_SamplePlugin.d.ts +0 -9
  77. package/dist/plugins/_SamplePlugin.js +0 -37
  78. package/dist/requireHook.d.ts +0 -1
  79. package/dist/requireHook.js +0 -48
  80. package/dist/schema.d.ts +0 -4
  81. package/dist/schema.js +0 -178
  82. package/dist/server/server.d.ts +0 -17
  83. package/dist/server/server.js +0 -223
  84. package/dist/server/ws.d.ts +0 -13
  85. package/dist/server/ws.js +0 -76
  86. package/dist/swcPlugins/autoCSSModules.d.ts +0 -17
  87. package/dist/swcPlugins/autoCSSModules.js +0 -63
  88. package/dist/swcPlugins/changeImportFromString.d.ts +0 -2
  89. package/dist/swcPlugins/changeImportFromString.js +0 -32
  90. package/dist/swcPlugins/lockCoreJS.d.ts +0 -6
  91. package/dist/swcPlugins/lockCoreJS.js +0 -56
  92. package/dist/types.d.ts +0 -144
  93. package/dist/types.js +0 -61
  94. package/dist/utils/browsersList.d.ts +0 -5
  95. package/dist/utils/browsersList.js +0 -33
  96. package/dist/utils/depMatch.d.ts +0 -6
  97. package/dist/utils/depMatch.js +0 -72
  98. package/dist/utils/formatWebpackMessages.d.ts +0 -12
  99. package/dist/utils/formatWebpackMessages.js +0 -128
  100. package/dist/utils/getEsBuildTarget.d.ts +0 -7
  101. package/dist/utils/getEsBuildTarget.js +0 -46
  102. package/dist/utils/pkgUpContainsName.d.ts +0 -1
  103. package/dist/utils/pkgUpContainsName.js +0 -50
@@ -1,241 +0,0 @@
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
- };
89
- config.name(opts.name);
90
- config.mode(opts.env);
91
- config.stats("none");
92
- Object.keys(opts.entry).forEach((key) => {
93
- const entry = config.entry(key);
94
- if (isDev && opts.hmr) {
95
- entry.add(require.resolve("../../client/client/client"));
96
- }
97
- entry.add(opts.entry[key]);
98
- });
99
- config.devtool(
100
- isDev ? userConfig.devtool === false ? false : userConfig.devtool || import_constants.DEFAULT_DEVTOOL : userConfig.devtool
101
- );
102
- const absOutputPath = (0, import_path.resolve)(
103
- opts.cwd,
104
- userConfig.outputPath || import_constants.DEFAULT_OUTPUT_PATH
105
- );
106
- const disableCompress = process.env.COMPRESS === "none";
107
- config.output.path(absOutputPath).filename(useHash ? `[name].[contenthash:8].js` : `[name].js`).chunkFilename(
108
- useHash ? `[name].[contenthash:8].async.js` : `[name].async.js`
109
- ).publicPath(userConfig.publicPath || "auto").pathinfo(isDev || disableCompress).set(
110
- "assetModuleFilename",
111
- `${applyOpts.staticPathPrefix}[name].[hash:8][ext]`
112
- ).set("hashFunction", "xxhash64");
113
- config.resolve.set("symlinks", true).modules.add("node_modules").end().alias.merge(userConfig.alias || {}).end().extensions.merge([
114
- ".ts",
115
- ".tsx",
116
- ".js",
117
- ".jsx",
118
- ".mjs",
119
- ".cjs",
120
- ".json",
121
- ".wasm"
122
- ]).end();
123
- config.externals(userConfig.externals || []);
124
- config.target(["web", "es5"]);
125
- config.experiments({
126
- topLevelAwait: true,
127
- outputModule: !!userConfig.esm
128
- });
129
- await (0, import_nodePolyfill.addNodePolyfill)(applyOpts);
130
- await (0, import_javaScriptRules.addJavaScriptRules)(applyOpts);
131
- await (0, import_cssRules.addCSSRules)(applyOpts);
132
- await (0, import_assetRules.addAssetRules)(applyOpts);
133
- await (0, import_svgRules.addSVGRules)(applyOpts);
134
- await (0, import_miniCSSExtractPlugin.addMiniCSSExtractPlugin)(applyOpts);
135
- await (0, import_ignorePlugin.addIgnorePlugin)(applyOpts);
136
- await (0, import_definePlugin.addDefinePlugin)(applyOpts);
137
- await (0, import_fastRefreshPlugin.addFastRefreshPlugin)(applyOpts);
138
- await (0, import_progressPlugin.addProgressPlugin)(applyOpts);
139
- await (0, import_detectDeadCodePlugin.addDetectDeadCodePlugin)(applyOpts);
140
- await (0, import_forkTSCheckerPlugin.addForkTSCheckerPlugin)(applyOpts);
141
- if (!opts.disableCopy) {
142
- await (0, import_copyPlugin.addCopyPlugin)(applyOpts);
143
- }
144
- await (0, import_manifestPlugin.addManifestPlugin)(applyOpts);
145
- if (isDev && opts.hmr) {
146
- config.plugin("hmr").use(import_webpack.default.HotModuleReplacementPlugin);
147
- }
148
- await (0, import_ssrPlugin.default)(applyOpts);
149
- await (0, import_compressPlugin.addCompressPlugin)(applyOpts);
150
- await (0, import_harmonyLinkingErrorPlugin.addHarmonyLinkingErrorPlugin)(applyOpts);
151
- await (0, import_detectCssModulesInDependence.addDependenceCssModulesDetector)(applyOpts);
152
- if (userConfig.runtimePublicPath) {
153
- config.plugin("runtimePublicPath").use(import_RuntimePublicPathPlugin.RuntimePublicPathPlugin);
154
- }
155
- config.plugin("case-sensitive-paths").use(import_case_sensitive_paths_webpack_plugin.default);
156
- if (opts.cache) {
157
- config.cache({
158
- type: "filesystem",
159
- version: require("../../package.json").version,
160
- buildDependencies: {
161
- config: opts.cache.buildDependencies || []
162
- },
163
- cacheDirectory: opts.cache.cacheDirectory || // 使用 rootDir 是在有 APP_ROOT 时,把 cache 目录放在根目录下
164
- (0, import_path.join)(
165
- opts.rootDir || opts.cwd,
166
- "node_modules",
167
- ".cache",
168
- "bundler-webpack"
169
- )
170
- });
171
- if (require.resolve("@umijs/utils/package").includes("_@umijs_utils@")) {
172
- const nodeModulesPath = opts.cache.absNodeModulesPath || (0, import_path.join)(opts.rootDir || opts.cwd, "node_modules");
173
- const localLinkedNodeModules = Object.keys(
174
- Object.assign(
175
- {},
176
- (_a = opts.pkg) == null ? void 0 : _a.dependencies,
177
- (_b = opts.pkg) == null ? void 0 : _b.peerDependencies,
178
- (_c = opts.pkg) == null ? void 0 : _c.devDependencies
179
- )
180
- ).map((pkg) => {
181
- try {
182
- return (0, import_path.resolve)(
183
- import_utils.resolve.sync(`${pkg}/package.json`, {
184
- basedir: opts.rootDir || opts.cwd,
185
- preserveSymlinks: false
186
- }),
187
- "../node_modules"
188
- );
189
- } catch {
190
- return opts.rootDir || opts.cwd;
191
- }
192
- }).filter((pkg) => !pkg.startsWith(opts.rootDir || opts.cwd));
193
- if (localLinkedNodeModules.length) {
194
- import_utils.logger.info(
195
- `Detected local linked tnpm node_modules, to avoid oom, they will be treated as immutablePaths & managedPaths in webpack snapshot:`
196
- );
197
- localLinkedNodeModules.forEach((p) => import_utils.logger.info(` ${p}`));
198
- }
199
- config.snapshot({
200
- immutablePaths: [nodeModulesPath, ...localLinkedNodeModules],
201
- managedPaths: [nodeModulesPath, ...localLinkedNodeModules]
202
- });
203
- }
204
- config.infrastructureLogging({
205
- level: "error",
206
- ...process.env.WEBPACK_FS_CACHE_DEBUG ? {
207
- debug: /webpack\.cache/
208
- } : {}
209
- });
210
- }
211
- if (opts.analyze) {
212
- await (0, import_bundleAnalyzerPlugin.addBundleAnalyzerPlugin)(applyOpts);
213
- }
214
- if (opts.chainWebpack) {
215
- await opts.chainWebpack(config, {
216
- env: opts.env,
217
- webpack: import_webpack.default
218
- });
219
- }
220
- if (userConfig.chainWebpack) {
221
- await userConfig.chainWebpack(config, {
222
- env: opts.env,
223
- webpack: import_webpack.default
224
- });
225
- }
226
- let webpackConfig = config.toConfig();
227
- webpackConfig = await (0, import_speedMeasureWebpackPlugin.addSpeedMeasureWebpackPlugin)({
228
- webpackConfig
229
- });
230
- if (opts.modifyWebpackConfig) {
231
- webpackConfig = await opts.modifyWebpackConfig(webpackConfig, {
232
- env: opts.env,
233
- webpack: import_webpack.default
234
- });
235
- }
236
- return webpackConfig;
237
- }
238
- // Annotate the CommonJS export names for ESM import in node:
239
- 0 && (module.exports = {
240
- getConfig
241
- });
@@ -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 addCopyPlugin(opts: IOpts): Promise<void>;
10
- export {};
@@ -1,63 +0,0 @@
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
- });
@@ -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
- browsers: any;
9
- }
10
- export declare function addCSSRules(opts: IOpts): Promise<void>;
11
- export {};
@@ -1,165 +0,0 @@
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
- });
@@ -1,17 +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 resolveDefine(opts: {
10
- define: any;
11
- publicPath?: string;
12
- }): {
13
- 'process.env': Record<string, any>;
14
- 'process.env.SSR_MANIFEST': string;
15
- };
16
- export declare function addDefinePlugin(opts: IOpts): Promise<void>;
17
- export {};
@@ -1,65 +0,0 @@
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
- function resolveDefine(opts) {
30
- const env = {};
31
- Object.keys(process.env).forEach((key) => {
32
- if (prefixRE.test(key) || ENV_SHOULD_PASS.includes(key)) {
33
- env[key] = process.env[key];
34
- }
35
- });
36
- env.PUBLIC_PATH = opts.publicPath || "/";
37
- for (const key in env) {
38
- env[key] = JSON.stringify(env[key]);
39
- }
40
- const define = {};
41
- if (opts.define) {
42
- for (const key in opts.define) {
43
- define[key] = JSON.stringify(opts.define[key]);
44
- }
45
- }
46
- return {
47
- "process.env": env,
48
- "process.env.SSR_MANIFEST": "process.env.SSR_MANIFEST",
49
- ...define
50
- };
51
- }
52
- async function addDefinePlugin(opts) {
53
- const { config, userConfig } = opts;
54
- config.plugin("define").use(import_webpack.DefinePlugin, [
55
- resolveDefine({
56
- define: userConfig.define || {},
57
- publicPath: userConfig.publicPath
58
- })
59
- ]);
60
- }
61
- // Annotate the CommonJS export names for ESM import in node:
62
- 0 && (module.exports = {
63
- addDefinePlugin,
64
- resolveDefine
65
- });
@@ -1,10 +0,0 @@
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 {};