@modern-js/builder 3.0.0-alpha.0 → 3.0.0-alpha.2

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 +61 -0
  59. package/dist/esm-node/index.mjs +6 -0
  60. package/dist/esm-node/plugins/devtools.mjs +15 -0
  61. package/dist/esm-node/plugins/emitRouteFile.mjs +30 -0
  62. package/dist/esm-node/plugins/environmentDefaults.mjs +68 -0
  63. package/dist/esm-node/plugins/globalVars.mjs +23 -0
  64. package/dist/esm-node/plugins/htmlMinify.mjs +83 -0
  65. package/dist/esm-node/plugins/manifest.mjs +20 -0
  66. package/dist/esm-node/plugins/postcss.mjs +83 -0
  67. package/dist/esm-node/plugins/runtimeChunk.mjs +22 -0
  68. package/dist/esm-node/rsc/common.mjs +89 -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 +145 -0
  71. package/dist/esm-node/rsc/plugins/rspack-rsc-server-plugin.mjs +213 -0
  72. package/dist/esm-node/rsc/rsc-client-loader.mjs +39 -0
  73. package/dist/esm-node/rsc/rsc-css-loader.mjs +10 -0
  74. package/dist/esm-node/rsc/rsc-server-loader.mjs +60 -0
  75. package/dist/esm-node/rsc/rsc-ssr-loader.mjs +28 -0
  76. package/dist/esm-node/shared/devServer.mjs +55 -0
  77. package/dist/esm-node/shared/getCssSupport.mjs +79 -0
  78. package/dist/esm-node/shared/manifest.mjs +14 -0
  79. package/dist/esm-node/shared/parseCommonConfig.mjs +174 -0
  80. package/dist/esm-node/shared/rsc/rscClientBrowserFallback.mjs +25 -0
  81. package/dist/esm-node/shared/rsc/rscEmptyModule.mjs +4 -0
  82. package/dist/esm-node/shared/utils.mjs +55 -0
  83. package/dist/esm-node/types.mjs +2 -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 +36 -31
  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 -166
  102. package/dist/rsc/plugins/rspack-rsc-client-plugin.js +0 -233
  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,60 @@
