@modern-js/builder 3.0.0-alpha.1 → 3.0.0

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 (136) hide show
  1. package/dist/cjs/createBuilder.js +96 -0
  2. package/dist/cjs/index.js +59 -0
  3. package/dist/cjs/plugins/devtools.js +47 -0
  4. package/dist/cjs/plugins/emitRouteFile.js +75 -0
  5. package/dist/cjs/plugins/environmentDefaults.js +100 -0
  6. package/dist/cjs/plugins/globalVars.js +55 -0
  7. package/dist/cjs/plugins/htmlMinify.js +115 -0
  8. package/dist/cjs/plugins/manifest.js +52 -0
  9. package/dist/cjs/plugins/postcss.js +118 -0
  10. package/dist/cjs/plugins/runtimeChunk.js +54 -0
  11. package/dist/cjs/rsc/common.js +157 -0
  12. package/dist/cjs/rsc/plugins/rsbuild-rsc-plugin.js +169 -0
  13. package/dist/cjs/rsc/plugins/rspack-rsc-client-plugin.js +187 -0
  14. package/dist/cjs/rsc/plugins/rspack-rsc-server-plugin.js +245 -0
  15. package/dist/cjs/rsc/rsc-client-loader.js +71 -0
  16. package/dist/cjs/rsc/rsc-css-loader.js +42 -0
  17. package/dist/cjs/rsc/rsc-server-loader.js +102 -0
  18. package/dist/cjs/rsc/rsc-ssr-loader.js +60 -0
  19. package/dist/cjs/shared/devServer.js +87 -0
  20. package/dist/cjs/shared/getCssSupport.js +121 -0
  21. package/dist/cjs/shared/manifest.js +46 -0
  22. package/dist/cjs/shared/parseCommonConfig.js +209 -0
  23. package/dist/cjs/shared/rsc/rscClientBrowserFallback.js +64 -0
  24. package/dist/cjs/shared/rsc/rscEmptyModule.js +36 -0
  25. package/dist/cjs/shared/utils.js +115 -0
  26. package/dist/cjs/types.js +18 -0
  27. package/dist/compiled/postcss-load-config/index.d.ts +1 -0
  28. package/dist/compiled/postcss-load-config/index.js +608 -0
  29. package/dist/compiled/postcss-load-config/index.js.LICENSE.txt +13 -0
  30. package/dist/compiled/postcss-load-config/license +20 -0
  31. package/dist/compiled/postcss-load-config/package.json +1 -0
  32. package/dist/esm/createBuilder.mjs +59 -0
  33. package/dist/esm/index.mjs +4 -0
  34. package/dist/esm/plugins/devtools.mjs +13 -0
  35. package/dist/esm/plugins/emitRouteFile.mjs +28 -0
  36. package/dist/esm/plugins/environmentDefaults.mjs +66 -0
  37. package/dist/esm/plugins/globalVars.mjs +21 -0
  38. package/dist/esm/plugins/htmlMinify.mjs +81 -0
  39. package/dist/esm/plugins/manifest.mjs +18 -0
  40. package/dist/esm/plugins/postcss.mjs +81 -0
  41. package/dist/esm/plugins/runtimeChunk.mjs +20 -0
  42. package/dist/esm/rsc/common.mjs +87 -0
  43. package/dist/esm/rsc/plugins/rsbuild-rsc-plugin.mjs +124 -0
  44. package/dist/esm/rsc/plugins/rspack-rsc-client-plugin.mjs +143 -0
  45. package/dist/esm/rsc/plugins/rspack-rsc-server-plugin.mjs +211 -0
  46. package/dist/esm/rsc/rsc-client-loader.mjs +37 -0
  47. package/dist/esm/rsc/rsc-css-loader.mjs +8 -0
  48. package/dist/esm/rsc/rsc-server-loader.mjs +58 -0
  49. package/dist/esm/rsc/rsc-ssr-loader.mjs +26 -0
  50. package/dist/esm/shared/devServer.mjs +53 -0
  51. package/dist/esm/shared/getCssSupport.mjs +77 -0
  52. package/dist/esm/shared/manifest.mjs +12 -0
  53. package/dist/esm/shared/parseCommonConfig.mjs +172 -0
  54. package/dist/esm/shared/rsc/rscClientBrowserFallback.mjs +20 -0
  55. package/dist/esm/shared/rsc/rscEmptyModule.mjs +2 -0
  56. package/dist/esm/shared/utils.mjs +53 -0
  57. package/dist/esm/types.mjs +0 -0
  58. package/dist/esm-node/createBuilder.mjs +60 -0
  59. package/dist/esm-node/index.mjs +5 -0
  60. package/dist/esm-node/plugins/devtools.mjs +14 -0
  61. package/dist/esm-node/plugins/emitRouteFile.mjs +29 -0
  62. package/dist/esm-node/plugins/environmentDefaults.mjs +67 -0
  63. package/dist/esm-node/plugins/globalVars.mjs +22 -0
  64. package/dist/esm-node/plugins/htmlMinify.mjs +82 -0
  65. package/dist/esm-node/plugins/manifest.mjs +19 -0
  66. package/dist/esm-node/plugins/postcss.mjs +82 -0
  67. package/dist/esm-node/plugins/runtimeChunk.mjs +21 -0
  68. package/dist/esm-node/rsc/common.mjs +88 -0
  69. package/dist/esm-node/rsc/plugins/rsbuild-rsc-plugin.mjs +126 -0
  70. package/dist/esm-node/rsc/plugins/rspack-rsc-client-plugin.mjs +144 -0
  71. package/dist/esm-node/rsc/plugins/rspack-rsc-server-plugin.mjs +212 -0
  72. package/dist/esm-node/rsc/rsc-client-loader.mjs +38 -0
  73. package/dist/esm-node/rsc/rsc-css-loader.mjs +9 -0
  74. package/dist/esm-node/rsc/rsc-server-loader.mjs +60 -0
  75. package/dist/esm-node/rsc/rsc-ssr-loader.mjs +27 -0
  76. package/dist/esm-node/shared/devServer.mjs +54 -0
  77. package/dist/esm-node/shared/getCssSupport.mjs +78 -0
  78. package/dist/esm-node/shared/manifest.mjs +13 -0
  79. package/dist/esm-node/shared/parseCommonConfig.mjs +173 -0
  80. package/dist/esm-node/shared/rsc/rscClientBrowserFallback.mjs +25 -0
  81. package/dist/esm-node/shared/rsc/rscEmptyModule.mjs +3 -0
  82. package/dist/esm-node/shared/utils.mjs +54 -0
  83. package/dist/esm-node/types.mjs +1 -0
  84. package/dist/types/shared/rsc/rscClientBrowserFallback.d.ts +2 -0
  85. package/dist/types/shared/rsc/rscEmptyModule.d.ts +2 -0
  86. package/dist/{types.d.ts → types/types.d.ts} +2 -16
  87. package/package.json +37 -32
  88. package/dist/createBuilder.js +0 -153
  89. package/dist/index.js +0 -45
  90. package/dist/plugins/babel-post.d.ts +0 -5
  91. package/dist/plugins/babel-post.js +0 -57
  92. package/dist/plugins/devtools.js +0 -42
  93. package/dist/plugins/emitRouteFile.js +0 -70
  94. package/dist/plugins/environmentDefaults.js +0 -99
  95. package/dist/plugins/globalVars.js +0 -50
  96. package/dist/plugins/htmlMinify.js +0 -126
  97. package/dist/plugins/manifest.js +0 -54
  98. package/dist/plugins/postcss.js +0 -133
  99. package/dist/plugins/runtimeChunk.js +0 -55
  100. package/dist/rsc/common.js +0 -174
  101. package/dist/rsc/plugins/rsbuild-rsc-plugin.js +0 -173
  102. package/dist/rsc/plugins/rspack-rsc-client-plugin.js +0 -215
  103. package/dist/rsc/plugins/rspack-rsc-server-plugin.js +0 -290
  104. package/dist/rsc/rsc-client-loader.js +0 -70
  105. package/dist/rsc/rsc-css-loader.js +0 -30
  106. package/dist/rsc/rsc-server-loader.js +0 -95
  107. package/dist/rsc/rsc-ssr-loader.js +0 -58
  108. package/dist/shared/devServer.js +0 -83
  109. package/dist/shared/getCssSupport.js +0 -113
  110. package/dist/shared/manifest.js +0 -38
  111. package/dist/shared/parseCommonConfig.js +0 -232
  112. package/dist/shared/utils.js +0 -109
  113. package/dist/types.js +0 -16
  114. /package/dist/{createBuilder.d.ts → types/createBuilder.d.ts} +0 -0
  115. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  116. /package/dist/{plugins → types/plugins}/devtools.d.ts +0 -0
  117. /package/dist/{plugins → types/plugins}/emitRouteFile.d.ts +0 -0
  118. /package/dist/{plugins → types/plugins}/environmentDefaults.d.ts +0 -0
  119. /package/dist/{plugins → types/plugins}/globalVars.d.ts +0 -0
  120. /package/dist/{plugins → types/plugins}/htmlMinify.d.ts +0 -0
  121. /package/dist/{plugins → types/plugins}/manifest.d.ts +0 -0
  122. /package/dist/{plugins → types/plugins}/postcss.d.ts +0 -0
  123. /package/dist/{plugins → types/plugins}/runtimeChunk.d.ts +0 -0
  124. /package/dist/{rsc → types/rsc}/common.d.ts +0 -0
  125. /package/dist/{rsc → types/rsc}/plugins/rsbuild-rsc-plugin.d.ts +0 -0
  126. /package/dist/{rsc → types/rsc}/plugins/rspack-rsc-client-plugin.d.ts +0 -0
  127. /package/dist/{rsc → types/rsc}/plugins/rspack-rsc-server-plugin.d.ts +0 -0
  128. /package/dist/{rsc → types/rsc}/rsc-client-loader.d.ts +0 -0
  129. /package/dist/{rsc → types/rsc}/rsc-css-loader.d.ts +0 -0
  130. /package/dist/{rsc → types/rsc}/rsc-server-loader.d.ts +0 -0
  131. /package/dist/{rsc → types/rsc}/rsc-ssr-loader.d.ts +0 -0
  132. /package/dist/{shared → types/shared}/devServer.d.ts +0 -0
  133. /package/dist/{shared → types/shared}/getCssSupport.d.ts +0 -0
  134. /package/dist/{shared → types/shared}/manifest.d.ts +0 -0
  135. /package/dist/{shared → types/shared}/parseCommonConfig.d.ts +0 -0
  136. /package/dist/{shared → types/shared}/utils.d.ts +0 -0
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ parseConfig: ()=>parseConfig,
28
+ createRspackBuilder: ()=>createRspackBuilder
29
+ });
30
+ const core_namespaceObject = require("@rsbuild/core");
31
+ const rsbuild_rsc_plugin_js_namespaceObject = require("./rsc/plugins/rsbuild-rsc-plugin.js");
32
+ const parseCommonConfig_js_namespaceObject = require("./shared/parseCommonConfig.js");
33
+ const rscClientBrowserFallback_js_namespaceObject = require("./shared/rsc/rscClientBrowserFallback.js");
34
+ async function parseConfig(builderConfig, options) {
35
+ builderConfig.performance ??= {};
36
+ builderConfig.performance.buildCache ??= true;
37
+ const { rsbuildConfig, rsbuildPlugins } = await (0, parseCommonConfig_js_namespaceObject.parseCommonConfig)(builderConfig, options);
38
+ const { sri } = builderConfig.security || {};
39
+ if (sri) if (true === sri) rsbuildConfig.security.sri = {
40
+ enable: 'auto'
41
+ };
42
+ else {
43
+ const algorithm = Array.isArray(sri.hashFuncNames) ? sri.hashFuncNames[0] : void 0;
44
+ rsbuildConfig.security.sri = {
45
+ enable: sri.enabled,
46
+ algorithm
47
+ };
48
+ }
49
+ if (false === Boolean(rsbuildConfig.tools.lightningcssLoader)) {
50
+ const { pluginPostcss } = await import("./plugins/postcss.js");
51
+ rsbuildPlugins.push(pluginPostcss({
52
+ autoprefixer: builderConfig.tools?.autoprefixer
53
+ }));
54
+ }
55
+ const enableRsc = builderConfig.server?.rsc ?? false;
56
+ if (enableRsc) {
57
+ const { rscClientRuntimePath, rscServerRuntimePath, internalDirectory } = options;
58
+ rsbuildPlugins.push((0, rsbuild_rsc_plugin_js_namespaceObject.rsbuildRscPlugin)({
59
+ appDir: options.cwd,
60
+ rscClientRuntimePath,
61
+ rscServerRuntimePath,
62
+ internalDirectory
63
+ }));
64
+ } else rsbuildPlugins.push((0, rscClientBrowserFallback_js_namespaceObject.rscClientBrowserFallbackPlugin)());
65
+ return {
66
+ rsbuildConfig,
67
+ rsbuildPlugins
68
+ };
69
+ }
70
+ async function createRspackBuilder(options) {
71
+ const { cwd = process.cwd(), config, ...rest } = options;
72
+ const { rsbuildConfig, rsbuildPlugins } = await parseConfig(config, {
73
+ ...rest,
74
+ cwd
75
+ });
76
+ rsbuildConfig.plugins = [
77
+ ...rsbuildPlugins,
78
+ ...rsbuildConfig.plugins || []
79
+ ];
80
+ const rsbuild = await (0, core_namespaceObject.createRsbuild)({
81
+ cwd,
82
+ rsbuildConfig
83
+ });
84
+ return {
85
+ ...rsbuild
86
+ };
87
+ }
88
+ exports.createRspackBuilder = __webpack_exports__.createRspackBuilder;
89
+ exports.parseConfig = __webpack_exports__.parseConfig;
90
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
91
+ "createRspackBuilder",
92
+ "parseConfig"
93
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
94
+ Object.defineProperty(exports, '__esModule', {
95
+ value: true
96
+ });
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ RUNTIME_CHUNK_REGEX: ()=>utils_js_namespaceObject.RUNTIME_CHUNK_REGEX,
28
+ logger: ()=>core_namespaceObject.logger,
29
+ RUNTIME_CHUNK_NAME: ()=>utils_js_namespaceObject.RUNTIME_CHUNK_NAME,
30
+ castArray: ()=>utils_js_namespaceObject.castArray,
31
+ SERVICE_WORKER_ENVIRONMENT_NAME: ()=>utils_js_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME,
32
+ isHtmlDisabled: ()=>utils_js_namespaceObject.isHtmlDisabled,
33
+ createBuilder: ()=>external_createBuilder_js_namespaceObject.createRspackBuilder,
34
+ parseRspackConfig: ()=>external_createBuilder_js_namespaceObject.parseConfig
35
+ });
36
+ const external_createBuilder_js_namespaceObject = require("./createBuilder.js");
37
+ const core_namespaceObject = require("@rsbuild/core");
38
+ const utils_js_namespaceObject = require("./shared/utils.js");
39
+ exports.RUNTIME_CHUNK_NAME = __webpack_exports__.RUNTIME_CHUNK_NAME;
40
+ exports.RUNTIME_CHUNK_REGEX = __webpack_exports__.RUNTIME_CHUNK_REGEX;
41
+ exports.SERVICE_WORKER_ENVIRONMENT_NAME = __webpack_exports__.SERVICE_WORKER_ENVIRONMENT_NAME;
42
+ exports.castArray = __webpack_exports__.castArray;
43
+ exports.createBuilder = __webpack_exports__.createBuilder;
44
+ exports.isHtmlDisabled = __webpack_exports__.isHtmlDisabled;
45
+ exports.logger = __webpack_exports__.logger;
46
+ exports.parseRspackConfig = __webpack_exports__.parseRspackConfig;
47
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
48
+ "RUNTIME_CHUNK_NAME",
49
+ "RUNTIME_CHUNK_REGEX",
50
+ "SERVICE_WORKER_ENVIRONMENT_NAME",
51
+ "castArray",
52
+ "createBuilder",
53
+ "isHtmlDisabled",
54
+ "logger",
55
+ "parseRspackConfig"
56
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
57
+ Object.defineProperty(exports, '__esModule', {
58
+ value: true
59
+ });
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ pluginDevtool: ()=>pluginDevtool
28
+ });
29
+ const pluginDevtool = (options)=>({
30
+ name: 'builder:devtool',
31
+ setup (api) {
32
+ const devtoolJs = 'boolean' == typeof options.sourceMap || options.sourceMap?.js !== void 0;
33
+ if (devtoolJs) return;
34
+ api.modifyBundlerChain((chain, { isProd, isServer })=>{
35
+ const prodDevTool = isServer ? 'source-map' : 'hidden-source-map';
36
+ const devtool = isProd ? prodDevTool : 'cheap-module-source-map';
37
+ chain.devtool(devtool);
38
+ });
39
+ }
40
+ });
41
+ exports.pluginDevtool = __webpack_exports__.pluginDevtool;
42
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
43
+ "pluginDevtool"
44
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
45
+ Object.defineProperty(exports, '__esModule', {
46
+ value: true
47
+ });
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ pluginEmitRouteFile: ()=>pluginEmitRouteFile,
37
+ isFileExists: ()=>isFileExists
38
+ });
39
+ const external_node_fs_namespaceObject = require("node:fs");
40
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
41
+ const external_node_path_namespaceObject = require("node:path");
42
+ async function isFileExists(file) {
43
+ return external_node_fs_default().promises.access(file, external_node_fs_default().constants.F_OK).then(()=>true).catch(()=>false);
44
+ }
45
+ const pluginEmitRouteFile = ()=>({
46
+ name: 'builder:emit-route-file',
47
+ setup (api) {
48
+ api.onBeforeStartDevServer(async ({ environments })=>{
49
+ const { fs, ROUTE_SPEC_FILE } = await import("@modern-js/utils");
50
+ const routeFilePath = (0, external_node_path_namespaceObject.join)(api.context.distPath, ROUTE_SPEC_FILE);
51
+ const htmlPaths = Object.values(environments).reduce((prev, curr)=>({
52
+ ...prev,
53
+ ...curr.htmlPaths
54
+ }), {});
55
+ const routesInfo = Object.entries(htmlPaths).map(([entryName, filename], index)=>({
56
+ urlPath: 0 === index ? '/' : `/${entryName}`,
57
+ entryName,
58
+ entryPath: filename,
59
+ isSPA: true
60
+ }));
61
+ if (!await isFileExists(routeFilePath) && routesInfo.length) await fs.outputFile(routeFilePath, JSON.stringify({
62
+ routes: routesInfo
63
+ }, null, 2));
64
+ });
65
+ }
66
+ });
67
+ exports.isFileExists = __webpack_exports__.isFileExists;
68
+ exports.pluginEmitRouteFile = __webpack_exports__.pluginEmitRouteFile;
69
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
70
+ "isFileExists",
71
+ "pluginEmitRouteFile"
72
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
73
+ Object.defineProperty(exports, '__esModule', {
74
+ value: true
75
+ });
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ pluginEnvironmentDefaults: ()=>pluginEnvironmentDefaults
28
+ });
29
+ const external_node_path_namespaceObject = require("node:path");
30
+ const utils_js_namespaceObject = require("../shared/utils.js");
31
+ const pluginEnvironmentDefaults = (distPath = {})=>({
32
+ name: 'builder:environment-defaults-plugin',
33
+ setup (api) {
34
+ api.modifyRsbuildConfig((config, { mergeRsbuildConfig })=>{
35
+ const compatConfig = {};
36
+ if (config.environments?.[utils_js_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME]) {
37
+ compatConfig.environments ??= {};
38
+ compatConfig.environments[utils_js_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME] = {
39
+ output: {
40
+ polyfill: 'off',
41
+ distPath: {
42
+ root: (0, external_node_path_namespaceObject.join)(distPath.root || 'dist', distPath.worker || 'worker'),
43
+ js: '',
44
+ css: '',
45
+ jsAsync: '',
46
+ cssAsync: ''
47
+ },
48
+ filename: {
49
+ js: '[name].js'
50
+ }
51
+ }
52
+ };
53
+ }
54
+ if (config.environments?.node) {
55
+ compatConfig.environments ??= {};
56
+ compatConfig.environments.node = {
57
+ output: {
58
+ emitAssets: false,
59
+ distPath: {
60
+ root: (0, external_node_path_namespaceObject.join)(distPath.root || 'dist', distPath.server || 'bundles'),
61
+ js: '',
62
+ css: '',
63
+ jsAsync: '',
64
+ cssAsync: ''
65
+ }
66
+ }
67
+ };
68
+ }
69
+ return compatConfig.environments ? mergeRsbuildConfig(compatConfig, config) : config;
70
+ });
71
+ api.modifyRsbuildConfig({
72
+ handler: (config)=>{
73
+ const environmentNameOrder = [
74
+ 'web',
75
+ 'node',
76
+ 'workerSSR'
77
+ ];
78
+ config.environments = Object.fromEntries(Object.entries(config.environments).sort((a1, a2)=>environmentNameOrder.includes(a1[0]) ? environmentNameOrder.indexOf(a1[0]) - environmentNameOrder.indexOf(a2[0]) : 1));
79
+ },
80
+ order: 'post'
81
+ });
82
+ api.modifyEnvironmentConfig(async (config, { name })=>{
83
+ config.output.overrideBrowserslist ??= await (0, utils_js_namespaceObject.getBrowserslistWithDefault)(api.context.rootPath, config, name === utils_js_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME ? 'node' : config.output.target);
84
+ });
85
+ api.modifyBundlerChain(async (chain, { environment })=>{
86
+ const isServiceWorker = environment.name === utils_js_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME;
87
+ if (isServiceWorker) chain.output.library({
88
+ ...chain.output.get('library') || {},
89
+ type: 'commonjs2'
90
+ });
91
+ });
92
+ }
93
+ });
94
+ exports.pluginEnvironmentDefaults = __webpack_exports__.pluginEnvironmentDefaults;
95
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
96
+ "pluginEnvironmentDefaults"
97
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
98
+ Object.defineProperty(exports, '__esModule', {
99
+ value: true
100
+ });
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ pluginGlobalVars: ()=>pluginGlobalVars
28
+ });
29
+ const utils_namespaceObject = require("@modern-js/utils");
30
+ const pluginGlobalVars = (options)=>({
31
+ name: 'builder:global-vars',
32
+ setup (api) {
33
+ api.modifyBundlerChain((chain, { env, target, bundler })=>{
34
+ if (!options) return;
35
+ const globalVars = (0, utils_namespaceObject.applyOptionsChain)({}, options, {
36
+ env,
37
+ target
38
+ });
39
+ const serializedVars = {};
40
+ Object.entries(globalVars).forEach(([key, value])=>{
41
+ serializedVars[key] = JSON.stringify(value) ?? 'undefined';
42
+ });
43
+ chain.plugin('globalVars').use(bundler.DefinePlugin, [
44
+ serializedVars
45
+ ]);
46
+ });
47
+ }
48
+ });
49
+ exports.pluginGlobalVars = __webpack_exports__.pluginGlobalVars;
50
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
51
+ "pluginGlobalVars"
52
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
53
+ Object.defineProperty(exports, '__esModule', {
54
+ value: true
55
+ });
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ pluginHtmlMinifierTerser: ()=>pluginHtmlMinifierTerser
28
+ });
29
+ const external_ts_deepmerge_namespaceObject = require("ts-deepmerge");
30
+ function applyRemoveConsole(options, config) {
31
+ const { removeConsole } = config.performance;
32
+ const compressOptions = 'boolean' == typeof options.compress ? {} : options.compress || {};
33
+ if (true === removeConsole) options.compress = {
34
+ ...compressOptions,
35
+ drop_console: true
36
+ };
37
+ else if (Array.isArray(removeConsole)) {
38
+ const pureFuncs = removeConsole.map((method)=>`console.${method}`);
39
+ options.compress = {
40
+ ...compressOptions,
41
+ pure_funcs: pureFuncs
42
+ };
43
+ }
44
+ return options;
45
+ }
46
+ function getTerserMinifyOptions(config) {
47
+ const options = {
48
+ mangle: {
49
+ safari10: true
50
+ },
51
+ format: {
52
+ ascii_only: 'ascii' === config.output.charset
53
+ }
54
+ };
55
+ if ('none' === config.output.legalComments) {
56
+ options.format ||= {};
57
+ options.format.comments = false;
58
+ }
59
+ const finalOptions = applyRemoveConsole(options, config);
60
+ return finalOptions;
61
+ }
62
+ function getMinifyOptions(config) {
63
+ const minifyJS = getTerserMinifyOptions(config);
64
+ return {
65
+ removeComments: false,
66
+ useShortDoctype: true,
67
+ keepClosingSlash: true,
68
+ collapseWhitespace: true,
69
+ removeRedundantAttributes: true,
70
+ removeScriptTypeAttributes: true,
71
+ removeStyleLinkTypeAttributes: true,
72
+ removeEmptyAttributes: true,
73
+ minifyJS,
74
+ minifyCSS: true,
75
+ minifyURLs: true
76
+ };
77
+ }
78
+ const pluginHtmlMinifierTerser = ()=>({
79
+ name: 'builder:plugin-html-minifier-terser',
80
+ setup (api) {
81
+ api.modifyBundlerChain(async (chain, { isProd, environment })=>{
82
+ const { output, tools: { htmlPlugin } } = environment.config;
83
+ const disableHtmlMinify = !isProd || false === output.minify || false === htmlPlugin;
84
+ const { minify } = await import("html-minifier-terser");
85
+ const pluginRecord = chain.plugins.entries();
86
+ const minifyOptions = getMinifyOptions(environment.config);
87
+ for (const id of Object.keys(pluginRecord)){
88
+ if (!id.startsWith('html-')) continue;
89
+ const values = pluginRecord[id].values();
90
+ const isHtmlRspackPlugin = values.some((item)=>{
91
+ const name = item?.name || item.constructor?.name;
92
+ return 'HtmlRspackPlugin' === name;
93
+ });
94
+ if (isHtmlRspackPlugin && !disableHtmlMinify) {
95
+ chain.plugin(id).tap((options)=>{
96
+ if (!options.length) return options;
97
+ const userMinifyOption = options[0].minify;
98
+ if (false === userMinifyOption) return options;
99
+ const minifyFn = (html)=>minify(html, userMinifyOption ? (0, external_ts_deepmerge_namespaceObject.merge)(minifyOptions, userMinifyOption) : minifyOptions);
100
+ options[0].minify = minifyFn;
101
+ return options;
102
+ });
103
+ continue;
104
+ }
105
+ }
106
+ });
107
+ }
108
+ });
109
+ exports.pluginHtmlMinifierTerser = __webpack_exports__.pluginHtmlMinifierTerser;
110
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
111
+ "pluginHtmlMinifierTerser"
112
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
113
+ Object.defineProperty(exports, '__esModule', {
114
+ value: true
115
+ });
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ pluginManifest: ()=>pluginManifest
28
+ });
29
+ const manifest_js_namespaceObject = require("../shared/manifest.js");
30
+ const pluginManifest = ()=>({
31
+ name: 'builder:manifest',
32
+ setup (api) {
33
+ api.modifyBundlerChain(async (chain, { target, CHAIN_ID })=>{
34
+ const { RspackManifestPlugin } = await import("rspack-manifest-plugin");
35
+ const publicPath = chain.output.get('publicPath');
36
+ chain.plugin(CHAIN_ID.PLUGIN.MANIFEST).use(RspackManifestPlugin, [
37
+ {
38
+ fileName: 'web' === target ? 'asset-manifest.json' : `asset-manifest-${target}.json`,
39
+ publicPath,
40
+ generate: manifest_js_namespaceObject.generateManifest
41
+ }
42
+ ]);
43
+ });
44
+ }
45
+ });
46
+ exports.pluginManifest = __webpack_exports__.pluginManifest;
47
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
48
+ "pluginManifest"
49
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
50
+ Object.defineProperty(exports, '__esModule', {
51
+ value: true
52
+ });