@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.
Files changed (101) hide show
  1. package/dist/build.d.ts +22 -0
  2. package/dist/build.js +151 -0
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/cli.js +96 -0
  5. package/dist/config/_sampleFeature.d.ts +10 -0
  6. package/dist/config/_sampleFeature.js +35 -0
  7. package/dist/config/assetRules.d.ts +11 -0
  8. package/dist/config/assetRules.js +48 -0
  9. package/dist/config/bundleAnalyzerPlugin.d.ts +10 -0
  10. package/dist/config/bundleAnalyzerPlugin.js +43 -0
  11. package/dist/config/compressPlugin.d.ts +10 -0
  12. package/dist/config/compressPlugin.js +128 -0
  13. package/dist/config/config.d.ts +31 -0
  14. package/dist/config/config.js +243 -0
  15. package/dist/config/copyPlugin.d.ts +10 -0
  16. package/dist/config/copyPlugin.js +63 -0
  17. package/dist/config/cssRules.d.ts +11 -0
  18. package/dist/config/cssRules.js +165 -0
  19. package/dist/config/definePlugin.d.ts +15 -0
  20. package/dist/config/definePlugin.js +79 -0
  21. package/dist/config/detectCssModulesInDependence.d.ts +10 -0
  22. package/dist/config/detectCssModulesInDependence.js +151 -0
  23. package/dist/config/detectDeadCode.d.ts +12 -0
  24. package/dist/config/detectDeadCode.js +191 -0
  25. package/dist/config/detectDeadCodePlugin.d.ts +9 -0
  26. package/dist/config/detectDeadCodePlugin.js +82 -0
  27. package/dist/config/fastRefreshPlugin.d.ts +12 -0
  28. package/dist/config/fastRefreshPlugin.js +49 -0
  29. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  30. package/dist/config/forkTSCheckerPlugin.js +49 -0
  31. package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
  32. package/dist/config/harmonyLinkingErrorPlugin.js +53 -0
  33. package/dist/config/ignorePlugin.d.ts +10 -0
  34. package/dist/config/ignorePlugin.js +40 -0
  35. package/dist/config/javaScriptRules.d.ts +16 -0
  36. package/dist/config/javaScriptRules.js +191 -0
  37. package/dist/config/manifestPlugin.d.ts +11 -0
  38. package/dist/config/manifestPlugin.js +40 -0
  39. package/dist/config/miniCSSExtractPlugin.d.ts +11 -0
  40. package/dist/config/miniCSSExtractPlugin.js +55 -0
  41. package/dist/config/nodePolyfill.d.ts +10 -0
  42. package/dist/config/nodePolyfill.js +51 -0
  43. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  44. package/dist/config/nodePrefixPlugin.js +38 -0
  45. package/dist/config/progressPlugin.d.ts +11 -0
  46. package/dist/config/progressPlugin.js +53 -0
  47. package/dist/config/purgecssWebpackPlugin.d.ts +10 -0
  48. package/dist/config/purgecssWebpackPlugin.js +43 -0
  49. package/dist/config/speedMeasureWebpackPlugin.d.ts +6 -0
  50. package/dist/config/speedMeasureWebpackPlugin.js +59 -0
  51. package/dist/config/ssrPlugin.d.ts +11 -0
  52. package/dist/config/ssrPlugin.js +98 -0
  53. package/dist/config/svgRules.d.ts +12 -0
  54. package/dist/config/svgRules.js +70 -0
  55. package/dist/constants.d.ts +15 -0
  56. package/dist/constants.js +59 -0
  57. package/dist/dev.d.ts +40 -0
  58. package/dist/dev.js +208 -0
  59. package/dist/index.d.ts +10 -0
  60. package/dist/index.js +32 -0
  61. package/dist/loader/svgr.d.ts +4 -0
  62. package/dist/loader/svgr.js +84 -0
  63. package/dist/loader/swc.d.ts +4 -0
  64. package/dist/loader/swc.js +149 -0
  65. package/dist/parcelCSS.d.ts +2 -0
  66. package/dist/parcelCSS.js +39 -0
  67. package/dist/plugins/EsbuildMinifyFix.d.ts +8 -0
  68. package/dist/plugins/EsbuildMinifyFix.js +136 -0
  69. package/dist/plugins/ProgressPlugin.d.ts +15 -0
  70. package/dist/plugins/ProgressPlugin.js +69 -0
  71. package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
  72. package/dist/plugins/RuntimePublicPathPlugin.js +45 -0
  73. package/dist/plugins/_SamplePlugin.d.ts +9 -0
  74. package/dist/plugins/_SamplePlugin.js +37 -0
  75. package/dist/requireHook.d.ts +1 -0
  76. package/dist/requireHook.js +49 -0
  77. package/dist/schema.d.ts +4 -0
  78. package/dist/schema.js +178 -0
  79. package/dist/server/server.d.ts +17 -0
  80. package/dist/server/server.js +223 -0
  81. package/dist/server/ws.d.ts +13 -0
  82. package/dist/server/ws.js +76 -0
  83. package/dist/swcPlugins/autoCSSModules.d.ts +17 -0
  84. package/dist/swcPlugins/autoCSSModules.js +63 -0
  85. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  86. package/dist/swcPlugins/changeImportFromString.js +32 -0
  87. package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
  88. package/dist/swcPlugins/lockCoreJS.js +56 -0
  89. package/dist/types.d.ts +144 -0
  90. package/dist/types.js +61 -0
  91. package/dist/utils/browsersList.d.ts +5 -0
  92. package/dist/utils/browsersList.js +33 -0
  93. package/dist/utils/depMatch.d.ts +6 -0
  94. package/dist/utils/depMatch.js +72 -0
  95. package/dist/utils/formatWebpackMessages.d.ts +12 -0
  96. package/dist/utils/formatWebpackMessages.js +128 -0
  97. package/dist/utils/getEsBuildTarget.d.ts +7 -0
  98. package/dist/utils/getEsBuildTarget.js +46 -0
  99. package/dist/utils/pkgUpContainsName.d.ts +1 -0
  100. package/dist/utils/pkgUpContainsName.js +50 -0
  101. package/package.json +5 -5
