@bleedingdev/modern-js-builder 3.2.0-ultramodern.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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -0
  3. package/dist/cjs/createBuilder.js +94 -0
  4. package/dist/cjs/index.js +59 -0
  5. package/dist/cjs/plugins/devtools.js +47 -0
  6. package/dist/cjs/plugins/emitRouteFile.js +75 -0
  7. package/dist/cjs/plugins/environmentDefaults.js +100 -0
  8. package/dist/cjs/plugins/globalVars.js +55 -0
  9. package/dist/cjs/plugins/htmlMinify.js +115 -0
  10. package/dist/cjs/plugins/manifest.js +52 -0
  11. package/dist/cjs/plugins/postcss.js +162 -0
  12. package/dist/cjs/plugins/rscConfig.js +159 -0
  13. package/dist/cjs/plugins/rsdoctor.js +64 -0
  14. package/dist/cjs/plugins/runtimeChunk.js +55 -0
  15. package/dist/cjs/shared/devServer.js +87 -0
  16. package/dist/cjs/shared/getCssSupport.js +121 -0
  17. package/dist/cjs/shared/manifest.js +46 -0
  18. package/dist/cjs/shared/parseCommonConfig.js +210 -0
  19. package/dist/cjs/shared/rsc/rsc-server-entry-loader.js +41 -0
  20. package/dist/cjs/shared/rsc/rscClientBrowserFallback.js +64 -0
  21. package/dist/cjs/shared/rsc/rscEmptyModule.js +36 -0
  22. package/dist/cjs/shared/utils.js +115 -0
  23. package/dist/cjs/types.js +18 -0
  24. package/dist/esm/createBuilder.mjs +57 -0
  25. package/dist/esm/index.mjs +3 -0
  26. package/dist/esm/plugins/devtools.mjs +13 -0
  27. package/dist/esm/plugins/emitRouteFile.mjs +28 -0
  28. package/dist/esm/plugins/environmentDefaults.mjs +66 -0
  29. package/dist/esm/plugins/globalVars.mjs +21 -0
  30. package/dist/esm/plugins/htmlMinify.mjs +81 -0
  31. package/dist/esm/plugins/manifest.mjs +18 -0
  32. package/dist/esm/plugins/postcss.mjs +115 -0
  33. package/dist/esm/plugins/rscConfig.mjs +112 -0
  34. package/dist/esm/plugins/rsdoctor.mjs +30 -0
  35. package/dist/esm/plugins/runtimeChunk.mjs +21 -0
  36. package/dist/esm/shared/devServer.mjs +53 -0
  37. package/dist/esm/shared/getCssSupport.mjs +77 -0
  38. package/dist/esm/shared/manifest.mjs +12 -0
  39. package/dist/esm/shared/parseCommonConfig.mjs +173 -0
  40. package/dist/esm/shared/rsc/rsc-server-entry-loader.mjs +7 -0
  41. package/dist/esm/shared/rsc/rscClientBrowserFallback.mjs +20 -0
  42. package/dist/esm/shared/rsc/rscEmptyModule.mjs +2 -0
  43. package/dist/esm/shared/utils.mjs +53 -0
  44. package/dist/esm/types.mjs +0 -0
  45. package/dist/esm-node/createBuilder.mjs +58 -0
  46. package/dist/esm-node/index.mjs +4 -0
  47. package/dist/esm-node/plugins/devtools.mjs +14 -0
  48. package/dist/esm-node/plugins/emitRouteFile.mjs +29 -0
  49. package/dist/esm-node/plugins/environmentDefaults.mjs +67 -0
  50. package/dist/esm-node/plugins/globalVars.mjs +22 -0
  51. package/dist/esm-node/plugins/htmlMinify.mjs +82 -0
  52. package/dist/esm-node/plugins/manifest.mjs +19 -0
  53. package/dist/esm-node/plugins/postcss.mjs +116 -0
  54. package/dist/esm-node/plugins/rscConfig.mjs +117 -0
  55. package/dist/esm-node/plugins/rsdoctor.mjs +31 -0
  56. package/dist/esm-node/plugins/runtimeChunk.mjs +22 -0
  57. package/dist/esm-node/shared/devServer.mjs +54 -0
  58. package/dist/esm-node/shared/getCssSupport.mjs +78 -0
  59. package/dist/esm-node/shared/manifest.mjs +13 -0
  60. package/dist/esm-node/shared/parseCommonConfig.mjs +174 -0
  61. package/dist/esm-node/shared/rsc/rsc-server-entry-loader.mjs +8 -0
  62. package/dist/esm-node/shared/rsc/rscClientBrowserFallback.mjs +25 -0
  63. package/dist/esm-node/shared/rsc/rscEmptyModule.mjs +3 -0
  64. package/dist/esm-node/shared/utils.mjs +54 -0
  65. package/dist/esm-node/types.mjs +1 -0
  66. package/dist/types/createBuilder.d.ts +8 -0
  67. package/dist/types/index.d.ts +8 -0
  68. package/dist/types/plugins/devtools.d.ts +4 -0
  69. package/dist/types/plugins/emitRouteFile.d.ts +6 -0
  70. package/dist/types/plugins/environmentDefaults.d.ts +3 -0
  71. package/dist/types/plugins/globalVars.d.ts +3 -0
  72. package/dist/types/plugins/htmlMinify.d.ts +2 -0
  73. package/dist/types/plugins/manifest.d.ts +2 -0
  74. package/dist/types/plugins/postcss.d.ts +6 -0
  75. package/dist/types/plugins/rscConfig.d.ts +18 -0
  76. package/dist/types/plugins/rsdoctor.d.ts +3 -0
  77. package/dist/types/plugins/runtimeChunk.d.ts +2 -0
  78. package/dist/types/shared/devServer.d.ts +6 -0
  79. package/dist/types/shared/getCssSupport.d.ts +1 -0
  80. package/dist/types/shared/manifest.d.ts +2 -0
  81. package/dist/types/shared/parseCommonConfig.d.ts +9 -0
  82. package/dist/types/shared/rsc/rsc-server-entry-loader.d.ts +5 -0
  83. package/dist/types/shared/rsc/rscClientBrowserFallback.d.ts +2 -0
  84. package/dist/types/shared/rsc/rscEmptyModule.d.ts +2 -0
  85. package/dist/types/shared/utils.d.ts +12 -0
  86. package/dist/types/types.d.ts +287 -0
  87. package/package.json +88 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ <p align="center">
