@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
@@ -0,0 +1,116 @@
1
+ import "node:module";
2
+ import { createRequire } from "node:module";
3
+ import node_path from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+ import { applyOptionsChain, isProd } from "@modern-js/utils";
6
+ import { logger } from "@rsbuild/core";
7
+ import { getCssSupport } from "../shared/getCssSupport.mjs";
8
+ const builderRequire = createRequire(import.meta.url);
9
+ const createRootRequire = (rootPath)=>createRequire(pathToFileURL(node_path.join(rootPath, 'package.json')).href);
10
+ const loadByResolver = (resolveWith, name)=>{
11
+ try {
12
+ return resolveWith(name);
13
+ } catch (error) {
14
+ const resolved = resolveWith.resolve(name);
15
+ return resolveWith(resolved);
16
+ }
17
+ };
18
+ const loadPostcssPlugin = (name, appRootPath)=>{
19
+ const resolvers = [
20
+ builderRequire,
21
+ createRootRequire(appRootPath),
22
+ createRootRequire(process.cwd())
23
+ ];
24
+ let firstError = null;
25
+ for (const resolveWith of resolvers)try {
26
+ return loadByResolver(resolveWith, name);
27
+ } catch (error) {
28
+ firstError ??= error;
29
+ }
30
+ throw firstError;
31
+ };
32
+ const importPostcssPlugin = (name, appRootPath)=>Promise.resolve(loadPostcssPlugin(name, appRootPath));
33
+ const clonePostCSSConfig = (config)=>({
34
+ ...config,
35
+ plugins: config.plugins ? [
36
+ ...config.plugins
37
+ ] : void 0
38
+ });
39
+ const postcssLoadConfig = builderRequire('postcss-load-config');
40
+ const userPostcssrcCache = new Map();
41
+ const loadUserPostcssrc = async (root)=>{
42
+ const cached = userPostcssrcCache.get(root);
43
+ if (cached) return clonePostCSSConfig(await cached);
44
+ const promise = postcssLoadConfig({}, root).catch((err)=>{
45
+ if (err?.message?.includes('No PostCSS Config found')) return {};
46
+ throw err;
47
+ });
48
+ userPostcssrcCache.set(root, promise);
49
+ return promise.then((config)=>{
50
+ userPostcssrcCache.set(root, config);
51
+ return clonePostCSSConfig(config);
52
+ });
53
+ };
54
+ const pluginPostcss = (options = {})=>({
55
+ name: 'builder:postcss-plugins',
56
+ pre: [
57
+ 'builder:environment-defaults-plugin'
58
+ ],
59
+ setup (api) {
60
+ const { autoprefixer } = options;
61
+ api.modifyEnvironmentConfig(async (config, { mergeEnvironmentConfig })=>{
62
+ if ('web' !== config.output.target) return config;
63
+ const cssSupport = getCssSupport(config.output.overrideBrowserslist);
64
+ const enableExtractCSS = !config.output?.injectStyles;
65
+ const enableCssMinify = !enableExtractCSS && isProd();
66
+ const cssnanoOptions = {
67
+ preset: [
68
+ 'default',
69
+ {
70
+ mergeLonghand: false,
71
+ normalizeUrl: false
72
+ }
73
+ ]
74
+ };
75
+ const plugins = await Promise.all([
76
+ importPostcssPlugin('postcss-flexbugs-fixes', api.context.rootPath),
77
+ !cssSupport.customProperties && importPostcssPlugin('postcss-custom-properties', api.context.rootPath),
78
+ !cssSupport.initial && importPostcssPlugin('postcss-initial', api.context.rootPath),
79
+ !cssSupport.pageBreak && importPostcssPlugin('postcss-page-break', api.context.rootPath),
80
+ !cssSupport.fontVariant && importPostcssPlugin('postcss-font-variant', api.context.rootPath),
81
+ !cssSupport.mediaMinmax && importPostcssPlugin('postcss-media-minmax', api.context.rootPath),
82
+ importPostcssPlugin('postcss-nesting', api.context.rootPath),
83
+ enableCssMinify && importPostcssPlugin('cssnano', api.context.rootPath).then((cssnano)=>cssnano(cssnanoOptions)),
84
+ importPostcssPlugin('autoprefixer', api.context.rootPath).then((autoprefixerPlugin)=>autoprefixerPlugin(applyOptionsChain({
85
+ flexbox: 'no-2009',
86
+ overrideBrowserslist: config.output.overrideBrowserslist
87
+ }, autoprefixer)))
88
+ ]).then((results)=>results.filter(Boolean));
89
+ const userOptions = await loadUserPostcssrc(api.context.rootPath);
90
+ return mergeEnvironmentConfig({
91
+ tools: {
92
+ postcss: (opts)=>{
93
+ if ('function' == typeof opts.postcssOptions) {
94
+ logger.warn('unexpected function type postcssOptions, the default postcss plugins will not be applied.');
95
+ return opts;
96
+ }
97
+ const existingOptions = opts.postcssOptions ?? {};
98
+ const mergedOptions = {
99
+ ...userOptions,
100
+ ...existingOptions
101
+ };
102
+ const userPlugins = userOptions.plugins ?? [];
103
+ const existingPlugins = existingOptions.plugins ?? [];
104
+ mergedOptions.plugins = [
105
+ ...userPlugins,
106
+ ...existingPlugins,
107
+ ...plugins
108
+ ];
109
+ opts.postcssOptions = mergedOptions;
110
+ }
111
+ }
112
+ }, config);
113
+ });
114
+ }
115
+ });
116
+ export { pluginPostcss };
@@ -0,0 +1,117 @@
1
+ import __rslib_shim_module__ from "node:module";
2
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
+ import path from "path";
4
+ import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
5
+ import { dirname as __rspack_dirname } from "node:path";
6
+ var rscConfig_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
7
+ const ASYNC_STORAGE_PATTERN = /universal[/\\]async_storage/;
8
+ const RSC_COMMON_LAYER = 'rsc-common';
9
+ const ENTRY_NAME_VAR = '__MODERN_JS_ENTRY_NAME';
10
+ const createVirtualModule = (content)=>`data:text/javascript,${encodeURIComponent(content)}`;
11
+ const isAsyncStorageExclude = (exclude)=>{
12
+ if ('string' == typeof exclude) return ASYNC_STORAGE_PATTERN.test(exclude);
13
+ if (exclude instanceof RegExp) return exclude.test('universal/async_storage') || exclude.test('universal\\async_storage');
14
+ return false;
15
+ };
16
+ function pluginRscConfig() {
17
+ return {
18
+ name: 'builder:rsc-config',
19
+ setup (api) {
20
+ let layersCache = null;
21
+ const getLayers = async ()=>{
22
+ if (!layersCache) {
23
+ const { Layers } = await import("rsbuild-plugin-rsc");
24
+ layersCache = Layers;
25
+ }
26
+ return layersCache;
27
+ };
28
+ api.modifyBundlerChain({
29
+ handler: (chain, { isServer })=>{
30
+ if (isServer) {
31
+ const routeFilePattern = /[/\\]routes[/\\](?:.*[/\\])?(?:layout|page|\$)\.[tj]sx?$/;
32
+ const appFilePattern = /[/\\]App\.[tj]sx?$/;
33
+ const combinedPattern = new RegExp(`(${routeFilePattern.source}|${appFilePattern.source})`);
34
+ let loaderPath;
35
+ try {
36
+ loaderPath = require.resolve('../shared/rsc/rsc-server-entry-loader');
37
+ } catch {
38
+ loaderPath = path.resolve(rscConfig_dirname, '../shared/rsc/rsc-server-entry-loader');
39
+ }
40
+ chain.module.rule('rsc-server-entry').test(/\.(tsx?|jsx?)$/).resource(combinedPattern).exclude.add(/node_modules/).end().use('rsc-server-entry-loader').loader(loaderPath).end();
41
+ }
42
+ },
43
+ order: 'pre'
44
+ });
45
+ api.modifyRspackConfig(async (config, utils)=>{
46
+ const isServer = 'node' === config.target || 'node' === utils.target || utils.environment?.name === 'server';
47
+ if (!isServer) return;
48
+ const Layers = await getLayers();
49
+ if (config.entry) {
50
+ const entries = config.entry;
51
+ const newEntries = {};
52
+ for (const [entryName, entryValue] of Object.entries(entries))if ('string' == typeof entryValue) newEntries[entryName] = {
53
+ import: entryValue,
54
+ layer: Layers.ssr
55
+ };
56
+ else if (Array.isArray(entryValue)) newEntries[entryName] = {
57
+ import: entryValue,
58
+ layer: Layers.ssr
59
+ };
60
+ else if ('object' == typeof entryValue && null !== entryValue) newEntries[entryName] = {
61
+ ...entryValue,
62
+ layer: Layers.ssr
63
+ };
64
+ else newEntries[entryName] = entryValue;
65
+ config.entry = newEntries;
66
+ }
67
+ if (config.module?.rules) {
68
+ const rules = config.module.rules;
69
+ for (const rule of rules)if (rule.layer === Layers.rsc) {
70
+ if (rule.exclude) {
71
+ if (!Array.isArray(rule.exclude)) rule.exclude = [
72
+ rule.exclude
73
+ ];
74
+ } else rule.exclude = [];
75
+ const hasExclude = rule.exclude.some(isAsyncStorageExclude);
76
+ if (!hasExclude) rule.exclude.push(ASYNC_STORAGE_PATTERN);
77
+ }
78
+ if (!Array.isArray(config.module.rules)) config.module.rules = [];
79
+ config.module.rules.push({
80
+ resource: ASYNC_STORAGE_PATTERN,
81
+ layer: RSC_COMMON_LAYER
82
+ });
83
+ }
84
+ });
85
+ api.modifyBundlerChain((chain, { isServer, isWebWorker })=>{
86
+ if (!isServer && !isWebWorker) {
87
+ const entries = chain.entryPoints.entries();
88
+ if (entries && 'object' == typeof entries) for (const entryName of Object.keys(entries)){
89
+ const entryPoint = chain.entry(entryName);
90
+ const code = `window.${ENTRY_NAME_VAR}="${entryName}";`;
91
+ entryPoint.add(createVirtualModule(code));
92
+ }
93
+ }
94
+ });
95
+ }
96
+ };
97
+ }
98
+ async function getRscPlugins(enableRsc, internalDirectory) {
99
+ if (enableRsc) {
100
+ const routesFileReg = new RegExp(`${internalDirectory.replace(/[/\\]/g, '[/\\\\]')}[/\\\\][^/\\\\]*[/\\\\]routes`);
101
+ const { pluginRSC } = await import("rsbuild-plugin-rsc");
102
+ return [
103
+ pluginRSC({
104
+ layers: {
105
+ rsc: [
106
+ /render[/\\].*[/\\]server[/\\]rsc/,
107
+ /AppProxy/,
108
+ routesFileReg
109
+ ]
110
+ }
111
+ }),
112
+ pluginRscConfig()
113
+ ];
114
+ }
115
+ return [];
116
+ }
117
+ export { getRscPlugins, pluginRscConfig };
@@ -0,0 +1,31 @@
1
+ import "node:module";
2
+ const isRsdoctorEnabled = (config)=>{
3
+ if (void 0 === config) return false;
4
+ if ('boolean' == typeof config) return config;
5
+ if ('boolean' == typeof config?.enabled) return config.enabled;
6
+ return true;
7
+ };
8
+ const getRsdoctorPluginOptions = (config)=>{
9
+ if (config && 'object' == typeof config) return {
10
+ disableClientServer: config.disableClientServer ?? true
11
+ };
12
+ return {
13
+ disableClientServer: true
14
+ };
15
+ };
16
+ const pluginRsdoctor = (config)=>{
17
+ if (!isRsdoctorEnabled(config)) return null;
18
+ const pluginOptions = getRsdoctorPluginOptions(config);
19
+ return {
20
+ name: 'builder:rsdoctor',
21
+ setup (api) {
22
+ api.modifyBundlerChain(async (chain)=>{
23
+ const { RsdoctorRspackPlugin } = await import("@rsdoctor/rspack-plugin");
24
+ chain.plugin('rsdoctor').use(RsdoctorRspackPlugin, [
25
+ pluginOptions
26
+ ]);
27
+ });
28
+ }
29
+ };
30
+ };
31
+ export { pluginRsdoctor };
@@ -0,0 +1,22 @@
1
+ import "node:module";
2
+ import { RUNTIME_CHUNK_NAME, RUNTIME_CHUNK_REGEX } from "../shared/utils.mjs";
3
+ const pluginRuntimeChunk = (disableInlineRuntimeChunk)=>({
4
+ name: 'builder:runtime-chunk',
5
+ setup (api) {
6
+ api.modifyBundlerChain(async (chain, { target, environment })=>{
7
+ if ('web' !== target) return;
8
+ const { config } = environment;
9
+ const { chunkSplit } = config.performance;
10
+ if (chunkSplit?.strategy !== 'all-in-one' && false !== config.splitChunks) chain.optimization.runtimeChunk({
11
+ name: RUNTIME_CHUNK_NAME
12
+ });
13
+ });
14
+ api.modifyRsbuildConfig((config)=>{
15
+ config.output ||= {};
16
+ if (disableInlineRuntimeChunk) return;
17
+ const originalConfig = api.getRsbuildConfig('original');
18
+ if (originalConfig.output?.inlineScripts === void 0) config.output.inlineScripts = RUNTIME_CHUNK_REGEX;
19
+ });
20
+ }
21
+ });
22
+ export { pluginRuntimeChunk };
@@ -0,0 +1,54 @@
1
+ import "node:module";
2
+ import { applyOptionsChain, isProd } from "@modern-js/utils";
3
+ import { merge } from "ts-deepmerge";
4
+ const defaultDevConfig = {
5
+ writeToDisk: (file)=>!file.includes('.hot-update.'),
6
+ hmr: true,
7
+ liveReload: true,
8
+ progressBar: true,
9
+ client: {
10
+ path: '/webpack-hmr',
11
+ overlay: false,
12
+ port: '<port>'
13
+ }
14
+ };
15
+ const transformToRsbuildServerOptions = (dev, devServer, server)=>{
16
+ const { host = '0.0.0.0', https, startUrl, beforeStartUrl, server: devServerConfig, ...devConfig } = dev;
17
+ const port = process.env.PORT ? Number(process.env.PORT) : server?.port ?? 8080;
18
+ const rsbuildDev = merge(defaultDevConfig, devConfig);
19
+ delete rsbuildDev.setupMiddlewares;
20
+ const legacyServerConfig = applyOptionsChain({}, devServer, {}, merge);
21
+ const serverCofig = {
22
+ compress: devServerConfig?.compress ?? legacyServerConfig.compress,
23
+ headers: devServerConfig?.headers ?? legacyServerConfig.headers,
24
+ historyApiFallback: devServerConfig?.historyApiFallback ?? legacyServerConfig.historyApiFallback,
25
+ proxy: devServerConfig?.proxy ?? legacyServerConfig.proxy
26
+ };
27
+ const rsbuildServer = isProd() ? {
28
+ publicDir: false,
29
+ htmlFallback: false,
30
+ printUrls: false
31
+ } : {
32
+ publicDir: false,
33
+ htmlFallback: false,
34
+ printUrls: false,
35
+ compress: serverCofig.compress,
36
+ headers: serverCofig.headers,
37
+ historyApiFallback: serverCofig.historyApiFallback,
38
+ proxy: serverCofig.proxy,
39
+ host,
40
+ port,
41
+ https: https ? https : void 0,
42
+ middlewareMode: true,
43
+ cors: server?.cors
44
+ };
45
+ if (!isProd() && startUrl) rsbuildServer.open = beforeStartUrl ? {
46
+ target: true === startUrl ? '//localhost:<port>' : startUrl,
47
+ before: beforeStartUrl
48
+ } : startUrl;
49
+ return {
50
+ rsbuildDev,
51
+ rsbuildServer
52
+ };
53
+ };
54
+ export { transformToRsbuildServerOptions };
@@ -0,0 +1,78 @@
1
+ import "node:module";
2
+ import browserslist from "browserslist";
3
+ const CSS_FEATURES_BROWSER = {
4
+ customProperties: {
5
+ and_chr: '49',
6
+ and_ff: '31',
7
+ android: '50',
8
+ chrome: '49',
9
+ edge: '15',
10
+ firefox: '31',
11
+ ios_saf: '9.3',
12
+ op_mob: '36',
13
+ opera: '36',
14
+ safari: '9.1',
15
+ samsung: '5.0'
16
+ },
17
+ initial: {
18
+ and_chr: '37',
19
+ and_ff: '27',
20
+ android: '37',
21
+ chrome: '37',
22
+ edge: '79',
23
+ firefox: '27',
24
+ ios_saf: '9.3',
25
+ op_mob: '24',
26
+ opera: '24',
27
+ safari: '9.1',
28
+ samsung: '3.0'
29
+ },
30
+ pageBreak: {
31
+ and_chr: '51',
32
+ and_ff: '92',
33
+ android: '51',
34
+ chrome: '51',
35
+ edge: '12',
36
+ firefox: '92',
37
+ ios_saf: '10',
38
+ op_mob: '37',
39
+ opera: '11.1',
40
+ safari: '10',
41
+ samsung: '5.0'
42
+ },
43
+ fontVariant: {
44
+ and_chr: '18',
45
+ and_ff: '34',
46
+ android: '4.4',
47
+ chrome: '1',
48
+ edge: '12',
49
+ firefox: '34',
50
+ ios_saf: '9.3',
51
+ op_mob: '12',
52
+ opera: '10',
53
+ safari: '9.1',
54
+ samsung: '1.0'
55
+ },
56
+ mediaMinmax: {
57
+ and_chr: '104',
58
+ and_ff: '109',
59
+ android: '104',
60
+ chrome: '104',
61
+ edge: '104',
62
+ firefox: '63',
63
+ opera: '91'
64
+ }
65
+ };
66
+ const getCssFeatureBrowsers = (feature)=>{
67
+ const featureBrowsers = CSS_FEATURES_BROWSER[feature];
68
+ return browserslist(Object.entries(featureBrowsers).map(([key, value])=>`${key} >= ${value}`));
69
+ };
70
+ const isFeatureSupported = (projectBrowsers, featureBrowsers)=>projectBrowsers.every((item)=>featureBrowsers.includes(item));
71
+ function getCssSupport(projectBrowserslist) {
72
+ const projectBrowsers = browserslist(projectBrowserslist);
73
+ return Object.keys(CSS_FEATURES_BROWSER).reduce((acc, key)=>{
74
+ acc[key] = isFeatureSupported(projectBrowsers, getCssFeatureBrowsers(key));
75
+ return acc;
76
+ }, {});
77
+ }
78
+ export { getCssSupport };
@@ -0,0 +1,13 @@
1
+ import "node:module";
2
+ const generateManifest = (seed, files, entries)=>{
3
+ const manifestFiles = files.reduce((manifest, file)=>{
4
+ manifest[file.name] = file.path;
5
+ return manifest;
6
+ }, seed);
7
+ const entrypointFiles = Object.keys(entries).reduce((previous, name)=>previous.concat(entries[name].filter((fileName)=>!fileName.endsWith('.map'))), []);
8
+ return {
9
+ files: manifestFiles,
10
+ entrypoints: entrypointFiles
11
+ };
12
+ };
13
+ export { generateManifest };
@@ -0,0 +1,174 @@
1
+ import "node:module";
2
+ import { mergeRsbuildConfig } from "@rsbuild/core";
3
+ import { pluginCssMinimizer } from "@rsbuild/plugin-css-minimizer";
4
+ import { pluginLess } from "@rsbuild/plugin-less";
5
+ import { pluginReact } from "@rsbuild/plugin-react";
6
+ import { pluginSass } from "@rsbuild/plugin-sass";
7
+ import { pluginDevtool } from "../plugins/devtools.mjs";
8
+ import { pluginEmitRouteFile } from "../plugins/emitRouteFile.mjs";
9
+ import { pluginEnvironmentDefaults } from "../plugins/environmentDefaults.mjs";
10
+ import { pluginGlobalVars } from "../plugins/globalVars.mjs";
11
+ import { pluginHtmlMinifierTerser } from "../plugins/htmlMinify.mjs";
12
+ import { pluginRuntimeChunk } from "../plugins/runtimeChunk.mjs";
13
+ import { transformToRsbuildServerOptions } from "./devServer.mjs";
14
+ import { NODE_MODULES_REGEX } from "./utils.mjs";
15
+ const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
16
+ const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
17
+ const isLooseCssModules = (path)=>{
18
+ if (NODE_MODULES_REGEX.test(path)) return CSS_MODULES_REGEX.test(path);
19
+ return !GLOBAL_CSS_REGEX.test(path);
20
+ };
21
+ function removeUndefinedKey(obj) {
22
+ Object.keys(obj).forEach((key)=>{
23
+ if (void 0 === obj[key]) delete obj[key];
24
+ });
25
+ return obj;
26
+ }
27
+ async function parseCommonConfig(builderConfig, options) {
28
+ const frameworkConfigPath = options?.frameworkConfigPath;
29
+ const { plugins: [...plugins] = [], splitChunks, performance: { rsdoctor: rsdoctorConfig, ...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;
30
+ let combinedAlias;
31
+ if (alias || resolve.alias) combinedAlias = [].concat(alias ?? []).concat(resolve.alias ?? []);
32
+ const rsbuildConfig = {
33
+ plugins,
34
+ splitChunks,
35
+ output: {
36
+ polyfill: 'ua' === polyfill ? 'off' : polyfill,
37
+ dataUriLimit,
38
+ sourceMap,
39
+ module,
40
+ ...outputConfig
41
+ },
42
+ resolve: {
43
+ ...resolve,
44
+ alias: combinedAlias
45
+ },
46
+ source: sourceConfig,
47
+ performance: performanceConfig,
48
+ html: htmlConfig,
49
+ tools: toolsConfig,
50
+ security: securityConfig,
51
+ environments
52
+ };
53
+ rsbuildConfig.tools.htmlPlugin = htmlPlugin;
54
+ rsbuildConfig.tools.lightningcssLoader ??= false;
55
+ const { html = {}, output = {}, source = {} } = rsbuildConfig;
56
+ source.transformImport = false === transformImport ? ()=>[] : transformImport;
57
+ if (!source.decorators) source.decorators = {
58
+ version: 'legacy'
59
+ };
60
+ output.charset ??= 'ascii';
61
+ if ('boolean' != typeof output.sourceMap) {
62
+ output.sourceMap ||= {};
63
+ output.sourceMap.css ??= 'production' !== process.env.NODE_ENV;
64
+ }
65
+ const { server: _server, worker, ...rsbuildDistPath } = distPath;
66
+ output.distPath = rsbuildDistPath;
67
+ output.distPath.html ??= 'html';
68
+ output.polyfill ??= 'entry';
69
+ if (disableCssModuleExtension) {
70
+ output.cssModules ||= {};
71
+ output.cssModules.auto ??= isLooseCssModules;
72
+ }
73
+ const extraConfig = {};
74
+ extraConfig.html ||= {};
75
+ extraConfig.html.outputStructure = outputStructure ?? 'nested';
76
+ html.title ??= '';
77
+ html.appIcon = appIcon;
78
+ extraConfig.tools ??= {};
79
+ if (false !== htmlPlugin) extraConfig.tools.htmlPlugin = (config)=>{
80
+ if ('function' == typeof config.templateParameters) {
81
+ const originFn = config.templateParameters;
82
+ config.templateParameters = (...args)=>{
83
+ const res = originFn(...args);
84
+ return {
85
+ title: config.title,
86
+ meta: void 0,
87
+ ...res
88
+ };
89
+ };
90
+ }
91
+ };
92
+ if (!dev.lazyCompilation) dev.lazyCompilation = false;
93
+ const { rsbuildDev, rsbuildServer } = transformToRsbuildServerOptions(dev || {}, devServer || {}, server || {});
94
+ rsbuildConfig.server = removeUndefinedKey(rsbuildServer);
95
+ rsbuildConfig.dev = removeUndefinedKey(rsbuildDev);
96
+ rsbuildConfig.html = html;
97
+ rsbuildConfig.output = output;
98
+ const rsbuildPlugins = [
99
+ pluginGlobalVars(globalVars),
100
+ pluginDevtool({
101
+ sourceMap
102
+ }),
103
+ pluginEmitRouteFile(),
104
+ pluginSass({
105
+ sassLoaderOptions: sass
106
+ }),
107
+ pluginLess({
108
+ lessLoaderOptions: less
109
+ }),
110
+ pluginEnvironmentDefaults(distPath),
111
+ pluginHtmlMinifierTerser()
112
+ ];
113
+ if (checkSyntax) {
114
+ const { pluginCheckSyntax } = await import("@rsbuild/plugin-check-syntax");
115
+ rsbuildPlugins.push(pluginCheckSyntax('boolean' == typeof checkSyntax ? {} : checkSyntax));
116
+ }
117
+ if (!disableTsChecker) {
118
+ const { pluginTypeCheck } = await import("@rsbuild/plugin-type-check");
119
+ rsbuildPlugins.push(pluginTypeCheck({
120
+ tsCheckerOptions: tsChecker
121
+ }));
122
+ }
123
+ if (convertToRem) {
124
+ const { pluginRem } = await import("@rsbuild/plugin-rem");
125
+ rsbuildPlugins.push(pluginRem('boolean' == typeof convertToRem ? {} : convertToRem));
126
+ }
127
+ if (enableCssModuleTSDeclaration) {
128
+ const { pluginTypedCSSModules } = await import("@rsbuild/plugin-typed-css-modules");
129
+ rsbuildPlugins.push(pluginTypedCSSModules());
130
+ }
131
+ rsbuildPlugins.push(pluginRuntimeChunk(builderConfig.output?.disableInlineRuntimeChunk));
132
+ const { sourceBuild } = builderConfig.experiments || {};
133
+ if (sourceBuild) {
134
+ const { pluginSourceBuild } = await import("@rsbuild/plugin-source-build");
135
+ rsbuildPlugins.push(pluginSourceBuild(true === sourceBuild ? {} : sourceBuild));
136
+ }
137
+ rsbuildPlugins.push(pluginReact());
138
+ if (!disableSvgr) {
139
+ const { pluginSvgr } = await import("@rsbuild/plugin-svgr");
140
+ rsbuildPlugins.push(pluginSvgr({
141
+ mixedImport: true,
142
+ svgrOptions: {
143
+ exportType: 'component' === svgDefaultExport ? 'default' : 'named'
144
+ }
145
+ }));
146
+ }
147
+ if (assetsRetry) {
148
+ const { pluginAssetsRetry } = await import("@rsbuild/plugin-assets-retry");
149
+ rsbuildPlugins.push(pluginAssetsRetry(assetsRetry));
150
+ }
151
+ if (frameworkConfigPath && false !== performanceConfig.buildCache) {
152
+ const buildCache = 'object' == typeof performanceConfig.buildCache ? performanceConfig.buildCache : {};
153
+ rsbuildConfig.performance.buildCache = {
154
+ ...buildCache,
155
+ buildDependencies: [
156
+ frameworkConfigPath,
157
+ ...buildCache.buildDependencies || []
158
+ ]
159
+ };
160
+ }
161
+ rsbuildPlugins.push(pluginCssMinimizer({
162
+ pluginOptions: minifyCss
163
+ }));
164
+ if (enableAssetManifest) {
165
+ const { pluginManifest } = await import("../plugins/manifest.mjs");
166
+ rsbuildPlugins.push(pluginManifest());
167
+ }
168
+ return {
169
+ rsbuildConfig: mergeRsbuildConfig(rsbuildConfig, extraConfig),
170
+ rsbuildPlugins,
171
+ rsdoctorConfig
172
+ };
173
+ }
174
+ export { isLooseCssModules, parseCommonConfig };
@@ -0,0 +1,8 @@
1
+ import "node:module";
2
+ function rscServerEntryLoader(source) {
3
+ this.cacheable(true);
4
+ const hasServerEntryDirective = source.includes("'use server-entry'") || source.includes('"use server-entry"') || source.includes('`use server-entry`');
5
+ if (hasServerEntryDirective) return source;
6
+ return `'use server-entry';\n${source}`;
7
+ }
8
+ export default rscServerEntryLoader;
@@ -0,0 +1,25 @@
1
+ import __rslib_shim_module__ from "node:module";
2
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
+ import path from "path";
4
+ import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
5
+ import { dirname as __rspack_dirname } from "node: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-rspack/client.browser'] = emptyModulePath;
21
+ });
22
+ }
23
+ };
24
+ }
25
+ export { rscClientBrowserFallbackPlugin };
@@ -0,0 +1,3 @@
1
+ import "node:module";
2
+ const rscEmptyModule = {};
3
+ export default rscEmptyModule;