@@ -0,0 +1,11 @@
1
+ import Config from '../../compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ name?: string;
5
+ config: Config;
6
+ userConfig: IConfig;
7
+ cwd: string;
8
+ env: Env;
9
+ }
10
+ export default function addSSRPlugin(opts: IOpts): void;
11
+ export {};
@@ -0,0 +1,98 @@
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/ssrPlugin.ts
20
+ var ssrPlugin_exports = {};
21
+ __export(ssrPlugin_exports, {
22
+ default: () => addSSRPlugin
23
+ });
24
+ module.exports = __toCommonJS(ssrPlugin_exports);
25
+ var import_webpack = require("@umijs/bundler-webpack/compiled/webpack");
26
+ var import_utils = require("@umijs/utils");
27
+ var import_fs = require("fs");
28
+ var import_path = require("path");
29
+ var import_constants = require("../constants");
30
+ var PLUGIN_NAME = "SSR_PLUGIN";
31
+ var SSRPlugin = class {
32
+ constructor(opts) {
33
+ this.opts = opts;
34
+ this.manifest = /* @__PURE__ */ new Map();
35
+ }
36
+ apply(compiler) {
37
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
38
+ compilation.hooks.processAssets.tap(PLUGIN_NAME, () => {
39
+ const publicPath = compiler.options.output.publicPath || "/";
40
+ const assets = compilation.getAssets().filter((asset) => {
41
+ if (asset.info.hotModuleReplacement) {
42
+ return false;
43
+ }
44
+ return true;
45
+ });
46
+ assets.forEach((asset) => {
47
+ if (asset.info.sourceFilename) {
48
+ this.manifest.set(
49
+ asset.info.sourceFilename,
50
+ publicPath + asset.name
51
+ );
52
+ }
53
+ });
54
+ const stats = compilation.getStats().toJson({
55
+ all: false,
56
+ assets: true,
57
+ cachedAssets: true,
58
+ cachedModules: true
59
+ });
60
+ const { assetsByChunkName } = stats;
61
+ Object.keys(assetsByChunkName).forEach((chunkName) => {
62
+ assetsByChunkName[chunkName].forEach((filename) => {
63
+ const ext = (0, import_path.extname)(filename.split(/[?#]/)[0]);
64
+ if (!filename.includes(".hot-update.")) {
65
+ this.manifest.set(chunkName + ext, publicPath + filename);
66
+ }
67
+ });
68
+ });
69
+ const assetsSource = JSON.stringify(
70
+ {
71
+ assets: Object.fromEntries(this.manifest)
72
+ },
73
+ null,
74
+ 2
75
+ );
76
+ if (process.env.NODE_ENV === "production" || this.opts.userConfig.writeToDisk) {
77
+ compilation.emitAsset(
78
+ "build-manifest.json",
79
+ new import_webpack.sources.RawSource(assetsSource, false)
80
+ );
81
+ } else {
82
+ const outputPath = compiler.options.output.path;
83
+ import_utils.fsExtra.mkdirpSync(outputPath);
84
+ (0, import_fs.writeFileSync)(
85
+ (0, import_path.join)(outputPath, "build-manifest.json"),
86
+ assetsSource,
87
+ "utf-8"
88
+ );
89
+ }
90
+ });
91
+ });
92
+ }
93
+ };
94
+ function addSSRPlugin(opts) {
95
+ if (opts.userConfig.ssr && opts.name !== import_constants.MFSU_NAME) {
96
+ opts.config.plugin("ssr-plugin").use(SSRPlugin, [opts]);
97
+ }
98
+ }
@@ -0,0 +1,12 @@
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
+ staticPathPrefix: string;
10
+ }
11
+ export declare function addSVGRules(opts: IOpts): Promise<void>;
12
+ export {};
@@ -0,0 +1,70 @@
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/svgRules.ts
30
+ var svgRules_exports = {};
31
+ __export(svgRules_exports, {
32
+ addSVGRules: () => addSVGRules
33
+ });
34
+ module.exports = __toCommonJS(svgRules_exports);
35
+ async function addSVGRules(opts) {
36
+ const { config, userConfig } = opts;
37
+ const { svgr, svgo = {} } = userConfig;
38
+ if (svgr) {
39
+ const svgrRule = config.module.rule("svgr");
40
+ svgrRule.test(/\.svg$/).issuer(/\.[jt]sx?$/).type("javascript/auto").use("svgr-loader").loader(require.resolve("../loader/svgr")).options({
41
+ svgoConfig: {
42
+ plugins: [
43
+ {
44
+ name: "preset-default",
45
+ params: {
46
+ overrides: {
47
+ removeTitle: false
48
+ }
49
+ }
50
+ },
51
+ "prefixIds"
52
+ ],
53
+ ...svgo
54
+ },
55
+ ...svgr,
56
+ svgo: !!svgo
57
+ }).end().use("url-loader").loader(require.resolve("@umijs/bundler-webpack/compiled/url-loader")).options({
58
+ limit: userConfig.inlineLimit,
59
+ fallback: require.resolve("@umijs/bundler-webpack/compiled/file-loader")
60
+ }).end();
61
+ }
62
+ if (svgo !== false) {
63
+ const svgRule = config.module.rule("svg");
64
+ svgRule.test(/\.svg$/).use("svgo-loader").loader(require.resolve("@umijs/bundler-webpack/compiled/svgo-loader")).options({ configFile: false, ...svgo }).end();
65
+ }
66
+ }
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ addSVGRules
70
+ });
@@ -0,0 +1,15 @@
1
+ export declare const DEFAULT_DEVTOOL = "cheap-module-source-map";
2
+ export declare const DEFAULT_OUTPUT_PATH = "dist";
3
+ export declare const MFSU_NAME = "MFSU";
4
+ export declare enum MESSAGE_TYPE {
5
+ ok = "ok",
6
+ warnings = "warnings",
7
+ errors = "errors",
8
+ hash = "hash",
9
+ stillOk = "still-ok",
10
+ invalid = "invalid"
11
+ }
12
+ export declare const DEFAULT_BROWSER_TARGETS: {
13
+ chrome: number;
14
+ };
15
+ export declare const DEFAULT_ESBUILD_TARGET_KEYS: string[];
@@ -0,0 +1,59 @@
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/constants.ts
20
+ var constants_exports = {};
21
+ __export(constants_exports, {
22
+ DEFAULT_BROWSER_TARGETS: () => DEFAULT_BROWSER_TARGETS,
23
+ DEFAULT_DEVTOOL: () => DEFAULT_DEVTOOL,
24
+ DEFAULT_ESBUILD_TARGET_KEYS: () => DEFAULT_ESBUILD_TARGET_KEYS,
25
+ DEFAULT_OUTPUT_PATH: () => DEFAULT_OUTPUT_PATH,
26
+ MESSAGE_TYPE: () => MESSAGE_TYPE,
27
+ MFSU_NAME: () => MFSU_NAME
28
+ });
29
+ module.exports = __toCommonJS(constants_exports);
30
+ var DEFAULT_DEVTOOL = "cheap-module-source-map";
31
+ var DEFAULT_OUTPUT_PATH = "dist";
32
+ var MFSU_NAME = "MFSU";
33
+ var MESSAGE_TYPE = /* @__PURE__ */ ((MESSAGE_TYPE2) => {
34
+ MESSAGE_TYPE2["ok"] = "ok";
35
+ MESSAGE_TYPE2["warnings"] = "warnings";
36
+ MESSAGE_TYPE2["errors"] = "errors";
37
+ MESSAGE_TYPE2["hash"] = "hash";
38
+ MESSAGE_TYPE2["stillOk"] = "still-ok";
39
+ MESSAGE_TYPE2["invalid"] = "invalid";
40
+ return MESSAGE_TYPE2;
41
+ })(MESSAGE_TYPE || {});
42
+ var DEFAULT_BROWSER_TARGETS = {
43
+ chrome: 80
44
+ };
45
+ var DEFAULT_ESBUILD_TARGET_KEYS = [
46
+ "chrome",
47
+ "firefox",
48
+ "edge",
49
+ "safari"
50
+ ];
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ DEFAULT_BROWSER_TARGETS,
54
+ DEFAULT_DEVTOOL,
55
+ DEFAULT_ESBUILD_TARGET_KEYS,
56
+ DEFAULT_OUTPUT_PATH,
57
+ MESSAGE_TYPE,
58
+ MFSU_NAME
59
+ });
package/dist/dev.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ /// <reference types="node" />
2
+ import { MFSU } from '@umijs/mfsu';
3
+ import type { Worker } from 'worker_threads';
4
+ import webpack from '../compiled/webpack';
5
+ import type { IOpts as IConfigOpts } from './config/config';
6
+ import { IConfig } from './types';
7
+ declare type IOpts = {
8
+ afterMiddlewares?: any[];
9
+ beforeMiddlewares?: any[];
10
+ onDevCompileDone?: Function;
11
+ onProgress?: Function;
12
+ onMFSUProgress?: Function;
13
+ port?: number;
14
+ host?: string;
15
+ ip?: string;
16
+ babelPreset?: any;
17
+ chainWebpack?: Function;
18
+ modifyWebpackConfig?: Function;
19
+ beforeBabelPlugins?: any[];
20
+ beforeBabelPresets?: any[];
21
+ extraBabelPlugins?: any[];
22
+ extraBabelPresets?: any[];
23
+ cwd: string;
24
+ rootDir?: string;
25
+ config: IConfig;
26
+ entry: Record<string, string>;
27
+ mfsuStrategy?: 'eager' | 'normal';
28
+ mfsuInclude?: string[];
29
+ srcCodeCache?: any;
30
+ startBuildWorker?: (deps: any[]) => Worker;
31
+ onBeforeMiddleware?: Function;
32
+ disableCopy?: boolean;
33
+ } & Pick<IConfigOpts, 'cache' | 'pkg'>;
34
+ export declare function ensureSerializableValue(obj: any): any;
35
+ export declare function dev(opts: IOpts): Promise<void>;
36
+ export declare function setup(opts: IOpts): Promise<{
37
+ mfsu: MFSU | null;
38
+ webpackConfig: webpack.Configuration;
39
+ }>;
40
+ export {};
package/dist/dev.js ADDED
@@ -0,0 +1,208 @@
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/dev.ts
30
+ var dev_exports = {};
31
+ __export(dev_exports, {
32
+ dev: () => dev,
33
+ ensureSerializableValue: () => ensureSerializableValue,
34
+ setup: () => setup
35
+ });
36
+ module.exports = __toCommonJS(dev_exports);
37
+ var import_mfsu = require("@umijs/mfsu");
38
+ var import_utils = require("@umijs/utils");
39
+ var import_fs = require("fs");
40
+ var import_path = require("path");
41
+ var import_webpack = __toESM(require("../compiled/webpack"));
42
+ var import_constants = require("./constants");
43
+ var import_server = require("./server/server");
44
+ var import_types = require("./types");
45
+ var configModule = (0, import_utils.importLazy)(
46
+ require.resolve("./config/config")
47
+ );
48
+ function ensureSerializableValue(obj) {
49
+ return JSON.parse(
50
+ JSON.stringify(
51
+ obj,
52
+ (_key, value) => {
53
+ if (typeof value === "function" || import_utils.lodash.isRegExp(value)) {
54
+ return value.toString();
55
+ }
56
+ return value;
57
+ },
58
+ 2
59
+ )
60
+ );
61
+ }
62
+ async function dev(opts) {
63
+ const { mfsu, webpackConfig } = await setup(opts);
64
+ await (0, import_server.createServer)({
65
+ webpackConfig,
66
+ userConfig: opts.config,
67
+ cwd: opts.cwd,
68
+ beforeMiddlewares: [
69
+ ...(mfsu == null ? void 0 : mfsu.getMiddlewares()) || [],
70
+ ...opts.beforeMiddlewares || []
71
+ ],
72
+ port: opts.port,
73
+ host: opts.host,
74
+ ip: opts.ip,
75
+ afterMiddlewares: [...opts.afterMiddlewares || []],
76
+ onDevCompileDone: opts.onDevCompileDone,
77
+ onProgress: opts.onProgress,
78
+ onBeforeMiddleware: opts.onBeforeMiddleware
79
+ });
80
+ }
81
+ async function setup(opts) {
82
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
83
+ const cacheDirectoryPath = (0, import_path.resolve)(
84
+ opts.rootDir || opts.cwd,
85
+ opts.config.cacheDirectoryPath || "node_modules/.cache"
86
+ );
87
+ const enableMFSU = opts.config.mfsu !== false;
88
+ let mfsu = null;
89
+ if (enableMFSU) {
90
+ mfsu = new import_mfsu.MFSU({
91
+ strategy: opts.mfsuStrategy,
92
+ include: opts.mfsuInclude || [],
93
+ srcCodeCache: opts.srcCodeCache,
94
+ implementor: import_webpack.default,
95
+ buildDepWithESBuild: (_a = opts.config.mfsu) == null ? void 0 : _a.esbuild,
96
+ depBuildConfig: {
97
+ extraPostCSSPlugins: ((_b = opts.config) == null ? void 0 : _b.extraPostCSSPlugins) || []
98
+ },
99
+ mfName: (_c = opts.config.mfsu) == null ? void 0 : _c.mfName,
100
+ runtimePublicPath: opts.config.runtimePublicPath,
101
+ tmpBase: ((_d = opts.config.mfsu) == null ? void 0 : _d.cacheDirectory) || (0, import_path.join)(cacheDirectoryPath, "mfsu"),
102
+ onMFSUProgress: opts.onMFSUProgress,
103
+ unMatchLibs: (_e = opts.config.mfsu) == null ? void 0 : _e.exclude,
104
+ shared: (_f = opts.config.mfsu) == null ? void 0 : _f.shared,
105
+ remoteAliases: (_g = opts.config.mfsu) == null ? void 0 : _g.remoteAliases,
106
+ remoteName: (_h = opts.config.mfsu) == null ? void 0 : _h.remoteName,
107
+ getCacheDependency() {
108
+ return ensureSerializableValue({
109
+ version: require("../package.json").version,
110
+ mfsu: opts.config.mfsu,
111
+ alias: opts.config.alias,
112
+ externals: opts.config.externals,
113
+ theme: opts.config.theme,
114
+ runtimePublicPath: opts.config.runtimePublicPath,
115
+ publicPath: opts.config.publicPath,
116
+ define: opts.config.define
117
+ });
118
+ },
119
+ startBuildWorker: opts.startBuildWorker,
120
+ cwd: opts.cwd
121
+ });
122
+ }
123
+ const webpackConfig = await configModule.getConfig({
124
+ cwd: opts.cwd,
125
+ rootDir: opts.rootDir,
126
+ env: import_types.Env.development,
127
+ entry: opts.entry,
128
+ userConfig: opts.config,
129
+ babelPreset: opts.babelPreset,
130
+ extraBabelPlugins: [
131
+ ...opts.beforeBabelPlugins || [],
132
+ ...(mfsu == null ? void 0 : mfsu.getBabelPlugins()) || [],
133
+ ...opts.extraBabelPlugins || []
134
+ ],
135
+ extraBabelPresets: [
136
+ ...opts.beforeBabelPresets || [],
137
+ ...opts.extraBabelPresets || []
138
+ ],
139
+ extraBabelIncludes: opts.config.extraBabelIncludes,
140
+ extraEsbuildLoaderHandler: (mfsu == null ? void 0 : mfsu.getEsbuildLoaderHandler()) || [],
141
+ chainWebpack: opts.chainWebpack,
142
+ modifyWebpackConfig: opts.modifyWebpackConfig,
143
+ hmr: process.env.HMR !== "none",
144
+ analyze: process.env.ANALYZE,
145
+ cache: opts.cache ? {
146
+ ...opts.cache,
147
+ cacheDirectory: (0, import_path.join)(
148
+ cacheDirectoryPath,
149
+ opts.mfsuStrategy === "eager" ? "bundler-webpack-eager" : "bundler-webpack"
150
+ )
151
+ } : void 0,
152
+ pkg: opts.pkg,
153
+ disableCopy: opts.disableCopy,
154
+ port: opts.port,
155
+ host: opts.host
156
+ });
157
+ const depConfig = await configModule.getConfig({
158
+ cwd: opts.cwd,
159
+ rootDir: opts.rootDir,
160
+ env: import_types.Env.development,
161
+ entry: opts.entry,
162
+ userConfig: { ...opts.config, forkTSChecker: false },
163
+ disableCopy: true,
164
+ hash: true,
165
+ staticPathPrefix: import_mfsu.MF_DEP_PREFIX,
166
+ name: import_constants.MFSU_NAME,
167
+ chainWebpack: (_i = opts.config.mfsu) == null ? void 0 : _i.chainWebpack,
168
+ extraBabelIncludes: opts.config.extraBabelIncludes,
169
+ cache: {
170
+ buildDependencies: (_j = opts.cache) == null ? void 0 : _j.buildDependencies,
171
+ cacheDirectory: (0, import_path.join)(cacheDirectoryPath, "mfsu-deps")
172
+ },
173
+ pkg: opts.pkg,
174
+ port: opts.port,
175
+ host: opts.host
176
+ });
177
+ (_k = webpackConfig.resolve).alias || (_k.alias = {});
178
+ ["@umijs/utils/compiled/strip-ansi", "react-error-overlay"].forEach((dep) => {
179
+ webpackConfig.resolve.alias[dep] = require.resolve(dep);
180
+ });
181
+ await (mfsu == null ? void 0 : mfsu.setWebpackConfig({
182
+ config: webpackConfig,
183
+ depConfig
184
+ }));
185
+ if (mfsu && webpackConfig.cache && typeof webpackConfig.cache === "object" && webpackConfig.cache.type === "filesystem") {
186
+ const webpackCachePath = (0, import_path.join)(
187
+ webpackConfig.cache.cacheDirectory,
188
+ `default-development`,
189
+ "index.pack"
190
+ );
191
+ const mfsuCacheExists = (0, import_fs.existsSync)(mfsu.getCacheFilePath());
192
+ const webpackCacheExists = (0, import_fs.existsSync)(webpackCachePath);
193
+ if (webpackCacheExists && !mfsuCacheExists) {
194
+ import_utils.logger.warn(`Invalidate webpack cache since mfsu cache is missing`);
195
+ import_utils.rimraf.sync(webpackConfig.cache.cacheDirectory);
196
+ }
197
+ }
198
+ return {
199
+ mfsu,
200
+ webpackConfig
201
+ };
202
+ }
203
+ // Annotate the CommonJS export names for ESM import in node:
204
+ 0 && (module.exports = {
205
+ dev,
206
+ ensureSerializableValue,
207
+ setup
208
+ });
@@ -0,0 +1,10 @@
1
+ import type webpack from '../compiled/webpack';
2
+ import './requireHook';
3
+ export type { RequestHandler, Express, } from '@umijs/bundler-utils/compiled/express';
4
+ export type { Compiler, Stats } from '../compiled/webpack';
5
+ export * from './build';
6
+ export * from './config/config';
7
+ export * from './dev';
8
+ export * from './schema';
9
+ export * from './constants';
10
+ export { webpack };
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/index.ts
17
+ var src_exports = {};
18
+ module.exports = __toCommonJS(src_exports);
19
+ var import_requireHook = require("./requireHook");
20
+ __reExport(src_exports, require("./build"), module.exports);
21
+ __reExport(src_exports, require("./config/config"), module.exports);
22
+ __reExport(src_exports, require("./dev"), module.exports);
23
+ __reExport(src_exports, require("./schema"), module.exports);
24
+ __reExport(src_exports, require("./constants"), module.exports);
25
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
27
+ ...require("./build"),
28
+ ...require("./config/config"),
29
+ ...require("./dev"),
30
+ ...require("./schema"),
31
+ ...require("./constants")
32
+ });
@@ -0,0 +1,4 @@
1
+ import { Config } from '@svgr/core';
2
+ import type { LoaderContext } from '../../compiled/webpack';
3
+ declare function svgrLoader(this: LoaderContext<Config>, contents: string): void;
4
+ export default svgrLoader;
@@ -0,0 +1,84 @@
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/loader/svgr.ts
30
+ var svgr_exports = {};
31
+ __export(svgr_exports, {
32
+ default: () => svgr_default
33
+ });
34
+ module.exports = __toCommonJS(svgr_exports);
35
+ var import_core = require("@svgr/core");
36
+ var import_plugin_jsx = __toESM(require("@svgr/plugin-jsx"));
37
+ var import_plugin_svgo = __toESM(require("@svgr/plugin-svgo"));
38
+ var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
39
+ var import_path = require("path");
40
+ var import_util = require("util");
41
+ var tranformSvg = (0, import_util.callbackify)(
42
+ async (contents, options, state) => {
43
+ const jsCode = await (0, import_core.transform)(contents, options, state);
44
+ const result = await (0, import_esbuild.transform)(jsCode, {
45
+ loader: "tsx",
46
+ target: "es2015"
47
+ });
48
+ if (!(result == null ? void 0 : result.code)) {
49
+ throw new Error(`Error while transforming using Esbuild`);
50
+ }
51
+ return result.code;
52
+ }
53
+ );
54
+ function svgrLoader(contents) {
55
+ this.cacheable && this.cacheable();
56
+ const callback = this.async();
57
+ const options = this.getOptions();
58
+ const previousExport = (() => {
59
+ if (contents.startsWith("export "))
60
+ return contents;
61
+ const exportMatches = contents.match(/^module.exports\s*=\s*(.*)/);
62
+ return exportMatches ? `export default ${exportMatches[1]}` : null;
63
+ })();
64
+ const state = {
65
+ caller: {
66
+ name: "svgr-loader",
67
+ previousExport,
68
+ defaultPlugins: [import_plugin_svgo.default, import_plugin_jsx.default]
69
+ },
70
+ filePath: (0, import_path.normalize)(this.resourcePath)
71
+ };
72
+ if (!previousExport) {
73
+ tranformSvg(contents, options, state, callback);
74
+ } else {
75
+ this.fs.readFile(this.resourcePath, (err, result) => {
76
+ if (err) {
77
+ callback(err);
78
+ return;
79
+ }
80
+ tranformSvg(String(result), options, state, callback);
81
+ });
82
+ }
83
+ }
84
+ var svgr_default = svgrLoader;
@@ -0,0 +1,4 @@
1
+ import type { LoaderContext } from '../../compiled/webpack';
2
+ import { type SwcOptions } from '../types';
3
+ declare function swcLoader(this: LoaderContext<SwcOptions>, contents: string, inputSourceMap: string | Record<string, any>): void;
4
+ export default swcLoader;