1
+ import __rslib_shim_module__ from "node:module";
2
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
3
+ import path from "path";
4
+ import { transform } from "@swc/core";
5
+ import { setRscBuildInfo } from "./common.mjs";
6
+ function extractMetadata(code) {
7
+ const metadataRegex = /\/\* @modern-js-rsc-metadata\n([\s\S]*?)\*\//;
8
+ const match = code.match(metadataRegex);
9
+ if (!match) return null;
10
+ try {
11
+ const metadata = JSON.parse(match[1]);
12
+ return metadata;
13
+ } catch (e) {
14
+ console.error('Failed to parse metadata:', e);
15
+ return null;
16
+ }
17
+ }
18
+ async function rscServerLoader(source) {
19
+ this.cacheable(true);
20
+ const callback = this.async();
21
+ const { appDir, runtimePath = '@modern-js/runtime/rsc/server' } = this.getOptions();
22
+ const result = await transform(source, {
23
+ filename: this.resourcePath,
24
+ jsc: {
25
+ target: 'es2020',
26
+ experimental: {
27
+ cacheRoot: path.resolve(appDir, 'node_modules/.swc'),
28
+ plugins: [
29
+ [
30
+ require.resolve('@modern-js/flight-server-transform-plugin'),
31
+ {
32
+ appDir: appDir,
33
+ runtimePath: runtimePath
34
+ }
35
+ ]
36
+ ]
37
+ }
38
+ },
39
+ isModule: true
40
+ });
41
+ const { code, map } = result;
42
+ const metadata = extractMetadata(code);
43
+ if (metadata?.directive && 'client' === metadata.directive) {
44
+ const { exportNames } = metadata;
45
+ if (exportNames.length > 0) setRscBuildInfo(this._module, {
46
+ type: 'client',
47
+ resourcePath: this.resourcePath,
48
+ clientReferences: exportNames
49
+ });
50
+ } else if (metadata) {
51
+ const { exportNames } = metadata;
52
+ if (exportNames.length > 0) setRscBuildInfo(this._module, {
53
+ type: 'server',
54
+ resourcePath: this.resourcePath,
55
+ exportNames: exportNames.map((item)=>item.exportName)
56
+ });
57
+ }
58
+ return callback(null, code, map);
59
+ }
60
+ export { rscServerLoader as default };
@@ -0,0 +1,28 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
3
+ import { getExportNames, isServerModule, parseSource, setRscBuildInfo } from "./common.mjs";
4
+ async function rscSsrLoader(source, sourceMap) {
5
+ this.cacheable(true);
6
+ const callback = this.async();
7
+ const ast = await parseSource(source);
8
+ const hasDeclareServerDirective = await isServerModule(ast);
9
+ const resourcePath = this.resourcePath;
10
+ if (!hasDeclareServerDirective) return void callback(null, source, sourceMap);
11
+ const exportedNames = await getExportNames(ast, true);
12
+ const importsCode = `
13
+ 'use server';
14
+ `;
15
+ const exportsCode = exportedNames.map((name)=>{
16
+ if ('default' === name) return 'export default () => {throw new Error("Server actions must not be called during server-side rendering.")}';
17
+ return `export const ${name} = () => {
18
+ throw new Error("Server actions must not be called during server-side rendering.")
19
+ }`;
20
+ }).join('\n');
21
+ if (exportedNames.length > 0) setRscBuildInfo(this._module, {
22
+ type: 'server',
23
+ resourcePath,
24
+ exportNames: exportedNames
25
+ });
26
+ callback(null, `${importsCode}\n${exportsCode}`, sourceMap);
27
+ }
28
+ export { rscSsrLoader as default };
@@ -0,0 +1,55 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
3
+ import { applyOptionsChain, isProd } from "@modern-js/utils";
4
+ import { merge } from "ts-deepmerge";
5
+ const defaultDevConfig = {
6
+ writeToDisk: (file)=>!file.includes('.hot-update.'),
7
+ hmr: true,
8
+ liveReload: true,
9
+ progressBar: true,
10
+ client: {
11
+ path: '/webpack-hmr',
12
+ overlay: false,
13
+ port: '<port>'
14
+ }
15
+ };
16
+ const transformToRsbuildServerOptions = (dev, devServer, server)=>{
17
+ const { host = '0.0.0.0', https, startUrl, beforeStartUrl, server: devServerConfig, ...devConfig } = dev;
18
+ const port = process.env.PORT ? Number(process.env.PORT) : server?.port ?? 8080;
19
+ const rsbuildDev = merge(defaultDevConfig, devConfig);
20
+ delete rsbuildDev.setupMiddlewares;
21
+ const legacyServerConfig = applyOptionsChain({}, devServer, {}, merge);
22
+ const serverCofig = {
23
+ compress: devServerConfig?.compress ?? legacyServerConfig.compress,
24
+ headers: devServerConfig?.headers ?? legacyServerConfig.headers,
25
+ historyApiFallback: devServerConfig?.historyApiFallback ?? legacyServerConfig.historyApiFallback,
26
+ proxy: devServerConfig?.proxy ?? legacyServerConfig.proxy
27
+ };
28
+ const rsbuildServer = isProd() ? {
29
+ publicDir: false,
30
+ htmlFallback: false,
31
+ printUrls: false
32
+ } : {
33
+ publicDir: false,
34
+ htmlFallback: false,
35
+ printUrls: false,
36
+ compress: serverCofig.compress,
37
+ headers: serverCofig.headers,
38
+ historyApiFallback: serverCofig.historyApiFallback,
39
+ proxy: serverCofig.proxy,
40
+ host,
41
+ port,
42
+ https: https ? https : void 0,
43
+ middlewareMode: true,
44
+ cors: server?.cors
45
+ };
46
+ if (!isProd() && startUrl) rsbuildServer.open = beforeStartUrl ? {
47
+ target: true === startUrl ? '//localhost:<port>' : startUrl,
48
+ before: beforeStartUrl
49
+ } : startUrl;
50
+ return {
51
+ rsbuildDev,
52
+ rsbuildServer
53
+ };
54
+ };
55
+ export { transformToRsbuildServerOptions };
@@ -0,0 +1,79 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
3
+ import browserslist from "browserslist";
4
+ const CSS_FEATURES_BROWSER = {
5
+ customProperties: {
6
+ and_chr: '49',
7
+ and_ff: '31',
8
+ android: '50',
9
+ chrome: '49',
10
+ edge: '15',
11
+ firefox: '31',
12
+ ios_saf: '9.3',
13
+ op_mob: '36',
14
+ opera: '36',
15
+ safari: '9.1',
16
+ samsung: '5.0'
17
+ },
18
+ initial: {
19
+ and_chr: '37',
20
+ and_ff: '27',
21
+ android: '37',
22
+ chrome: '37',
23
+ edge: '79',
24
+ firefox: '27',
25
+ ios_saf: '9.3',
26
+ op_mob: '24',
27
+ opera: '24',
28
+ safari: '9.1',
29
+ samsung: '3.0'
30
+ },
31
+ pageBreak: {
32
+ and_chr: '51',
33
+ and_ff: '92',
34
+ android: '51',
35
+ chrome: '51',
36
+ edge: '12',
37
+ firefox: '92',
38
+ ios_saf: '10',
39
+ op_mob: '37',
40
+ opera: '11.1',
41
+ safari: '10',
42
+ samsung: '5.0'
43
+ },
44
+ fontVariant: {
45
+ and_chr: '18',
46
+ and_ff: '34',
47
+ android: '4.4',
48
+ chrome: '1',
49
+ edge: '12',
50
+ firefox: '34',
51
+ ios_saf: '9.3',
52
+ op_mob: '12',
53
+ opera: '10',
54
+ safari: '9.1',
55
+ samsung: '1.0'
56
+ },
57
+ mediaMinmax: {
58
+ and_chr: '104',
59
+ and_ff: '109',
60
+ android: '104',
61
+ chrome: '104',
62
+ edge: '104',
63
+ firefox: '63',
64
+ opera: '91'
65
+ }
66
+ };
67
+ const getCssFeatureBrowsers = (feature)=>{
68
+ const featureBrowsers = CSS_FEATURES_BROWSER[feature];
69
+ return browserslist(Object.entries(featureBrowsers).map(([key, value])=>`${key} >= ${value}`));
70
+ };
71
+ const isFeatureSupported = (projectBrowsers, featureBrowsers)=>projectBrowsers.every((item)=>featureBrowsers.includes(item));
72
+ function getCssSupport(projectBrowserslist) {
73
+ const projectBrowsers = browserslist(projectBrowserslist);
74
+ return Object.keys(CSS_FEATURES_BROWSER).reduce((acc, key)=>{
75
+ acc[key] = isFeatureSupported(projectBrowsers, getCssFeatureBrowsers(key));
76
+ return acc;
77
+ }, {});
78
+ }
79
+ export { getCssSupport };
@@ -0,0 +1,14 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
3
+ const generateManifest = (seed, files, entries)=>{
4
+ const manifestFiles = files.reduce((manifest, file)=>{
5
+ manifest[file.name] = file.path;
6
+ return manifest;
7
+ }, seed);
8
+ const entrypointFiles = Object.keys(entries).reduce((previous, name)=>previous.concat(entries[name].filter((fileName)=>!fileName.endsWith('.map'))), []);
9
+ return {
10
+ files: manifestFiles,
11
+ entrypoints: entrypointFiles
12
+ };
13
+ };
14
+ export { generateManifest };
@@ -0,0 +1,174 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
3
+ import { mergeRsbuildConfig } from "@rsbuild/core";
4
+ import { pluginCssMinimizer } from "@rsbuild/plugin-css-minimizer";
5
+ import { pluginLess } from "@rsbuild/plugin-less";
6
+ import { pluginReact } from "@rsbuild/plugin-react";
7
+ import { pluginSass } from "@rsbuild/plugin-sass";
8
+ import { pluginDevtool } from "../plugins/devtools.mjs";
9
+ import { pluginEmitRouteFile } from "../plugins/emitRouteFile.mjs";
10
+ import { pluginEnvironmentDefaults } from "../plugins/environmentDefaults.mjs";
11
+ import { pluginGlobalVars } from "../plugins/globalVars.mjs";
12
+ import { pluginHtmlMinifierTerser } from "../plugins/htmlMinify.mjs";
13
+ import { pluginRuntimeChunk } from "../plugins/runtimeChunk.mjs";
14
+ import { transformToRsbuildServerOptions } from "./devServer.mjs";
15
+ import { NODE_MODULES_REGEX } from "./utils.mjs";
16
+ const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
17
+ const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
18
+ const isLooseCssModules = (path)=>{
19
+ if (NODE_MODULES_REGEX.test(path)) return CSS_MODULES_REGEX.test(path);
20
+ return !GLOBAL_CSS_REGEX.test(path);
21
+ };
22
+ function removeUndefinedKey(obj) {
23
+ Object.keys(obj).forEach((key)=>{
24
+ if (void 0 === obj[key]) delete obj[key];
25
+ });
26
+ return obj;
27
+ }
28
+ async function parseCommonConfig(builderConfig, options) {
29
+ const frameworkConfigPath = options?.frameworkConfigPath;
30
+ const { plugins: [...plugins] = [], splitChunks, performance: { ...performanceConfig } = {}, output: { module = false, enableCssModuleTSDeclaration, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetManifest, sourceMap, convertToRem, polyfill, dataUriLimit = 10000, distPath = {}, ...outputConfig } = {}, html: { outputStructure, appIcon, ...htmlConfig } = {}, source: { alias, globalVars, transformImport, ...sourceConfig } = {}, dev = {}, server = {}, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, less, sass, htmlPlugin, autoprefixer, ...toolsConfig } = {}, environments = {}, resolve = {} } = builderConfig;
31
+ let combinedAlias;
32
+ if (alias || resolve.alias) combinedAlias = [].concat(alias ?? []).concat(resolve.alias ?? []);
33
+ const rsbuildConfig = {
34
+ plugins,
35
+ splitChunks,
36
+ output: {
37
+ polyfill: 'ua' === polyfill ? 'off' : polyfill,
38
+ dataUriLimit,
39
+ sourceMap,
40
+ module,
41
+ ...outputConfig
42
+ },
43
+ resolve: {
44
+ ...resolve,
45
+ alias: combinedAlias
46
+ },
47
+ source: sourceConfig,
48
+ performance: performanceConfig,
49
+ html: htmlConfig,
50
+ tools: toolsConfig,
51
+ security: securityConfig,
52
+ environments
53
+ };
54
+ rsbuildConfig.tools.htmlPlugin = htmlPlugin;
55
+ rsbuildConfig.tools.lightningcssLoader ??= false;
56
+ const { html = {}, output = {}, source = {} } = rsbuildConfig;
57
+ source.transformImport = false === transformImport ? ()=>[] : transformImport;
58
+ if (!source.decorators) source.decorators = {
59
+ version: 'legacy'
60
+ };
61
+ output.charset ??= 'ascii';
62
+ if ('boolean' != typeof output.sourceMap) {
63
+ output.sourceMap ||= {};
64
+ output.sourceMap.css ??= 'production' !== process.env.NODE_ENV;
65
+ }
66
+ const { server: _server, worker, ...rsbuildDistPath } = distPath;
67
+ output.distPath = rsbuildDistPath;
68
+ output.distPath.html ??= 'html';
69
+ output.polyfill ??= 'entry';
70
+ if (disableCssModuleExtension) {
71
+ output.cssModules ||= {};
72
+ output.cssModules.auto ??= isLooseCssModules;
73
+ }
74
+ const extraConfig = {};
75
+ extraConfig.html ||= {};
76
+ extraConfig.html.outputStructure = outputStructure ?? 'nested';
77
+ html.title ??= '';
78
+ html.appIcon = appIcon;
79
+ extraConfig.tools ??= {};
80
+ if (false !== htmlPlugin) extraConfig.tools.htmlPlugin = (config)=>{
81
+ if ('function' == typeof config.templateParameters) {
82
+ const originFn = config.templateParameters;
83
+ config.templateParameters = (...args)=>{
84
+ const res = originFn(...args);
85
+ return {
86
+ title: config.title,
87
+ meta: void 0,
88
+ ...res
89
+ };
90
+ };
91
+ }
92
+ };
93
+ if (!dev.lazyCompilation) dev.lazyCompilation = false;
94
+ const { rsbuildDev, rsbuildServer } = transformToRsbuildServerOptions(dev || {}, devServer || {}, server || {});
95
+ rsbuildConfig.server = removeUndefinedKey(rsbuildServer);
96
+ rsbuildConfig.dev = removeUndefinedKey(rsbuildDev);
97
+ rsbuildConfig.html = html;
98
+ rsbuildConfig.output = output;
99
+ const rsbuildPlugins = [
100
+ pluginGlobalVars(globalVars),
101
+ pluginDevtool({
102
+ sourceMap
103
+ }),
104
+ pluginEmitRouteFile(),
105
+ pluginSass({
106
+ sassLoaderOptions: sass
107
+ }),
108
+ pluginLess({
109
+ lessLoaderOptions: less
110
+ }),
111
+ pluginEnvironmentDefaults(distPath),
112
+ pluginHtmlMinifierTerser()
113
+ ];
114
+ if (checkSyntax) {
115
+ const { pluginCheckSyntax } = await import("@rsbuild/plugin-check-syntax");
116
+ rsbuildPlugins.push(pluginCheckSyntax('boolean' == typeof checkSyntax ? {} : checkSyntax));
117
+ }
118
+ if (!disableTsChecker) {
119
+ const { pluginTypeCheck } = await import("@rsbuild/plugin-type-check");
120
+ rsbuildPlugins.push(pluginTypeCheck({
121
+ tsCheckerOptions: tsChecker
122
+ }));
123
+ }
124
+ if (convertToRem) {
125
+ const { pluginRem } = await import("@rsbuild/plugin-rem");
126
+ rsbuildPlugins.push(pluginRem('boolean' == typeof convertToRem ? {} : convertToRem));
127
+ }
128
+ if (enableCssModuleTSDeclaration) {
129
+ const { pluginTypedCSSModules } = await import("@rsbuild/plugin-typed-css-modules");
130
+ rsbuildPlugins.push(pluginTypedCSSModules());
131
+ }
132
+ rsbuildPlugins.push(pluginRuntimeChunk(builderConfig.output?.disableInlineRuntimeChunk));
133
+ const { sourceBuild } = builderConfig.experiments || {};
134
+ if (sourceBuild) {
135
+ const { pluginSourceBuild } = await import("@rsbuild/plugin-source-build");
136
+ rsbuildPlugins.push(pluginSourceBuild(true === sourceBuild ? {} : sourceBuild));
137
+ }
138
+ rsbuildPlugins.push(pluginReact());
139
+ if (!disableSvgr) {
140
+ const { pluginSvgr } = await import("@rsbuild/plugin-svgr");
141
+ rsbuildPlugins.push(pluginSvgr({
142
+ mixedImport: true,
143
+ svgrOptions: {
144
+ exportType: 'component' === svgDefaultExport ? 'default' : 'named'
145
+ }
146
+ }));
147
+ }
148
+ if (assetsRetry) {
149
+ const { pluginAssetsRetry } = await import("@rsbuild/plugin-assets-retry");
150
+ rsbuildPlugins.push(pluginAssetsRetry(assetsRetry));
151
+ }
152
+ if (frameworkConfigPath && false !== performanceConfig.buildCache) {
153
+ const buildCache = 'object' == typeof performanceConfig.buildCache ? performanceConfig.buildCache : {};
154
+ rsbuildConfig.performance.buildCache = {
155
+ ...buildCache,
156
+ buildDependencies: [
157
+ frameworkConfigPath,
158
+ ...buildCache.buildDependencies || []
159
+ ]
160
+ };
161
+ }
162
+ rsbuildPlugins.push(pluginCssMinimizer({
163
+ pluginOptions: minifyCss
164
+ }));
165
+ if (enableAssetManifest) {
166
+ const { pluginManifest } = await import("../plugins/manifest.mjs");
167
+ rsbuildPlugins.push(pluginManifest());
168
+ }
169
+ return {
170
+ rsbuildConfig: mergeRsbuildConfig(rsbuildConfig, extraConfig),
171
+ rsbuildPlugins
172
+ };
173
+ }
174
+ export { isLooseCssModules, parseCommonConfig };
@@ -0,0 +1,25 @@
1
+ import __rslib_shim_module__ from "node:module";
2
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
3
+ import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
4
+ import { dirname as __rspack_dirname } from "node:path";
5
+ import path from "path";
6
+ var rscClientBrowserFallback_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
7
+ function rscClientBrowserFallbackPlugin() {
8
+ return {
9
+ name: 'builder:rsc-client-browser-fallback',
10
+ setup (api) {
11
+ let emptyModulePath;
12
+ try {
13
+ emptyModulePath = require.resolve('./rscEmptyModule');
14
+ } catch {
15
+ emptyModulePath = path.resolve(rscClientBrowserFallback_dirname, 'rscEmptyModule');
16
+ }
17
+ api.modifyRspackConfig((config)=>{
18
+ config.resolve ??= {};
19
+ config.resolve.fallback ??= {};
20
+ config.resolve.fallback['react-server-dom-webpack/client.browser'] = emptyModulePath;
21
+ });
22
+ }
23
+ };
24
+ }
25
+ export { rscClientBrowserFallbackPlugin };
@@ -0,0 +1,4 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
3
+ const rscEmptyModule = {};
4
+ export { rscEmptyModule as default };
@@ -0,0 +1,55 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
3
+ import browserslist from "browserslist";
4
+ const RUNTIME_CHUNK_NAME = 'builder-runtime';
5
+ const RUNTIME_CHUNK_REGEX = new RegExp(`${RUNTIME_CHUNK_NAME}([.].+)?\\.js$`);
6
+ const SERVICE_WORKER_ENVIRONMENT_NAME = 'workerSSR';
7
+ const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
8
+ const castArray = (arr)=>{
9
+ if (void 0 === arr) return [];
10
+ return Array.isArray(arr) ? arr : [
11
+ arr
12
+ ];
13
+ };
14
+ const browsersListCache = new Map();
15
+ async function getBrowserslist(path) {
16
+ const env = process.env.NODE_ENV;
17
+ const cacheKey = `${path}${env}`;
18
+ if (browsersListCache.has(cacheKey)) return browsersListCache.get(cacheKey);
19
+ const result = browserslist.loadConfig({
20
+ path,
21
+ env
22
+ });
23
+ if (result) {
24
+ browsersListCache.set(cacheKey, result);
25
+ return result;
26
+ }
27
+ return null;
28
+ }
29
+ const isHtmlDisabled = (config, target)=>{
30
+ const { htmlPlugin } = config.tools;
31
+ return false === htmlPlugin || Array.isArray(htmlPlugin) && htmlPlugin.includes(false) || 'web' !== target;
32
+ };
33
+ const DEFAULT_WEB_BROWSERSLIST = [
34
+ 'chrome >= 87',
35
+ 'edge >= 88',
36
+ 'firefox >= 78',
37
+ 'safari >= 14'
38
+ ];
39
+ const DEFAULT_BROWSERSLIST = {
40
+ web: DEFAULT_WEB_BROWSERSLIST,
41
+ node: [
42
+ 'node >= 16'
43
+ ],
44
+ 'web-worker': DEFAULT_WEB_BROWSERSLIST
45
+ };
46
+ async function getBrowserslistWithDefault(path, config, target) {
47
+ const { overrideBrowserslist: overrides } = config?.output || {};
48
+ if ('web' === target || 'web-worker' === target) {
49
+ if (overrides) return overrides;
50
+ const browserslistrc = await getBrowserslist(path);
51
+ if (browserslistrc) return browserslistrc;
52
+ }
53
+ return DEFAULT_BROWSERSLIST[target];
54
+ }
55
+ export { NODE_MODULES_REGEX, RUNTIME_CHUNK_NAME, RUNTIME_CHUNK_REGEX, SERVICE_WORKER_ENVIRONMENT_NAME, castArray, getBrowserslistWithDefault, isHtmlDisabled };
@@ -0,0 +1,2 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
@@ -0,0 +1,2 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ export declare function rscClientBrowserFallbackPlugin(): RsbuildPlugin;
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -1,7 +1,6 @@
1
1
  import type { AliasOption } from '@modern-js/utils';