2
+ <a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
3
+ </p>
4
+
5
+ <h1 align="center">Modern.js</h1>
6
+
7
+ <p align="center">
8
+ A Progressive React Framework for modern web development.
9
+ </p>
10
+
11
+ ## Getting Started
12
+
13
+ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
14
+
15
+ ## Documentation
16
+
17
+ - [English Documentation](https://modernjs.dev/en/)
18
+ - [中文文档](https://modernjs.dev)
19
+
20
+ ## Contributing
21
+
22
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
23
+
24
+ ## License
25
+
26
+ Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
@@ -0,0 +1,94 @@
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
+ createRspackBuilder: ()=>createRspackBuilder,
28
+ parseConfig: ()=>parseConfig
29
+ });
30
+ const core_namespaceObject = require("@rsbuild/core");
31
+ const rscConfig_js_namespaceObject = require("./plugins/rscConfig.js");
32
+ const rsdoctor_js_namespaceObject = require("./plugins/rsdoctor.js");
33
+ const parseCommonConfig_js_namespaceObject = require("./shared/parseCommonConfig.js");
34
+ const rscClientBrowserFallback_js_namespaceObject = require("./shared/rsc/rscClientBrowserFallback.js");
35
+ async function parseConfig(builderConfig, options) {
36
+ builderConfig.performance ??= {};
37
+ builderConfig.performance.buildCache ??= true;
38
+ const { rsbuildConfig, rsbuildPlugins, rsdoctorConfig } = await (0, parseCommonConfig_js_namespaceObject.parseCommonConfig)(builderConfig, options);
39
+ const { sri } = builderConfig.security || {};
40
+ if (sri) if (true === sri) rsbuildConfig.security.sri = {
41
+ enable: 'auto'
42
+ };
43
+ else {
44
+ const algorithm = Array.isArray(sri.hashFuncNames) ? sri.hashFuncNames[0] : void 0;
45
+ rsbuildConfig.security.sri = {
46
+ enable: sri.enabled,
47
+ algorithm
48
+ };
49
+ }
50
+ if (false === Boolean(rsbuildConfig.tools.lightningcssLoader)) {
51
+ const { pluginPostcss } = await import("./plugins/postcss.js");
52
+ rsbuildPlugins.push(pluginPostcss({
53
+ autoprefixer: builderConfig.tools?.autoprefixer
54
+ }));
55
+ }
56
+ const enableRsc = builderConfig.server?.rsc ?? false;
57
+ if (enableRsc) {
58
+ const rscPlugins = await (0, rscConfig_js_namespaceObject.getRscPlugins)(enableRsc, options.internalDirectory);
59
+ rsbuildPlugins.push(...rscPlugins);
60
+ } else rsbuildPlugins.push((0, rscClientBrowserFallback_js_namespaceObject.rscClientBrowserFallbackPlugin)());
61
+ const rsdoctorPlugin = (0, rsdoctor_js_namespaceObject.pluginRsdoctor)(rsdoctorConfig);
62
+ if (rsdoctorPlugin) rsbuildPlugins.push(rsdoctorPlugin);
63
+ return {
64
+ rsbuildConfig,
65
+ rsbuildPlugins
66
+ };
67
+ }
68
+ async function createRspackBuilder(options) {
69
+ const { cwd = process.cwd(), config, ...rest } = options;
70
+ const { rsbuildConfig, rsbuildPlugins } = await parseConfig(config, {
71
+ ...rest,
72
+ cwd
73
+ });
74
+ rsbuildConfig.plugins = [
75
+ ...rsbuildPlugins,
76
+ ...rsbuildConfig.plugins || []
77
+ ];
78
+ const rsbuild = await (0, core_namespaceObject.createRsbuild)({
79
+ cwd,
80
+ rsbuildConfig
81
+ });
82
+ return {
83
+ ...rsbuild
84
+ };
85
+ }
86
+ exports.createRspackBuilder = __webpack_exports__.createRspackBuilder;
87
+ exports.parseConfig = __webpack_exports__.parseConfig;
88
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
89
+ "createRspackBuilder",
90
+ "parseConfig"
91
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
92
+ Object.defineProperty(exports, '__esModule', {
93
+ value: true
94
+ });
@@ -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_NAME: ()=>utils_js_namespaceObject.RUNTIME_CHUNK_NAME,
28
+ RUNTIME_CHUNK_REGEX: ()=>utils_js_namespaceObject.RUNTIME_CHUNK_REGEX,
29
+ SERVICE_WORKER_ENVIRONMENT_NAME: ()=>utils_js_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME,
30
+ castArray: ()=>utils_js_namespaceObject.castArray,
31
+ createBuilder: ()=>external_createBuilder_js_namespaceObject.createRspackBuilder,
32
+ isHtmlDisabled: ()=>utils_js_namespaceObject.isHtmlDisabled,
33
+ logger: ()=>core_namespaceObject.logger,
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
+ isFileExists: ()=>isFileExists,
37
+ pluginEmitRouteFile: ()=>pluginEmitRouteFile
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?.server) {
55
+ compatConfig.environments ??= {};
56
+ compatConfig.environments.server = {
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
+ 'client',
75
+ 'server',
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
+ });