@modern-js/uni-builder 0.0.0-nightly-20231218170633 → 0.0.0-nightly-20231219170633

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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import type { CreateUniBuilderOptions } from './types';
2
- export declare function createUniBuilder(options: CreateUniBuilderOptions): Promise<import("@rsbuild/shared").RsbuildInstance<import("@rsbuild/shared").RsbuildProvider>>;
3
- export type { BundlerChain } from '@rsbuild/shared';
2
+ export type { CreateUniBuilderOptions };
3
+ export type { BundlerChain, RsbuildPlugin } from '@rsbuild/shared';
4
4
  export type { BuilderConfig } from './types';
5
+ export type { StartDevServerOptions } from './shared/devServer';
6
+ export declare function createUniBuilder(options: CreateUniBuilderOptions): Promise<Omit<import("@rsbuild/shared").RsbuildInstance<import("@rsbuild/shared").RsbuildProvider>, "startDevServer"> & {
7
+ startDevServer: (options: import("./shared/devServer").StartDevServerOptions) => Promise<import("@rsbuild/shared").StartServerResult>;
8
+ }>;
9
+ export { logger } from '@rsbuild/core';
5
10
  export { RUNTIME_CHUNK_NAME } from './shared/constants';
package/dist/index.js CHANGED
@@ -19,11 +19,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var src_exports = {};
20
20
  __export(src_exports, {
21
21
  RUNTIME_CHUNK_NAME: () => import_constants.RUNTIME_CHUNK_NAME,
22
- createUniBuilder: () => createUniBuilder
22
+ createUniBuilder: () => createUniBuilder,
23
+ logger: () => import_core.logger
23
24
  });
24
25
  module.exports = __toCommonJS(src_exports);
25
26
  var import_rspack = require("./rspack");
26
27
  var import_webpack = require("./webpack");
28
+ var import_core = require("@rsbuild/core");
27
29
  var import_constants = require("./shared/constants");