2
2
  import type { ConfigChain, ConfigChainWithContext, DevConfig, DistPathConfig, EnvironmentConfig, HtmlConfig, OutputConfig, Polyfill, RsbuildConfig, RsbuildPluginAPI, RsbuildPlugins, RsbuildTarget, Rspack, SecurityConfig, ServerConfig, SourceConfig, ToolsConfig } from '@rsbuild/core';
3
3
  import type { PluginAssetsRetryOptions } from '@rsbuild/plugin-assets-retry';
4
- import type { PluginBabelOptions } from '@rsbuild/plugin-babel';
5
4
  import type { PluginCheckSyntaxOptions } from '@rsbuild/plugin-check-syntax';
6
5
  import type { PluginCssMinimizerOptions } from '@rsbuild/plugin-css-minimizer';
7
6
  import type { PluginLessOptions } from '@rsbuild/plugin-less';
@@ -99,13 +98,6 @@ export type BuilderExtraConfig = {
99
98
  * Modify the options of [css-minimizer-webpack-plugin](https://github.com/webpack-contrib/css-minimizer-webpack-plugin).
100
99
  */
101
100
  minifyCss?: PluginCssMinimizerOptions['pluginOptions'];
102
- /**
103
- * Modify the options of [babel-loader](https://github.com/babel/babel-loader)
104
- * When `tools.babel`'s type is Function,the default babel config will be passed in as the first parameter, the config object can be modified directly, or a value can be returned as the final result.
105
- * When `tools.babel`'s type is `Object`, the config will be shallow merged with default config by `Object.assign`.
106
- * Note that `Object.assign` is a shallow copy and will completely overwrite the built-in `presets` or `plugins` array, please use it with caution.
107
- */
108
- babel?: PluginBabelOptions['babelLoaderOptions'];
109
101
  /**
110
102
  * Modify the config of [less-loader](https://github.com/webpack-contrib/less-loader).
111
103
  */
@@ -263,6 +255,7 @@ export type BuilderConfig = {
263
255
  port?: number;
264
256
  cors?: ServerConfig['cors'];
265
257
  };
258
+ splitChunks?: RsbuildConfig['splitChunks'];
266
259
  performance?: RsbuildConfig['performance'];
267
260
  security?: Omit<SecurityConfig, 'sri'>;
268
261
  tools?: Omit<ToolsConfig, 'htmlPlugin'>;
@@ -270,14 +263,7 @@ export type BuilderConfig = {
270
263
  source?: Omit<SourceConfig, 'alias' | 'transformImport'>;
271
264
  plugins?: RsbuildPlugins;
272
265
  environments?: {
273
- [key: string]: EnvironmentConfig & {
274
- tools?: {
275
- /**
276
- * Modify the options of [babel-loader](https://github.com/babel/babel-loader)
277
- */
278
- babel?: PluginBabelOptions['babelLoaderOptions'];
279
- };
280
- };
266
+ [key: string]: EnvironmentConfig;
281
267
  };
282
268
  } & BuilderExtraConfig;
283
269
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/builder",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.2",
4
4
  "description": "A builder for Modern.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,38 +11,41 @@
11
11
  "type": "commonjs",
12
12
  "exports": {
13
13
  ".": {
14
- "types": "./dist/index.d.ts",
15
- "default": "./dist/index.js"
14
+ "types": "./dist/types/index.d.ts",
15
+ "node": {
16
+ "import": "./dist/esm-node/index.mjs",
17
+ "require": "./dist/cjs/index.js"
18
+ },
19
+ "default": "./dist/cjs/index.js"
16
20
  }
17
21
  },
18
- "main": "./dist/index.js",
19
- "types": "./dist/index.d.ts",
22
+ "main": "./dist/cjs/index.js",
23
+ "types": "./dist/types/index.d.ts",
20
24
  "files": [
21
25
  "compiled",
22
26
  "dist"
23
27
  ],
24
28
  "dependencies": {
25
- "@rsbuild/core": "1.6.15",
26
- "@rsbuild/plugin-assets-retry": "1.5.0",
27
- "@rsbuild/plugin-babel": "1.0.6",
28
- "@rsbuild/plugin-check-syntax": "1.6.0",
29
- "@rsbuild/plugin-css-minimizer": "1.1.0",
30
- "@rsbuild/plugin-less": "1.5.0",
31
- "@rsbuild/plugin-react": "1.4.2",
32
- "@rsbuild/plugin-rem": "1.0.4",
33
- "@rsbuild/plugin-sass": "1.4.0",
34
- "@rsbuild/plugin-source-build": "1.0.3",
35
- "@rsbuild/plugin-svgr": "1.2.3",
36
- "@rsbuild/plugin-type-check": "1.3.2",
37
- "@rsbuild/plugin-typed-css-modules": "1.2.0",
38
- "@swc/core": "1.14.0",
29
+ "@rsbuild/core": "2.0.0-beta.0",
30
+ "@rsbuild/plugin-assets-retry": "1.5.1",
31
+ "@rsbuild/plugin-check-syntax": "1.6.1",
32
+ "@rsbuild/plugin-css-minimizer": "1.1.1",
33
+ "@rsbuild/plugin-less": "1.6.0",
34
+ "@rsbuild/plugin-react": "1.4.4",
35
+ "@rsbuild/plugin-rem": "1.0.5",
36
+ "@rsbuild/plugin-sass": "1.5.0",
37
+ "@rsbuild/plugin-source-build": "1.0.4",
38
+ "@rsbuild/plugin-svgr": "1.3.0",
39
+ "@rsbuild/plugin-type-check": "1.3.3",
40
+ "@rsbuild/plugin-typed-css-modules": "1.2.1",
41
+ "@swc/core": "1.15.10",
39
42
  "@swc/helpers": "^0.5.17",
40
43
  "autoprefixer": "10.4.23",
41
44
  "browserslist": "4.28.1",
45
+ "core-js": "^3.48.0",
42
46
  "cssnano": "6.1.2",
43
47
  "html-minifier-terser": "^7.2.0",
44
- "jiti": "1.21.7",
45
- "lodash": "^4.17.21",
48
+ "lodash": "^4.17.23",
46
49
  "postcss": "^8.5.6",
47
50
  "postcss-custom-properties": "13.3.12",
48
51
  "postcss-flexbugs-fixes": "5.0.2",
@@ -51,28 +54,30 @@
51
54
  "postcss-media-minmax": "5.0.0",
52
55
  "postcss-nesting": "12.1.5",
53
56
  "postcss-page-break": "3.0.4",
54
- "rspack-manifest-plugin": "5.1.0",
57
+ "rspack-manifest-plugin": "5.2.1",
55
58
  "ts-deepmerge": "7.0.3",
56
- "@modern-js/flight-server-transform-plugin": "3.0.0-alpha.0",
57
- "@modern-js/utils": "3.0.0-alpha.0"
59
+ "tsx": "^4.21.0",
60
+ "@modern-js/flight-server-transform-plugin": "3.0.0-alpha.2",
61
+ "@modern-js/utils": "3.0.0-alpha.2"
58
62
  },
59
63
  "devDependencies": {
64
+ "@rslib/core": "0.19.3",
60
65
  "@types/html-minifier-terser": "^7.0.2",
61
- "@types/lodash": "^4.17.21",
66
+ "@types/lodash": "^4.17.23",
62
67
  "react": "^19.2.3",
63
- "terser": "^5.44.1",
68
+ "terser": "^5.46.0",
64
69
  "typescript": "^5.3.0",
65
- "@modern-js/types": "3.0.0-alpha.0",
66
- "@scripts/rstest-config": "2.66.0",
67
- "@scripts/build": "2.66.0"
70
+ "@modern-js/rslib": "2.68.10",
71
+ "@modern-js/types": "3.0.0-alpha.2",
72
+ "@scripts/rstest-config": "2.66.0"
68
73
  },
69
74
  "publishConfig": {
70
75
  "access": "public",
71
76
  "registry": "https://registry.npmjs.org/"
72
77
  },
73
78
  "scripts": {
74
- "build": "modern-lib build",
75
- "dev": "modern-lib build --watch",
79
+ "build": "rslib build",
80
+ "dev": "rslib build --watch",
76
81
  "test": "rstest run",
77
82
  "test:watch": "rstest watch"
78
83
  }