28
30
  async function createUniBuilder(options) {
29
31
  return options.bundlerType === "rspack" ? (0, import_rspack.createRspackBuilder)(options) : (0, import_webpack.createWebpackBuilder)(options);
@@ -31,5 +33,6 @@ async function createUniBuilder(options) {
31
33
  // Annotate the CommonJS export names for ESM import in node:
32
34
  0 && (module.exports = {
33
35
  RUNTIME_CHUNK_NAME,
34
- createUniBuilder
36
+ createUniBuilder,
37
+ logger
35
38
  });
@@ -1,8 +1,18 @@
1
1
  import type { RsbuildConfig, RsbuildPlugin, RsbuildInstance } from '@rsbuild/core';
2
- import type { RsbuildProvider } from '@rsbuild/shared';
2
+ import type { RsbuildProvider, StartServerResult } from '@rsbuild/shared';
3
3
  import type { UniBuilderRspackConfig, CreateRspackBuilderOptions, CreateBuilderCommonOptions } from '../types';
4
+ import type { StartDevServerOptions } from '../shared/devServer';
4
5
  export declare function parseConfig(uniBuilderConfig: UniBuilderRspackConfig, options: CreateBuilderCommonOptions): Promise<{
5
6
  rsbuildConfig: RsbuildConfig;
6
7
  rsbuildPlugins: RsbuildPlugin[];
7
8
  }>;
8
- export declare function createRspackBuilder(options: CreateRspackBuilderOptions): Promise<RsbuildInstance<RsbuildProvider>>;
9
+ type UniBuilderInstance = Omit<RsbuildInstance<RsbuildProvider>, 'startDevServer'> & {
10
+ /**
11
+ * should be used in conjunction with the upper-layer framework:
12
+ *
13
+ * missing route.json (required in modern server)
14
+ */
15
+ startDevServer: (options: StartDevServerOptions) => Promise<StartServerResult>;
16
+ };
17
+ export declare function createRspackBuilder(options: CreateRspackBuilderOptions): Promise<UniBuilderInstance>;
18
+ export {};
@@ -34,7 +34,6 @@ __export(rspack_exports, {
34
34
  module.exports = __toCommonJS(rspack_exports);
35
35
  var import_core = require("@rsbuild/core");
36
36
  var import_parseCommonConfig = require("../shared/parseCommonConfig");
37
- var import_plugin_styled_components = require("@rsbuild/plugin-styled-components");
38
37
  async function parseConfig(uniBuilderConfig, options) {
39
38
  var _uniBuilderConfig_output, _uniBuilderConfig_tools, _uniBuilderConfig_tools1;
40
39
  const { rsbuildConfig, rsbuildPlugins } = await (0, import_parseCommonConfig.parseCommonConfig)(uniBuilderConfig, options);
@@ -49,7 +48,11 @@ async function parseConfig(uniBuilderConfig, options) {
49
48
  babelLoaderOptions: (_uniBuilderConfig_tools2 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools2 === void 0 ? void 0 : _uniBuilderConfig_tools2.babel
50
49
  }));
51
50
  }
52
- rsbuildPlugins.push((0, import_plugin_styled_components.pluginStyledComponents)((_uniBuilderConfig_tools1 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools1 === void 0 ? void 0 : _uniBuilderConfig_tools1.styledComponents));
51
+ if (((_uniBuilderConfig_tools1 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools1 === void 0 ? void 0 : _uniBuilderConfig_tools1.styledComponents) !== false) {
52
+ var _uniBuilderConfig_tools3;
53
+ const { pluginStyledComponents } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-styled-components")));
54
+ rsbuildPlugins.push(pluginStyledComponents((_uniBuilderConfig_tools3 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools3 === void 0 ? void 0 : _uniBuilderConfig_tools3.styledComponents));
55
+ }
53
56
  return {
54
57
  rsbuildConfig,
55
58
  rsbuildPlugins
@@ -66,7 +69,13 @@ async function createRspackBuilder(options) {
66
69
  rsbuildConfig
67
70
  });
68
71
  rsbuild.addPlugins(rsbuildPlugins);
69
- return rsbuild;
72
+ return {
73
+ ...rsbuild,
74
+ startDevServer: async (options2 = {}) => {
75
+ const { startDevServer } = await Promise.resolve().then(() => __toESM(require("../shared/devServer")));
76
+ return startDevServer(rsbuild, options2, config);
77
+ }
78
+ };
70
79
  }
71
80
  // Annotate the CommonJS export names for ESM import in node:
72
81
  0 && (module.exports = {
@@ -0,0 +1,13 @@
1
+ import { StartDevServerOptions as RsbuildStartDevServerOptions, StartServerResult, RsbuildInstance } from '@rsbuild/shared';
2
+ import type { ModernDevServerOptionsNew } from '@modern-js/server';
3
+ import { BuilderConfig } from '../types';
4
+ type ServerOptions = Partial<Omit<ModernDevServerOptionsNew, 'config'>> & {
5
+ config?: Partial<ModernDevServerOptionsNew['config']>;
6
+ };
7
+ export type StartDevServerOptions = Omit<RsbuildStartDevServerOptions, 'printURLs'> & {
8
+ apiOnly?: boolean;
9
+ defaultPort?: number;
10
+ serverOptions?: ServerOptions;
11
+ };
12
+ export declare function startDevServer(rsbuild: RsbuildInstance, options: StartDevServerOptions | undefined, builderConfig: BuilderConfig): Promise<StartServerResult>;
13
+ export {};
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var devServer_exports = {};
30
+ __export(devServer_exports, {
31
+ startDevServer: () => startDevServer
32
+ });
33
+ module.exports = __toCommonJS(devServer_exports);
34
+ var import_shared = require("@rsbuild/shared");
35
+ const getServerOptions = (builderConfig) => {
36
+ var _builderConfig_output_distPath, _builderConfig_output, _builderConfig_output1, _builderConfig_output2;
37
+ return {
38
+ output: {
39
+ path: (_builderConfig_output = builderConfig.output) === null || _builderConfig_output === void 0 ? void 0 : (_builderConfig_output_distPath = _builderConfig_output.distPath) === null || _builderConfig_output_distPath === void 0 ? void 0 : _builderConfig_output_distPath.root,
40
+ assetPrefix: (_builderConfig_output1 = builderConfig.output) === null || _builderConfig_output1 === void 0 ? void 0 : _builderConfig_output1.assetPrefix,
41
+ distPath: (_builderConfig_output2 = builderConfig.output) === null || _builderConfig_output2 === void 0 ? void 0 : _builderConfig_output2.distPath
42
+ },
43
+ source: {
44
+ alias: {}
45
+ },
46
+ html: {},
47
+ tools: {
48
+ babel: {}
49
+ },
50
+ server: {},
51
+ runtime: {},
52
+ bff: {}
53
+ };
54
+ };
55
+ const getDevServerOptions = async ({ builderConfig, serverOptions, port }) => {
56
+ var _builderConfig_dev, _builderConfig_dev1, _builderConfig_dev2, _builderConfig_tools;
57
+ var _builderConfig_dev_hmr, _builderConfig_dev_hmr1;
58
+ const defaultDevConfig = (0, import_shared.deepmerge)(
59
+ {
60
+ hot: (_builderConfig_dev_hmr = (_builderConfig_dev = builderConfig.dev) === null || _builderConfig_dev === void 0 ? void 0 : _builderConfig_dev.hmr) !== null && _builderConfig_dev_hmr !== void 0 ? _builderConfig_dev_hmr : true,
61
+ watch: true,
62
+ client: {
63
+ port: port.toString()
64
+ },
65
+ port,
66
+ liveReload: (_builderConfig_dev_hmr1 = (_builderConfig_dev1 = builderConfig.dev) === null || _builderConfig_dev1 === void 0 ? void 0 : _builderConfig_dev1.hmr) !== null && _builderConfig_dev_hmr1 !== void 0 ? _builderConfig_dev_hmr1 : true,
67
+ https: (_builderConfig_dev2 = builderConfig.dev) === null || _builderConfig_dev2 === void 0 ? void 0 : _builderConfig_dev2.https
68
+ },
69
+ // merge devServerOptions from serverOptions
70
+ serverOptions.dev || {}
71
+ );
72
+ const devConfig = (0, import_shared.mergeChainedOptions)({
73
+ defaults: defaultDevConfig,
74
+ options: (_builderConfig_tools = builderConfig.tools) === null || _builderConfig_tools === void 0 ? void 0 : _builderConfig_tools.devServer,
75
+ mergeFn: import_shared.deepmerge
76
+ });
77
+ const defaultConfig = getServerOptions(builderConfig);
78
+ const config = serverOptions.config ? (0, import_shared.deepmerge)(defaultConfig, serverOptions.config) : defaultConfig;
79
+ return {
80
+ config,
81
+ devConfig
82
+ };
83
+ };
84
+ async function startDevServer(rsbuild, options = {}, builderConfig) {
85
+ (0, import_shared.debug)("create dev server");
86
+ const { ServerForRsbuild } = await Promise.resolve().then(() => __toESM(require("@modern-js/server")));
87
+ const rsbuildServer = await rsbuild.getServerAPIs(options);
88
+ const { serverOptions = {} } = options;
89
+ const { config, devConfig } = await getDevServerOptions({
90
+ builderConfig,
91
+ serverOptions,
92
+ port: rsbuildServer.config.port
93
+ });
94
+ const compileMiddlewareAPI = options.apiOnly ? void 0 : await rsbuildServer.startCompile();
95
+ const server = new ServerForRsbuild({
96
+ pwd: rsbuild.context.rootPath,
97
+ ...serverOptions,
98
+ rsbuild,
99
+ getMiddlewares: (config2) => rsbuildServer.getMiddlewares({
100
+ compileMiddlewareAPI,
101
+ overrides: config2
102
+ }),
103
+ dev: devConfig,
104
+ config
105
+ });
106
+ const { config: { port, host } } = rsbuildServer;
107
+ (0, import_shared.debug)("create dev server done");
108
+ await rsbuildServer.beforeStart();
109
+ const protocol = devConfig.https ? "https" : "http";
110
+ const urls = (0, import_shared.getAddressUrls)(protocol, port, host);
111
+ (0, import_shared.debug)("listen dev server");
112
+ await server.init();
113
+ return new Promise((resolve) => {
114
+ server.listen({
115
+ host,
116
+ port
117
+ }, async (err) => {
118
+ if (err) {
119
+ throw err;
120
+ }
121
+ (0, import_shared.debug)("listen dev server done");
122
+ await rsbuildServer.afterStart({
123
+ port,
124
+ routes: [
125
+ {
126
+ route: "/",
127
+ name: "index"
128
+ }
129
+ ]
130
+ });
131
+ resolve({
132
+ port,
133
+ urls: urls.map((item) => item.url),
134
+ server
135
+ });
136
+ });
137
+ });
138
+ }
139
+ // Annotate the CommonJS export names for ESM import in node:
140
+ 0 && (module.exports = {
141
+ startDevServer
142
+ });
@@ -1,5 +1,5 @@
1
1
  import { type RsbuildPlugin, type RsbuildConfig } from '@rsbuild/core';
2
- import type { UniBuilderRspackConfig, UniBuilderWebpackConfig, CreateBuilderCommonOptions } from '../types';
2
+ import type { CreateBuilderCommonOptions, UniBuilderRspackConfig, UniBuilderWebpackConfig } from '../types';
3
3
  /** Determine if a file path is a CSS module when disableCssModuleExtension is enabled. */
4
4
  export declare const isLooseCssModules: (path: string) => boolean;
5
5
  export declare function parseCommonConfig<B = 'rspack' | 'webpack'>(uniBuilderConfig: B extends 'rspack' ? UniBuilderRspackConfig : UniBuilderWebpackConfig, options: CreateBuilderCommonOptions): Promise<{
@@ -34,23 +34,15 @@ __export(parseCommonConfig_exports, {
34
34
  module.exports = __toCommonJS(parseCommonConfig_exports);
35
35
  var import_shared = require("@rsbuild/shared");
36
36
  var import_core = require("@rsbuild/core");
37
- var import_plugin_rem = require("@rsbuild/plugin-rem");
38
- var import_plugin_pug = require("@rsbuild/plugin-pug");
39
- var import_plugin_assets_retry = require("@rsbuild/plugin-assets-retry");
40
- var import_plugin_type_check = require("@rsbuild/plugin-type-check");
41
37
  var import_plugin_react = require("@rsbuild/plugin-react");
42
- var import_fallback = require("./plugins/fallback");
43
38
  var import_globalVars = require("./plugins/globalVars");
44
39
  var import_runtimeChunk = require("./plugins/runtimeChunk");
45
40
  var import_frameworkConfig = require("./plugins/frameworkConfig");
46
- var import_mainFields = require("./plugins/mainFields");
47
- var import_extensionPrefix = require("./plugins/extensionPrefix");
48
41
  var import_splitChunk = require("./plugins/splitChunk");
49
- var import_plugin_svgr = require("@rsbuild/plugin-svgr");
50
- var import_plugin_check_syntax = require("@rsbuild/plugin-check-syntax");
51
42
  var import_plugin_css_minimizer = require("@rsbuild/plugin-css-minimizer");
52
43
  var import_postcssLegacy = require("./plugins/postcssLegacy");
53
44
  var import_devtools = require("./plugins/devtools");
45
+ var import_emitRouteFile = require("./plugins/emitRouteFile");
54
46
  const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
55
47
  const isLooseCssModules = (path) => {
56
48
  if (import_shared.NODE_MODULES_REGEX.test(path)) {
@@ -58,31 +50,6 @@ const isLooseCssModules = (path) => {
58
50
  }
59
51
  return !GLOBAL_CSS_REGEX.test(path);
60
52
  };
61
- const genHttpsOptions = async (userOptions, cwd) => {
62
- const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
63
- if (!httpsOptions.key || !httpsOptions.cert) {
64
- let devcertPath;
65
- try {
66
- devcertPath = require.resolve("devcert", {
67
- paths: [
68
- cwd,
69
- __dirname
70
- ]
71
- });
72
- } catch (err) {
73
- const command = import_shared.color.bold(import_shared.color.yellow(`npm add devcert@1.2.2 -D`));
74
- import_shared.logger.error(`You have enabled "dev.https" option, but the "devcert" package is not installed.`);
75
- import_shared.logger.error(`Please run ${command} to install manually, otherwise the https can not work.`);
76
- throw new Error('[https] "devcert" is not found.');
77
- }
78
- const devcert = require(devcertPath);
79
- const selfsign = await devcert.certificateFor([
80
- "localhost"
81
- ]);
82
- return selfsign;
83
- }
84
- return httpsOptions;
85
- };
86
53
  function removeUndefinedKey(obj) {
87
54
  Object.keys(obj).forEach((key) => {
88
55
  if (obj[key] === void 0) {
@@ -124,14 +91,11 @@ async function getBrowserslistWithDefault(path, config, target) {
124
91
  return DEFAULT_BROWSERSLIST[target];
125
92
  }
126
93
  async function parseCommonConfig(uniBuilderConfig, options) {
127
- var _uniBuilderConfig_output, _uniBuilderConfig_output1, _uniBuilderConfig_output2, _uniBuilderConfig_html, _uniBuilderConfig_html1, _uniBuilderConfig_html2, _uniBuilderConfig_html3, _uniBuilderConfig_html4, _uniBuilderConfig_html5, _tools_devServer, _tools_devServer1, _tools_devServer2, _tools_devServer3, _tools_devServer4, _tools_devServer5, _tools_devServer6, _tools_devServer_devMiddleware, _tools_devServer7, _tools_devServer8, _tools_devServer_before, _tools_devServer9, _tools_devServer_after, _tools_devServer10, _tools_devServer11, _uniBuilderConfig_source, _uniBuilderConfig_output3, _uniBuilderConfig_security, _uniBuilderConfig_output4, _uniBuilderConfig_output5, _uniBuilderConfig_source1, _uniBuilderConfig_source2, _uniBuilderConfig_output6, _uniBuilderConfig_output7, _uniBuilderConfig_experiments, _uniBuilderConfig_tools, _uniBuilderConfig_output8, _uniBuilderConfig_output9, _uniBuilderConfig_tools1;
128
- var _output, _output_distPath, _output1, _extraConfig, _html;
94
+ var _uniBuilderConfig_output, _uniBuilderConfig_output1, _uniBuilderConfig_output2, _uniBuilderConfig_html, _uniBuilderConfig_html1, _uniBuilderConfig_html2, _uniBuilderConfig_html3, _uniBuilderConfig_html4, _uniBuilderConfig_html5, _uniBuilderConfig_source, _uniBuilderConfig_output3, _uniBuilderConfig_security, _uniBuilderConfig_output4, _uniBuilderConfig_output5, _uniBuilderConfig_source1, _uniBuilderConfig_source2, _uniBuilderConfig_output6, _uniBuilderConfig_output7, _uniBuilderConfig_experiments, _uniBuilderConfig_tools, _uniBuilderConfig_output8, _uniBuilderConfig_output9, _uniBuilderConfig_tools1;
95
+ var _output, _output_distPath, _output1, _extraConfig, _html, _dev;
129
96
  const { cwd, frameworkConfigPath, entry, target } = options;
130
97
  const rsbuildConfig = (0, import_shared.deepmerge)({}, uniBuilderConfig);
131
98
  const { dev = {}, html = {}, output = {}, tools = {} } = rsbuildConfig;
132
- if (dev.progressBar === void 0) {
133
- dev.progressBar = true;
134
- }
135
99
  if (output.cssModuleLocalIdentName) {
136
100
  var _output2;
137
101
  (_output2 = output).cssModules || (_output2.cssModules = {});
@@ -205,38 +169,15 @@ async function parseCommonConfig(uniBuilderConfig, options) {
205
169
  extraConfig.html.templateParameters = (_, { entryName }) => uniBuilderConfig.html.templateParametersByEntries[entryName];
206
170
  delete html.templateParametersByEntries;
207
171
  }
208
- const server = (0, import_shared.isProd)() ? {
209
- publicDir: false
210
- } : {
211
- https: ((_tools_devServer = tools.devServer) === null || _tools_devServer === void 0 ? void 0 : _tools_devServer.https) || dev.https ? await genHttpsOptions(((_tools_devServer1 = tools.devServer) === null || _tools_devServer1 === void 0 ? void 0 : _tools_devServer1.https) || dev.https, cwd) : void 0,
172
+ if (dev.progressBar === void 0) {
173
+ dev.progressBar = true;
174
+ }
175
+ var _writeToDisk;
176
+ (_writeToDisk = (_dev = dev).writeToDisk) !== null && _writeToDisk !== void 0 ? _writeToDisk : _dev.writeToDisk = (file) => !file.includes(".hot-update.");
177
+ const server = (0, import_shared.isProd)() ? {} : {
212
178
  port: dev.port,
213
- host: dev.host,
214
- compress: (_tools_devServer2 = tools.devServer) === null || _tools_devServer2 === void 0 ? void 0 : _tools_devServer2.compress,
215
- headers: (_tools_devServer3 = tools.devServer) === null || _tools_devServer3 === void 0 ? void 0 : _tools_devServer3.headers,
216
- historyApiFallback: (_tools_devServer4 = tools.devServer) === null || _tools_devServer4 === void 0 ? void 0 : _tools_devServer4.historyApiFallback,
217
- proxy: (_tools_devServer5 = tools.devServer) === null || _tools_devServer5 === void 0 ? void 0 : _tools_devServer5.proxy,
218
- publicDir: false
179
+ host: dev.host
219
180
  };
220
- dev.client = (_tools_devServer6 = tools.devServer) === null || _tools_devServer6 === void 0 ? void 0 : _tools_devServer6.client;
221
- var _tools_devServer_devMiddleware_writeToDisk;
222
- dev.writeToDisk = (_tools_devServer_devMiddleware_writeToDisk = (_tools_devServer7 = tools.devServer) === null || _tools_devServer7 === void 0 ? void 0 : (_tools_devServer_devMiddleware = _tools_devServer7.devMiddleware) === null || _tools_devServer_devMiddleware === void 0 ? void 0 : _tools_devServer_devMiddleware.writeToDisk) !== null && _tools_devServer_devMiddleware_writeToDisk !== void 0 ? _tools_devServer_devMiddleware_writeToDisk : true;
223
- if (((_tools_devServer8 = tools.devServer) === null || _tools_devServer8 === void 0 ? void 0 : _tools_devServer8.hot) === false) {
224
- dev.hmr = false;
225
- }
226
- if (((_tools_devServer9 = tools.devServer) === null || _tools_devServer9 === void 0 ? void 0 : (_tools_devServer_before = _tools_devServer9.before) === null || _tools_devServer_before === void 0 ? void 0 : _tools_devServer_before.length) || ((_tools_devServer10 = tools.devServer) === null || _tools_devServer10 === void 0 ? void 0 : (_tools_devServer_after = _tools_devServer10.after) === null || _tools_devServer_after === void 0 ? void 0 : _tools_devServer_after.length)) {
227
- var _tools_devServer12;
228
- dev.setupMiddlewares = [
229
- ...((_tools_devServer12 = tools.devServer) === null || _tools_devServer12 === void 0 ? void 0 : _tools_devServer12.setupMiddlewares) || [],
230
- (middlewares) => {
231
- var _tools_devServer14, _tools_devServer15;
232
- middlewares.unshift(...((_tools_devServer14 = tools.devServer) === null || _tools_devServer14 === void 0 ? void 0 : _tools_devServer14.before) || []);
233
- middlewares.push(...((_tools_devServer15 = tools.devServer) === null || _tools_devServer15 === void 0 ? void 0 : _tools_devServer15.after) || []);
234
- }
235
- ];
236
- } else if ((_tools_devServer11 = tools.devServer) === null || _tools_devServer11 === void 0 ? void 0 : _tools_devServer11.setupMiddlewares) {
237
- var _tools_devServer13;
238
- dev.setupMiddlewares = (_tools_devServer13 = tools.devServer) === null || _tools_devServer13 === void 0 ? void 0 : _tools_devServer13.setupMiddlewares;
239
- }
240
181
  delete tools.devServer;
241
182
  delete dev.https;
242
183
  delete dev.port;
@@ -256,15 +197,18 @@ async function parseCommonConfig(uniBuilderConfig, options) {
256
197
  (0, import_globalVars.pluginGlobalVars)((_uniBuilderConfig_source = uniBuilderConfig.source) === null || _uniBuilderConfig_source === void 0 ? void 0 : _uniBuilderConfig_source.globalVars),
257
198
  (0, import_devtools.pluginDevtool)({
258
199
  disableSourceMap: (_uniBuilderConfig_output3 = uniBuilderConfig.output) === null || _uniBuilderConfig_output3 === void 0 ? void 0 : _uniBuilderConfig_output3.disableSourceMap
259
- })
200
+ }),
201
+ (0, import_emitRouteFile.pluginEmitRouteFile)()
260
202
  ];
261
203
  const checkSyntaxOptions = (_uniBuilderConfig_security = uniBuilderConfig.security) === null || _uniBuilderConfig_security === void 0 ? void 0 : _uniBuilderConfig_security.checkSyntax;
262
204
  if (checkSyntaxOptions) {
263
- rsbuildPlugins.push((0, import_plugin_check_syntax.pluginCheckSyntax)(typeof checkSyntaxOptions === "boolean" ? {} : checkSyntaxOptions));
205
+ const { pluginCheckSyntax } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-check-syntax")));
206
+ rsbuildPlugins.push(pluginCheckSyntax(typeof checkSyntaxOptions === "boolean" ? {} : checkSyntaxOptions));
264
207
  }
265
208
  if (!((_uniBuilderConfig_output4 = uniBuilderConfig.output) === null || _uniBuilderConfig_output4 === void 0 ? void 0 : _uniBuilderConfig_output4.disableTsChecker)) {
266
209
  var _uniBuilderConfig_tools2;
267
- rsbuildPlugins.push((0, import_plugin_type_check.pluginTypeCheck)({
210
+ const { pluginTypeCheck } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-type-check")));
211
+ rsbuildPlugins.push(pluginTypeCheck({
268
212
  forkTsCheckerOptions: (_uniBuilderConfig_tools2 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools2 === void 0 ? void 0 : _uniBuilderConfig_tools2.tsChecker
269
213
  }));
270
214
  delete output.disableTsChecker;
@@ -272,7 +216,8 @@ async function parseCommonConfig(uniBuilderConfig, options) {
272
216
  }
273
217
  if (!((_uniBuilderConfig_output5 = uniBuilderConfig.output) === null || _uniBuilderConfig_output5 === void 0 ? void 0 : _uniBuilderConfig_output5.disableSvgr)) {
274
218
  var _uniBuilderConfig_output13;
275
- rsbuildPlugins.push((0, import_plugin_svgr.pluginSvgr)({
219
+ const { pluginSvgr } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-svgr")));
220
+ rsbuildPlugins.push(pluginSvgr({
276
221
  svgDefaultExport: ((_uniBuilderConfig_output13 = uniBuilderConfig.output) === null || _uniBuilderConfig_output13 === void 0 ? void 0 : _uniBuilderConfig_output13.svgDefaultExport) || "url"
277
222
  }));
278
223
  delete output.disableSvgr;
@@ -280,15 +225,18 @@ async function parseCommonConfig(uniBuilderConfig, options) {
280
225
  }
281
226
  if ((_uniBuilderConfig_source1 = uniBuilderConfig.source) === null || _uniBuilderConfig_source1 === void 0 ? void 0 : _uniBuilderConfig_source1.resolveMainFields) {
282
227
  var _uniBuilderConfig_source3;
283
- rsbuildPlugins.push((0, import_mainFields.pluginMainFields)((_uniBuilderConfig_source3 = uniBuilderConfig.source) === null || _uniBuilderConfig_source3 === void 0 ? void 0 : _uniBuilderConfig_source3.resolveMainFields));
228
+ const { pluginMainFields } = await Promise.resolve().then(() => __toESM(require("./plugins/mainFields")));
229
+ rsbuildPlugins.push(pluginMainFields((_uniBuilderConfig_source3 = uniBuilderConfig.source) === null || _uniBuilderConfig_source3 === void 0 ? void 0 : _uniBuilderConfig_source3.resolveMainFields));
284
230
  }
285
231
  if ((_uniBuilderConfig_source2 = uniBuilderConfig.source) === null || _uniBuilderConfig_source2 === void 0 ? void 0 : _uniBuilderConfig_source2.resolveExtensionPrefix) {
286
232
  var _uniBuilderConfig_source4;
287
- rsbuildPlugins.push((0, import_extensionPrefix.pluginExtensionPrefix)((_uniBuilderConfig_source4 = uniBuilderConfig.source) === null || _uniBuilderConfig_source4 === void 0 ? void 0 : _uniBuilderConfig_source4.resolveExtensionPrefix));
233
+ const { pluginExtensionPrefix } = await Promise.resolve().then(() => __toESM(require("./plugins/extensionPrefix")));
234
+ rsbuildPlugins.push(pluginExtensionPrefix((_uniBuilderConfig_source4 = uniBuilderConfig.source) === null || _uniBuilderConfig_source4 === void 0 ? void 0 : _uniBuilderConfig_source4.resolveExtensionPrefix));
288
235
  }
289
236
  const remOptions = (_uniBuilderConfig_output6 = uniBuilderConfig.output) === null || _uniBuilderConfig_output6 === void 0 ? void 0 : _uniBuilderConfig_output6.convertToRem;
290
237
  if (remOptions) {
291
- rsbuildPlugins.push((0, import_plugin_rem.pluginRem)(typeof remOptions === "boolean" ? {} : remOptions));
238
+ const { pluginRem } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-rem")));
239
+ rsbuildPlugins.push(pluginRem(typeof remOptions === "boolean" ? {} : remOptions));
292
240
  }
293
241
  rsbuildPlugins.push((0, import_runtimeChunk.pluginRuntimeChunk)((_uniBuilderConfig_output7 = uniBuilderConfig.output) === null || _uniBuilderConfig_output7 === void 0 ? void 0 : _uniBuilderConfig_output7.disableInlineRuntimeChunk));
294
242
  if ((_uniBuilderConfig_experiments = uniBuilderConfig.experiments) === null || _uniBuilderConfig_experiments === void 0 ? void 0 : _uniBuilderConfig_experiments.sourceBuild) {
@@ -298,16 +246,19 @@ async function parseCommonConfig(uniBuilderConfig, options) {
298
246
  rsbuildPlugins.push((0, import_plugin_react.pluginReact)());
299
247
  const pugOptions = (_uniBuilderConfig_tools = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools === void 0 ? void 0 : _uniBuilderConfig_tools.pug;
300
248
  if (pugOptions) {
301
- rsbuildPlugins.push((0, import_plugin_pug.pluginPug)(typeof pugOptions === "boolean" ? {} : {
249
+ const { pluginPug } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-pug")));
250
+ rsbuildPlugins.push(pluginPug(typeof pugOptions === "boolean" ? {} : {
302
251
  pugOptions
303
252
  }));
304
253
  }
305
254
  if ((_uniBuilderConfig_output8 = uniBuilderConfig.output) === null || _uniBuilderConfig_output8 === void 0 ? void 0 : _uniBuilderConfig_output8.assetsRetry) {
306
255
  var _uniBuilderConfig_output14;
307
- rsbuildPlugins.push((0, import_plugin_assets_retry.pluginAssetsRetry)((_uniBuilderConfig_output14 = uniBuilderConfig.output) === null || _uniBuilderConfig_output14 === void 0 ? void 0 : _uniBuilderConfig_output14.assetsRetry));
256
+ const { pluginAssetsRetry } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-assets-retry")));
257
+ rsbuildPlugins.push(pluginAssetsRetry((_uniBuilderConfig_output14 = uniBuilderConfig.output) === null || _uniBuilderConfig_output14 === void 0 ? void 0 : _uniBuilderConfig_output14.assetsRetry));
308
258
  }
309
259
  if ((_uniBuilderConfig_output9 = uniBuilderConfig.output) === null || _uniBuilderConfig_output9 === void 0 ? void 0 : _uniBuilderConfig_output9.enableAssetFallback) {
310
- rsbuildPlugins.push((0, import_fallback.pluginFallback)());
260
+ const { pluginFallback } = await Promise.resolve().then(() => __toESM(require("./plugins/fallback")));
261
+ rsbuildPlugins.push(pluginFallback());
311
262
  }
312
263
  if (frameworkConfigPath) {
313
264
  rsbuildPlugins.push((0, import_frameworkConfig.pluginFrameworkConfig)(frameworkConfigPath));
@@ -0,0 +1,5 @@
1
+ import { type RsbuildPlugin } from '@rsbuild/shared';
2
+ /**
3
+ * generate a basic route.json for modern.js server
4
+ */
5
+ export declare const pluginEmitRouteFile: () => RsbuildPlugin;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var emitRouteFile_exports = {};
30
+ __export(emitRouteFile_exports, {
31
+ pluginEmitRouteFile: () => pluginEmitRouteFile
32
+ });
33
+ module.exports = __toCommonJS(emitRouteFile_exports);
34
+ var import_path = require("path");
35
+ var import_shared = require("@rsbuild/shared");
36
+ const pluginEmitRouteFile = () => ({
37
+ name: "uni-builder:emit-route-file",
38
+ setup(api) {
39
+ api.onBeforeStartDevServer(async () => {
40
+ const { fs, ROUTE_SPEC_FILE } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
41
+ const routeFilePath = (0, import_path.join)(api.context.distPath, ROUTE_SPEC_FILE);
42
+ const htmlPaths = api.getHTMLPaths();
43
+ const routesInfo = Object.entries(htmlPaths).map(([entryName, filename], index) => ({
44
+ urlPath: index === 0 ? "/" : `/${entryName}`,
45
+ entryName,
46
+ entryPath: filename,
47
+ isSPA: true
48
+ }));
49
+ if (!await (0, import_shared.isFileExists)(routeFilePath) && routesInfo.length) {
50
+ await fs.outputFile(routeFilePath, JSON.stringify({
51
+ routes: routesInfo
52
+ }, null, 2));
53
+ }
54
+ });
55
+ }
56
+ });
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ pluginEmitRouteFile
60
+ });
package/dist/types.d.ts CHANGED
@@ -44,7 +44,7 @@ export type DisableSourceMapOption = boolean | {
44
44
  };
45
45
  export type UniBuilderExtraConfig = {
46
46
  tools?: {
47
- styledComponents?: PluginStyledComponentsOptions;
47
+ styledComponents?: false | PluginStyledComponentsOptions;
48
48
  devServer?: {
49
49
  before?: RequestHandler[];
50
50
  after?: RequestHandler[];
@@ -1,7 +1,13 @@
1
1
  import { type RsbuildConfig, type RsbuildPlugin, type RsbuildInstance } from '@rsbuild/core';
2
+ import type { StartServerResult } from '@rsbuild/shared';
2
3
  import type { UniBuilderWebpackConfig, CreateWebpackBuilderOptions, CreateBuilderCommonOptions } from '../types';
4
+ import type { StartDevServerOptions } from '../shared/devServer';
3
5
  export declare function parseConfig(uniBuilderConfig: UniBuilderWebpackConfig, options: CreateBuilderCommonOptions): Promise<{
4
6
  rsbuildConfig: RsbuildConfig;
5
7
  rsbuildPlugins: RsbuildPlugin[];
6
8
  }>;
7
- export declare function createWebpackBuilder(options: CreateWebpackBuilderOptions): Promise<RsbuildInstance>;
9
+ type UniBuilderWebpackInstance = Omit<RsbuildInstance, 'startDevServer'> & {
10
+ startDevServer: (options: StartDevServerOptions) => Promise<StartServerResult>;
11
+ };
12
+ export declare function createWebpackBuilder(options: CreateWebpackBuilderOptions): Promise<UniBuilderWebpackInstance>;
13
+ export {};
@@ -35,7 +35,6 @@ module.exports = __toCommonJS(webpack_exports);
35
35
  var import_core = require("@rsbuild/core");
36
36
  var import_parseCommonConfig = require("../shared/parseCommonConfig");
37
37
  var import_moduleScopes = require("./plugins/moduleScopes");
38
- var import_styledComponents = require("./plugins/styledComponents");
39
38
  var import_babel = require("./plugins/babel");
40
39
  var import_react = require("./plugins/react");
41
40
  async function parseConfig(uniBuilderConfig, options) {
@@ -63,7 +62,11 @@ async function parseConfig(uniBuilderConfig, options) {
63
62
  const { pluginLazyCompilation } = await Promise.resolve().then(() => __toESM(require("./plugins/lazyCompilation")));
64
63
  rsbuildPlugins.push(pluginLazyCompilation((_uniBuilderConfig_experiments1 = uniBuilderConfig.experiments) === null || _uniBuilderConfig_experiments1 === void 0 ? void 0 : _uniBuilderConfig_experiments1.lazyCompilation));
65
64
  }
66
- rsbuildPlugins.push((0, import_styledComponents.pluginStyledComponents)((_uniBuilderConfig_tools2 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools2 === void 0 ? void 0 : _uniBuilderConfig_tools2.styledComponents));
65
+ if (((_uniBuilderConfig_tools2 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools2 === void 0 ? void 0 : _uniBuilderConfig_tools2.styledComponents) !== false) {
66
+ var _uniBuilderConfig_tools3;
67
+ const { pluginStyledComponents } = await Promise.resolve().then(() => __toESM(require("./plugins/styledComponents")));
68
+ rsbuildPlugins.push(pluginStyledComponents((_uniBuilderConfig_tools3 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools3 === void 0 ? void 0 : _uniBuilderConfig_tools3.styledComponents));
69
+ }
67
70
  return {
68
71
  rsbuildConfig,
69
72
  rsbuildPlugins
@@ -86,7 +89,13 @@ async function createWebpackBuilder(options) {
86
89
  ...rsbuildPlugins,
87
90
  (0, import_moduleScopes.pluginModuleScopes)((_options_config_source = options.config.source) === null || _options_config_source === void 0 ? void 0 : _options_config_source.moduleScopes)
88
91
  ]);
89
- return rsbuild;
92
+ return {
93
+ ...rsbuild,
94
+ startDevServer: async (options2 = {}) => {
95
+ const { startDevServer } = await Promise.resolve().then(() => __toESM(require("../shared/devServer")));
96
+ return startDevServer(rsbuild, options2, config);
97
+ }
98
+ };
90
99
  }
91
100
  // Annotate the CommonJS export names for ESM import in node:
92
101
  0 && (module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/uni-builder",
3
- "version": "0.0.0-nightly-20231218170633",
3
+ "version": "0.0.0-nightly-20231219170633",
4
4
  "description": "Unified builder for Modern.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -59,7 +59,10 @@
59
59
  "ts-loader": "9.4.4",
60
60
  "webpack": "^5.89.0",
61
61
  "webpack-manifest-plugin": "5.0.0",
62
- "webpack-subresource-integrity": "5.1.0"
62
+ "webpack-subresource-integrity": "5.1.0",
63
+ "@modern-js/server": "0.0.0-nightly-20231219170633",
64
+ "@modern-js/utils": "0.0.0-nightly-20231219170633",
65
+ "@modern-js/prod-server": "0.0.0-nightly-20231219170633"
63
66
  },
64
67
  "devDependencies": {
65
68
  "@rsbuild/plugin-swc": "0.2.4",
@@ -67,8 +70,8 @@
67
70
  "react": "^18.2.0",
68
71
  "react-dom": "^18.2.0",
69
72
  "typescript": "^5.3.0",
70
- "@scripts/build": "0.0.0-nightly-20231218170633",
71
- "@scripts/vitest-config": "0.0.0-nightly-20231218170633"
73
+ "@scripts/vitest-config": "0.0.0-nightly-20231219170633",
74
+ "@scripts/build": "0.0.0-nightly-20231219170633"
72
75
  },
73
76
  "publishConfig": {
74
77
  "access": "public",