@rsbuild/core 0.0.20 → 0.0.22
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/compiled/connect-history-api-fallback/index.d.ts +1 -0
- package/compiled/connect-history-api-fallback/index.js +1 -0
- package/compiled/connect-history-api-fallback/license +21 -0
- package/compiled/connect-history-api-fallback/package.json +1 -0
- package/compiled/open/index.d.ts +153 -0
- package/compiled/open/index.js +1 -0
- package/compiled/open/license +9 -0
- package/compiled/open/package.json +1 -0
- package/compiled/open/xdg-open +1066 -0
- package/dist/cli/commands.js +2 -2
- package/dist/cli/config.js +19 -2
- package/dist/cli/index.d.ts +1 -5
- package/dist/cli/index.js +3 -21
- package/dist/cli/run.d.ts +7 -0
- package/dist/cli/run.js +49 -0
- package/dist/client/hmr.js +418 -0
- package/dist/index.d.ts +1 -1
- package/dist/plugins/cache.js +8 -8
- package/dist/plugins/cleanOutput.js +3 -3
- package/dist/plugins/fileSize.js +24 -24
- package/dist/plugins/html.js +6 -24
- package/dist/plugins/index.js +0 -1
- package/dist/plugins/startUrl.js +2 -4
- package/dist/rspack-provider/core/createCompiler.d.ts +1 -1
- package/dist/rspack-provider/core/createCompiler.js +3 -3
- package/dist/rspack-provider/core/initHooks.d.ts +2 -1
- package/dist/rspack-provider/plugins/css.js +3 -10
- package/dist/rspack-provider/plugins/rspack-profile.js +6 -6
- package/dist/rspack-provider/plugins/swc.js +2 -3
- package/dist/rspack-provider/provider.js +4 -4
- package/dist/rspack-provider/rspackLoader/css-modules-typescript-pre-loader/postcss-icss-extract-plugin.d.ts +1 -1
- package/dist/rspack-provider/rspackLoader/css-modules-typescript-pre-loader/postcss-icss-extract-plugin.js +4 -4
- package/dist/rspack-provider/shared/fs.js +2 -2
- package/dist/rspack-provider/shared/plugin.js +1 -4
- package/dist/server/dev-middleware/index.d.ts +1 -0
- package/dist/server/dev-middleware/index.js +5 -4
- package/dist/server/devServer.d.ts +2 -2
- package/dist/server/devServer.js +26 -18
- package/dist/server/prodServer.d.ts +5 -3
- package/dist/server/prodServer.js +14 -4
- package/dist/server/restart.d.ts +11 -0
- package/dist/server/restart.js +64 -0
- package/package.json +8 -38
- package/dist/plugins/rem.d.ts +0 -2
- package/dist/plugins/rem.js +0 -103
- package/dist/rspack-provider/plugins/fallback.d.ts +0 -2
- package/dist/rspack-provider/plugins/fallback.js +0 -52
- package/dist/server/dev-middleware/hmr-client/createSocketUrl.js +0 -68
- package/dist/server/dev-middleware/hmr-client/index.js +0 -164
- /package/dist/{server/dev-middleware/hmr-client → client/hmr}/createSocketUrl.d.ts +0 -0
- /package/dist/{server/dev-middleware/hmr-client → client/hmr}/index.d.ts +0 -0
package/dist/plugins/fileSize.js
CHANGED
|
@@ -33,19 +33,18 @@ __export(fileSize_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(fileSize_exports);
|
|
35
35
|
var import_path = __toESM(require("path"));
|
|
36
|
-
var import_fs_extra = require("@rsbuild/shared/fs-extra");
|
|
37
36
|
var import_shared = require("@rsbuild/shared");
|
|
38
|
-
var
|
|
37
|
+
var import_shared2 = require("@rsbuild/shared");
|
|
39
38
|
var import_gzip_size = __toESM(require("gzip-size"));
|
|
40
39
|
const filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
|
|
41
40
|
const getAssetColor = (size) => {
|
|
42
41
|
if (size > 300 * 1e3) {
|
|
43
|
-
return
|
|
42
|
+
return import_shared2.color.red;
|
|
44
43
|
}
|
|
45
44
|
if (size > 100 * 1e3) {
|
|
46
|
-
return
|
|
45
|
+
return import_shared2.color.yellow;
|
|
47
46
|
}
|
|
48
|
-
return
|
|
47
|
+
return import_shared2.color.green;
|
|
49
48
|
};
|
|
50
49
|
async function printHeader(longestFileLength, longestLabelLength) {
|
|
51
50
|
const longestLengths = [longestFileLength, longestLabelLength];
|
|
@@ -57,11 +56,15 @@ async function printHeader(longestFileLength, longestLabelLength) {
|
|
|
57
56
|
}
|
|
58
57
|
return `${prev + curLabel} `;
|
|
59
58
|
}, " ");
|
|
60
|
-
|
|
59
|
+
import_shared2.logger.log(import_shared2.color.bold(import_shared2.color.blue(headerRow)));
|
|
61
60
|
}
|
|
61
|
+
const calcFileSize = (len) => {
|
|
62
|
+
const val = len / 1e3;
|
|
63
|
+
return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
|
|
64
|
+
};
|
|
62
65
|
async function printFileSizes(stats, distPath) {
|
|
63
66
|
const formatAsset = (asset) => {
|
|
64
|
-
const contents =
|
|
67
|
+
const contents = import_shared.fse.readFileSync(import_path.default.join(distPath, asset.name));
|
|
65
68
|
const size = contents.length;
|
|
66
69
|
const gzippedSize = import_gzip_size.default.sync(contents);
|
|
67
70
|
return {
|
|
@@ -69,10 +72,8 @@ async function printFileSizes(stats, distPath) {
|
|
|
69
72
|
folder: import_path.default.join(import_path.default.basename(distPath), import_path.default.dirname(asset.name)),
|
|
70
73
|
name: import_path.default.basename(asset.name),
|
|
71
74
|
gzippedSize,
|
|
72
|
-
sizeLabel: (
|
|
73
|
-
gzipSizeLabel: getAssetColor(gzippedSize)(
|
|
74
|
-
(0, import_filesize.default)(gzippedSize, { round: 1 })
|
|
75
|
-
)
|
|
75
|
+
sizeLabel: calcFileSize(size),
|
|
76
|
+
gzipSizeLabel: getAssetColor(gzippedSize)(calcFileSize(gzippedSize))
|
|
76
77
|
};
|
|
77
78
|
};
|
|
78
79
|
const multiStats = "stats" in stats ? stats.stats : [stats];
|
|
@@ -100,7 +101,7 @@ async function printFileSizes(stats, distPath) {
|
|
|
100
101
|
const longestFileLength = Math.max(
|
|
101
102
|
...assets.map((a) => (a.folder + import_path.default.sep + a.name).length)
|
|
102
103
|
);
|
|
103
|
-
|
|
104
|
+
import_shared2.logger.info(`Production file sizes:
|
|
104
105
|
`);
|
|
105
106
|
printHeader(longestFileLength, longestLabelLength);
|
|
106
107
|
let totalSize = 0;
|
|
@@ -116,21 +117,20 @@ async function printFileSizes(stats, distPath) {
|
|
|
116
117
|
const rightPadding = " ".repeat(longestLabelLength - sizeLength);
|
|
117
118
|
sizeLabel += rightPadding;
|
|
118
119
|
}
|
|
119
|
-
let fileNameLabel =
|
|
120
|
+
let fileNameLabel = import_shared2.color.dim(asset.folder + import_path.default.sep) + import_shared2.color.cyan(asset.name);
|
|
120
121
|
if (fileNameLength < longestFileLength) {
|
|
121
122
|
const rightPadding = " ".repeat(longestFileLength - fileNameLength);
|
|
122
123
|
fileNameLabel += rightPadding;
|
|
123
124
|
}
|
|
124
|
-
|
|
125
|
+
import_shared2.logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
|
|
125
126
|
});
|
|
126
|
-
const totalSizeLabel = `${
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
import_shared.logger.log(`
|
|
127
|
+
const totalSizeLabel = `${import_shared2.color.bold(
|
|
128
|
+
import_shared2.color.blue("Total size:")
|
|
129
|
+
)} ${calcFileSize(totalSize)}`;
|
|
130
|
+
const gzippedSizeLabel = `${import_shared2.color.bold(
|
|
131
|
+
import_shared2.color.blue("Gzipped size:")
|
|
132
|
+
)} ${calcFileSize(totalGzipSize)}`;
|
|
133
|
+
import_shared2.logger.log(`
|
|
134
134
|
${totalSizeLabel}
|
|
135
135
|
${gzippedSizeLabel}
|
|
136
136
|
`);
|
|
@@ -144,8 +144,8 @@ const pluginFileSize = () => ({
|
|
|
144
144
|
try {
|
|
145
145
|
await printFileSizes(stats, api.context.distPath);
|
|
146
146
|
} catch (err) {
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
import_shared2.logger.error("Failed to print file size.");
|
|
148
|
+
import_shared2.logger.error(err);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
});
|
package/dist/plugins/html.js
CHANGED
|
@@ -40,8 +40,6 @@ __export(html_exports, {
|
|
|
40
40
|
module.exports = __toCommonJS(html_exports);
|
|
41
41
|
var import_path = __toESM(require("path"));
|
|
42
42
|
var import_shared = require("@rsbuild/shared");
|
|
43
|
-
var import_fs_extra = require("@rsbuild/shared/fs-extra");
|
|
44
|
-
var import_lodash = __toESM(require("lodash"));
|
|
45
43
|
var import_HtmlBasicPlugin = require("../rspack-plugins/HtmlBasicPlugin");
|
|
46
44
|
function getTitle(entryName, config) {
|
|
47
45
|
return (0, import_shared.mergeChainedOptions)({
|
|
@@ -133,11 +131,13 @@ const applyInjectTags = (api) => {
|
|
|
133
131
|
api.modifyBundlerChain(async (chain, { HtmlPlugin, CHAIN_ID }) => {
|
|
134
132
|
const config = api.getNormalizedConfig();
|
|
135
133
|
const tags = (0, import_shared.castArray)(config.html.tags).filter(Boolean);
|
|
136
|
-
const tagsByEntries =
|
|
137
|
-
|
|
138
|
-
(
|
|
134
|
+
const tagsByEntries = config.html.tagsByEntries || {};
|
|
135
|
+
Object.keys(tagsByEntries).forEach(
|
|
136
|
+
(key) => tagsByEntries[key] = (0, import_shared.castArray)(tagsByEntries[key]).filter(Boolean)
|
|
137
|
+
);
|
|
138
|
+
const shouldByEntries = Object.values(tagsByEntries).some(
|
|
139
|
+
(entry) => Array.isArray(entry) && entry.length > 0
|
|
139
140
|
);
|
|
140
|
-
const shouldByEntries = import_lodash.default.some(tagsByEntries, "length");
|
|
141
141
|
if (!tags.length && !shouldByEntries) {
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
@@ -163,7 +163,6 @@ const applyInjectTags = (api) => {
|
|
|
163
163
|
const pluginHtml = () => ({
|
|
164
164
|
name: "plugin-html",
|
|
165
165
|
setup(api) {
|
|
166
|
-
const routesInfo = [];
|
|
167
166
|
api.modifyBundlerChain(
|
|
168
167
|
async (chain, { HtmlPlugin, isProd, CHAIN_ID, target }) => {
|
|
169
168
|
const config = api.getNormalizedConfig();
|
|
@@ -225,12 +224,6 @@ const pluginHtml = () => ({
|
|
|
225
224
|
entryValue
|
|
226
225
|
}
|
|
227
226
|
});
|
|
228
|
-
routesInfo.push({
|
|
229
|
-
urlPath: index === 0 ? "/" : `/${entryName}`,
|
|
230
|
-
entryName,
|
|
231
|
-
entryPath: filename,
|
|
232
|
-
isSPA: true
|
|
233
|
-
});
|
|
234
227
|
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(HtmlPlugin, [finalOptions]);
|
|
235
228
|
})
|
|
236
229
|
);
|
|
@@ -261,17 +254,6 @@ const pluginHtml = () => ({
|
|
|
261
254
|
}
|
|
262
255
|
}
|
|
263
256
|
);
|
|
264
|
-
const emitRouteJson = async () => {
|
|
265
|
-
const routeFilePath = import_path.default.join(api.context.distPath, import_shared.ROUTE_SPEC_FILE);
|
|
266
|
-
if (!await (0, import_shared.isFileExists)(routeFilePath) && routesInfo.length) {
|
|
267
|
-
await import_fs_extra.fs.outputFile(
|
|
268
|
-
routeFilePath,
|
|
269
|
-
JSON.stringify({ routes: routesInfo }, null, 2)
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
api.onBeforeBuild(emitRouteJson);
|
|
274
|
-
api.onBeforeStartDevServer(emitRouteJson);
|
|
275
257
|
applyInjectTags(api);
|
|
276
258
|
}
|
|
277
259
|
});
|
package/dist/plugins/index.js
CHANGED
|
@@ -46,7 +46,6 @@ const plugins = {
|
|
|
46
46
|
inlineChunk: () => Promise.resolve().then(() => __toESM(require("./inlineChunk"))).then((m) => m.pluginInlineChunk()),
|
|
47
47
|
bundleAnalyzer: () => Promise.resolve().then(() => __toESM(require("./bundleAnalyzer"))).then((m) => m.pluginBundleAnalyzer()),
|
|
48
48
|
asset: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset()),
|
|
49
|
-
rem: () => Promise.resolve().then(() => __toESM(require("./rem"))).then((m) => m.pluginRem()),
|
|
50
49
|
wasm: () => Promise.resolve().then(() => __toESM(require("./wasm"))).then((m) => m.pluginWasm()),
|
|
51
50
|
moment: () => Promise.resolve().then(() => __toESM(require("./moment"))).then((m) => m.pluginMoment()),
|
|
52
51
|
nodeAddons: () => Promise.resolve().then(() => __toESM(require("./nodeAddons"))).then((m) => m.pluginNodeAddons()),
|
package/dist/plugins/startUrl.js
CHANGED
|
@@ -80,7 +80,7 @@ async function openBrowser(url) {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
try {
|
|
83
|
-
const { default: open } = await Promise.resolve().then(() => __toESM(require("open")));
|
|
83
|
+
const { default: open } = await Promise.resolve().then(() => __toESM(require("../../compiled/open")));
|
|
84
84
|
await open(url);
|
|
85
85
|
return true;
|
|
86
86
|
} catch (err) {
|
|
@@ -96,7 +96,7 @@ function pluginStartUrl() {
|
|
|
96
96
|
name: "plugin-start-url",
|
|
97
97
|
setup(api) {
|
|
98
98
|
api.onAfterStartDevServer(async (params) => {
|
|
99
|
-
const { port } = params;
|
|
99
|
+
const { port, routes } = params;
|
|
100
100
|
const config = api.getNormalizedConfig();
|
|
101
101
|
const { startUrl, beforeStartUrl } = config.dev;
|
|
102
102
|
const { open, https } = api.context.devServer || {};
|
|
@@ -106,8 +106,6 @@ function pluginStartUrl() {
|
|
|
106
106
|
}
|
|
107
107
|
const urls = [];
|
|
108
108
|
if (startUrl === true || !startUrl) {
|
|
109
|
-
const { entry } = api.context;
|
|
110
|
-
const routes = (0, import_shared.formatRoutes)(entry);
|
|
111
109
|
const protocol = https ? "https" : "http";
|
|
112
110
|
urls.push(
|
|
113
111
|
(0, import_shared.normalizeUrl)(`${protocol}://localhost:${port}/${routes[0].route}`)
|
|
@@ -9,4 +9,4 @@ export declare function createCompiler({
|
|
|
9
9
|
context: Context;
|
|
10
10
|
rspackConfigs: RspackConfig[];
|
|
11
11
|
}): Promise<import("@rspack/core").MultiCompiler>;
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function createDevMiddleware(options: InitConfigsOptions, customCompiler?: RspackCompiler | RspackMultiCompiler): Promise<import("@rsbuild/shared").DevMiddleware>;
|
|
@@ -29,7 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var createCompiler_exports = {};
|
|
30
30
|
__export(createCompiler_exports, {
|
|
31
31
|
createCompiler: () => createCompiler,
|
|
32
|
-
|
|
32
|
+
createDevMiddleware: () => createDevMiddleware
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(createCompiler_exports);
|
|
35
35
|
var import_shared = require("@rsbuild/shared");
|
|
@@ -82,7 +82,7 @@ async function createCompiler({
|
|
|
82
82
|
(0, import_shared.debug)("create compiler done");
|
|
83
83
|
return compiler;
|
|
84
84
|
}
|
|
85
|
-
async function
|
|
85
|
+
async function createDevMiddleware(options, customCompiler) {
|
|
86
86
|
let compiler;
|
|
87
87
|
if (customCompiler) {
|
|
88
88
|
compiler = customCompiler;
|
|
@@ -98,5 +98,5 @@ async function startDevCompile(options, customCompiler) {
|
|
|
98
98
|
// Annotate the CommonJS export names for ESM import in node:
|
|
99
99
|
0 && (module.exports = {
|
|
100
100
|
createCompiler,
|
|
101
|
-
|
|
101
|
+
createDevMiddleware
|
|
102
102
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OnExitFn, OnAfterBuildFn, OnBeforeBuildFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn, OnAfterStartDevServerFn, OnBeforeStartDevServerFn, OnAfterCreateCompilerFn, OnBeforeCreateCompilerFn, ModifyBundlerChainFn, type RspackConfig, type ModifyRspackConfigFn } from '@rsbuild/shared';
|
|
2
2
|
import type { RsbuildConfig } from '../types';
|
|
3
|
+
import type { Compiler, MultiCompiler } from '@rspack/core';
|
|
3
4
|
export declare function initHooks(): {
|
|
4
5
|
/** parameters are not bundler-related */
|
|
5
6
|
onExitHook: import("@rsbuild/shared").AsyncHook<OnExitFn>;
|
|
@@ -11,7 +12,7 @@ export declare function initHooks(): {
|
|
|
11
12
|
onBeforeBuildHook: import("@rsbuild/shared").AsyncHook<OnBeforeBuildFn<RspackConfig>>;
|
|
12
13
|
modifyRspackConfigHook: import("@rsbuild/shared").AsyncHook<ModifyRspackConfigFn>;
|
|
13
14
|
modifyRsbuildConfigHook: import("@rsbuild/shared").AsyncHook<ModifyRsbuildConfigFn<RsbuildConfig>>;
|
|
14
|
-
onAfterCreateCompilerHook: import("@rsbuild/shared").AsyncHook<OnAfterCreateCompilerFn<
|
|
15
|
+
onAfterCreateCompilerHook: import("@rsbuild/shared").AsyncHook<OnAfterCreateCompilerFn<Compiler | MultiCompiler>>;
|
|
15
16
|
onBeforeCreateCompilerHook: import("@rsbuild/shared").AsyncHook<OnBeforeCreateCompilerFn<RspackConfig>>;
|
|
16
17
|
modifyBundlerChainHook: import("@rsbuild/shared").AsyncHook<ModifyBundlerChainFn>;
|
|
17
18
|
};
|
|
@@ -90,11 +90,7 @@ async function applyBaseCSSRule({
|
|
|
90
90
|
rule.use(CHAIN_ID.USE.CSS).loader((0, import_shared2.getCompiledPath)("css-loader")).options(cssLoaderOptions).end();
|
|
91
91
|
} else {
|
|
92
92
|
if (!isServer && !isWebWorker && enableCSSModuleTS) {
|
|
93
|
-
const { cssModules
|
|
94
|
-
const cssModulesAuto = (0, import_shared.getCssModulesAutoRule)(
|
|
95
|
-
cssModules,
|
|
96
|
-
disableCssModuleExtension
|
|
97
|
-
);
|
|
93
|
+
const { cssModules } = config.output;
|
|
98
94
|
rule.use(CHAIN_ID.USE.CSS_MODULES_TS).loader(
|
|
99
95
|
import_path.default.resolve(
|
|
100
96
|
__dirname,
|
|
@@ -103,7 +99,7 @@ async function applyBaseCSSRule({
|
|
|
103
99
|
).options({
|
|
104
100
|
modules: {
|
|
105
101
|
exportLocalsConvention: cssModules.exportLocalsConvention,
|
|
106
|
-
auto:
|
|
102
|
+
auto: cssModules.auto
|
|
107
103
|
}
|
|
108
104
|
}).end();
|
|
109
105
|
}
|
|
@@ -129,10 +125,7 @@ const applyCSSModuleRule = (rules, ruleTest, config) => {
|
|
|
129
125
|
if (ruleIndex === -1) {
|
|
130
126
|
return;
|
|
131
127
|
}
|
|
132
|
-
const cssModulesAuto =
|
|
133
|
-
config.output.cssModules,
|
|
134
|
-
config.output.disableCssModuleExtension
|
|
135
|
-
);
|
|
128
|
+
const cssModulesAuto = config.output.cssModules.auto;
|
|
136
129
|
if (!cssModulesAuto) {
|
|
137
130
|
return;
|
|
138
131
|
}
|
|
@@ -35,18 +35,18 @@ module.exports = __toCommonJS(rspack_profile_exports);
|
|
|
35
35
|
var import_path = __toESM(require("path"));
|
|
36
36
|
var import_core = require("@rspack/core");
|
|
37
37
|
var import_inspector = __toESM(require("inspector"));
|
|
38
|
-
var import_fs_extra = require("@rsbuild/shared/fs-extra");
|
|
39
38
|
var import_shared = require("@rsbuild/shared");
|
|
39
|
+
var import_shared2 = require("@rsbuild/shared");
|
|
40
40
|
const stopProfiler = (output, profileSession) => {
|
|
41
41
|
if (!profileSession) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
profileSession.post("Profiler.stop", (error, param) => {
|
|
45
45
|
if (error) {
|
|
46
|
-
|
|
46
|
+
import_shared2.logger.error("Failed to generate JS CPU profile:", error);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
import_shared.fse.writeFileSync(output, JSON.stringify(param.profile));
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
const pluginRspackProfile = () => ({
|
|
@@ -70,7 +70,7 @@ const pluginRspackProfile = () => ({
|
|
|
70
70
|
const cpuProfilePath = import_path.default.join(profileDir, "jscpuprofile.json");
|
|
71
71
|
const loggingFilePath = import_path.default.join(profileDir, "logging.json");
|
|
72
72
|
const onStart = () => {
|
|
73
|
-
|
|
73
|
+
import_shared.fse.ensureDirSync(profileDir);
|
|
74
74
|
if (enableProfileTrace) {
|
|
75
75
|
(0, import_core.experimental_registerGlobalTrace)("trace", "chrome", traceFilePath);
|
|
76
76
|
}
|
|
@@ -90,13 +90,13 @@ const pluginRspackProfile = () => ({
|
|
|
90
90
|
logging: "verbose",
|
|
91
91
|
loggingTrace: true
|
|
92
92
|
});
|
|
93
|
-
|
|
93
|
+
import_shared.fse.writeFileSync(loggingFilePath, JSON.stringify(logging));
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
96
|
api.onExit(() => {
|
|
97
97
|
enableProfileTrace && (0, import_core.experimental_cleanupGlobalTrace)();
|
|
98
98
|
stopProfiler(cpuProfilePath, profileSession);
|
|
99
|
-
|
|
99
|
+
import_shared2.logger.info(`Saved Rspack profile file to ${profileDir}`);
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
});
|
|
@@ -33,7 +33,6 @@ __export(swc_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(swc_exports);
|
|
35
35
|
var import_shared = require("@rsbuild/shared");
|
|
36
|
-
var import_lodash = require("lodash");
|
|
37
36
|
var path = __toESM(require("path"));
|
|
38
37
|
const builtinSwcLoaderName = "builtin:swc-loader";
|
|
39
38
|
async function getDefaultSwcConfig(config, rootPath, target) {
|
|
@@ -72,7 +71,7 @@ const pluginSwc = () => ({
|
|
|
72
71
|
isServer,
|
|
73
72
|
isServiceWorker
|
|
74
73
|
});
|
|
75
|
-
const rule = chain.module.rule(CHAIN_ID.RULE.JS).test(
|
|
74
|
+
const rule = chain.module.rule(CHAIN_ID.RULE.JS).test(import_shared.SCRIPT_REGEX).type("javascript/auto");
|
|
76
75
|
(0, import_shared.applyScriptCondition)({
|
|
77
76
|
rule,
|
|
78
77
|
config,
|
|
@@ -99,7 +98,7 @@ const pluginSwc = () => ({
|
|
|
99
98
|
rule.use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options(swcConfig);
|
|
100
99
|
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
|
|
101
100
|
or: ["text/javascript", "application/javascript"]
|
|
102
|
-
}).use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options((0,
|
|
101
|
+
}).use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options((0, import_shared.cloneDeep)(swcConfig));
|
|
103
102
|
}
|
|
104
103
|
);
|
|
105
104
|
api.modifyRspackConfig(async (config) => {
|
|
@@ -73,15 +73,15 @@ function rspackProvider({
|
|
|
73
73
|
});
|
|
74
74
|
},
|
|
75
75
|
async startDevServer(options) {
|
|
76
|
-
const {
|
|
76
|
+
const { createDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
|
|
77
77
|
return (0, import_server.startDevServer)(
|
|
78
78
|
{ context, pluginStore, rsbuildOptions },
|
|
79
|
-
|
|
79
|
+
createDevMiddleware,
|
|
80
80
|
options
|
|
81
81
|
);
|
|
82
82
|
},
|
|
83
|
-
async preview() {
|
|
84
|
-
return (0, import_server.startProdServer)(context, context.config);
|
|
83
|
+
async preview(options) {
|
|
84
|
+
return (0, import_server.startProdServer)(context, context.config, options);
|
|
85
85
|
},
|
|
86
86
|
async build(options) {
|
|
87
87
|
const { build: buildImpl, rspackBuild } = await Promise.resolve().then(() => __toESM(require("./core/build")));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CssModuleLocalsConvention } from '@rsbuild/shared';
|
|
2
2
|
import type { AcceptedPlugin as PostCSSPlugin } from 'postcss';
|
|
3
3
|
export type PostcssParsePluginOptions = {
|
|
4
4
|
exportLocalsConvention: CssModuleLocalsConvention;
|
|
@@ -22,16 +22,16 @@ __export(postcss_icss_extract_plugin_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(postcss_icss_extract_plugin_exports);
|
|
24
24
|
var import_icss_utils = require("@rsbuild/shared/icss-utils");
|
|
25
|
-
var
|
|
25
|
+
var import_shared = require("@rsbuild/shared");
|
|
26
26
|
const dashesCamelCase = (str) => str.replace(/-+(\w)/g, (_match, firstLetter) => firstLetter.toUpperCase());
|
|
27
27
|
const getExportLocalsConvention = (name, exportLocalsConventionType) => {
|
|
28
28
|
switch (exportLocalsConventionType) {
|
|
29
29
|
case "camelCase": {
|
|
30
|
-
const camelName = (0,
|
|
31
|
-
return camelName === name ? [name] : [name, (0,
|
|
30
|
+
const camelName = (0, import_shared.camelCase)(name);
|
|
31
|
+
return camelName === name ? [name] : [name, (0, import_shared.camelCase)(name)];
|
|
32
32
|
}
|
|
33
33
|
case "camelCaseOnly": {
|
|
34
|
-
return [(0,
|
|
34
|
+
return [(0, import_shared.camelCase)(name)];
|
|
35
35
|
}
|
|
36
36
|
case "dashes": {
|
|
37
37
|
const dashesCamelName = dashesCamelCase(name);
|
|
@@ -23,10 +23,10 @@ __export(fs_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(fs_exports);
|
|
24
24
|
var import_path = require("path");
|
|
25
25
|
var import_shared = require("@rsbuild/shared");
|
|
26
|
-
var
|
|
26
|
+
var import_shared2 = require("@rsbuild/shared");
|
|
27
27
|
const getCompiledPath = (packageName) => {
|
|
28
28
|
const providerCompilerPath = (0, import_path.join)(__dirname, "../../compiled", packageName);
|
|
29
|
-
if (
|
|
29
|
+
if (import_shared2.fse.existsSync(providerCompilerPath)) {
|
|
30
30
|
return providerCompilerPath;
|
|
31
31
|
} else {
|
|
32
32
|
return (0, import_shared.getSharedPkgCompiledPath)(packageName);
|
|
@@ -54,7 +54,6 @@ const applyDefaultPlugins = (plugins) => (0, import_shared.awaitableGetter)([
|
|
|
54
54
|
Promise.resolve().then(() => __toESM(require("../plugins/less"))).then((m) => m.pluginLess()),
|
|
55
55
|
Promise.resolve().then(() => __toESM(require("../plugins/sass"))).then((m) => m.pluginSass()),
|
|
56
56
|
Promise.resolve().then(() => __toESM(require("../plugins/minimize"))).then((m) => m.pluginMinimize()),
|
|
57
|
-
plugins.rem(),
|
|
58
57
|
Promise.resolve().then(() => __toESM(require("../plugins/hmr"))).then((m) => m.pluginHMR()),
|
|
59
58
|
Promise.resolve().then(() => __toESM(require("../plugins/progress"))).then((m) => m.pluginProgress()),
|
|
60
59
|
Promise.resolve().then(() => __toESM(require("../plugins/swc"))).then((m) => m.pluginSwc()),
|
|
@@ -68,9 +67,7 @@ const applyDefaultPlugins = (plugins) => (0, import_shared.awaitableGetter)([
|
|
|
68
67
|
plugins.networkPerformance(),
|
|
69
68
|
plugins.preloadOrPrefetch(),
|
|
70
69
|
plugins.performance(),
|
|
71
|
-
Promise.resolve().then(() => __toESM(require("../plugins/rspack-profile"))).then((m) => m.pluginRspackProfile())
|
|
72
|
-
Promise.resolve().then(() => __toESM(require("../plugins/fallback"))).then((m) => m.pluginFallback())
|
|
73
|
-
// fallback should be the last plugin
|
|
70
|
+
Promise.resolve().then(() => __toESM(require("../plugins/rspack-profile"))).then((m) => m.pluginRspackProfile())
|
|
74
71
|
]);
|
|
75
72
|
// Annotate the CommonJS export names for ESM import in node:
|
|
76
73
|
0 && (module.exports = {
|
|
@@ -40,7 +40,7 @@ function getHMRClientPath(client) {
|
|
|
40
40
|
const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
|
|
41
41
|
const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
42
42
|
const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
43
|
-
const clientEntry = `${require.resolve("@rsbuild/core/hmr
|
|
43
|
+
const clientEntry = `${require.resolve("@rsbuild/core/client/hmr")}?${host}${path}${port}${protocol}`;
|
|
44
44
|
return clientEntry;
|
|
45
45
|
}
|
|
46
46
|
class DevMiddleware extends import_events.EventEmitter {
|
|
@@ -48,11 +48,12 @@ class DevMiddleware extends import_events.EventEmitter {
|
|
|
48
48
|
super();
|
|
49
49
|
this.devOptions = dev;
|
|
50
50
|
this.socketServer = new import_socketServer.default(dev);
|
|
51
|
-
|
|
52
|
-
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
53
|
-
}
|
|
51
|
+
this.devMiddleware = devMiddleware;
|
|
54
52
|
}
|
|
55
53
|
init(app) {
|
|
54
|
+
if (this.devMiddleware) {
|
|
55
|
+
this.middleware = this.setupDevMiddleware(this.devMiddleware);
|
|
56
|
+
}
|
|
56
57
|
app.on("listening", () => {
|
|
57
58
|
this.socketServer.prepare(app);
|
|
58
59
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { Server } from 'http';
|
|
5
5
|
import type { ListenOptions } from 'net';
|
|
6
6
|
import { RsbuildDevServerOptions, CreateDevServerOptions, DevServerContext, StartDevServerOptions, StartServerResult } from '@rsbuild/shared';
|
|
7
|
-
import connect from 'connect';
|
|
7
|
+
import connect from '@rsbuild/shared/connect';
|
|
8
8
|
export declare class RsbuildDevServer {
|
|
9
9
|
private readonly dev;
|
|
10
10
|
private readonly devMiddleware;
|
|
@@ -22,7 +22,7 @@ export declare class RsbuildDevServer {
|
|
|
22
22
|
}
|
|
23
23
|
export declare function startDevServer<Options extends {
|
|
24
24
|
context: DevServerContext;
|
|
25
|
-
}>(options: Options,
|
|
25
|
+
}>(options: Options, createDevMiddleware: (options: Options, compiler: StartDevServerOptions['compiler']) => Promise<CreateDevServerOptions['devMiddleware']>, {
|
|
26
26
|
open,
|
|
27
27
|
compiler,
|
|
28
28
|
printURLs,
|
package/dist/server/devServer.js
CHANGED
|
@@ -37,10 +37,11 @@ var import_https = require("https");
|
|
|
37
37
|
var import_url = __toESM(require("url"));
|
|
38
38
|
var import_shared = require("@rsbuild/shared");
|
|
39
39
|
var import_dev_middleware = __toESM(require("./dev-middleware"));
|
|
40
|
-
var import_connect = __toESM(require("connect"));
|
|
40
|
+
var import_connect = __toESM(require("@rsbuild/shared/connect"));
|
|
41
41
|
var import_proxy = require("./proxy");
|
|
42
42
|
var import_middlewares = require("./middlewares");
|
|
43
43
|
var import_path = require("path");
|
|
44
|
+
var import_restart = require("./restart");
|
|
44
45
|
class RsbuildDevServer {
|
|
45
46
|
constructor(options) {
|
|
46
47
|
this.middlewares = (0, import_connect.default)();
|
|
@@ -120,9 +121,8 @@ class RsbuildDevServer {
|
|
|
120
121
|
})
|
|
121
122
|
);
|
|
122
123
|
if (dev.historyApiFallback) {
|
|
123
|
-
const { default: connectHistoryApiFallback } = await Promise.resolve().then(() => __toESM(require("connect-history-api-fallback")));
|
|
124
|
+
const { default: connectHistoryApiFallback } = await Promise.resolve().then(() => __toESM(require("../../compiled/connect-history-api-fallback")));
|
|
124
125
|
const historyApiFallbackMiddleware = connectHistoryApiFallback(
|
|
125
|
-
// @ts-expect-error
|
|
126
126
|
typeof dev.historyApiFallback === "boolean" ? {} : dev.historyApiFallback
|
|
127
127
|
);
|
|
128
128
|
this.middlewares.use(historyApiFallbackMiddleware);
|
|
@@ -156,7 +156,7 @@ class RsbuildDevServer {
|
|
|
156
156
|
this.app.close();
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
async function startDevServer(options,
|
|
159
|
+
async function startDevServer(options, createDevMiddleware, {
|
|
160
160
|
open,
|
|
161
161
|
compiler,
|
|
162
162
|
printURLs = true,
|
|
@@ -164,7 +164,7 @@ async function startDevServer(options, startDevCompile, {
|
|
|
164
164
|
logger: customLogger,
|
|
165
165
|
getPortSilently
|
|
166
166
|
} = {}) {
|
|
167
|
-
var _a, _b, _c;
|
|
167
|
+
var _a, _b, _c, _d, _e;
|
|
168
168
|
if (!process.env.NODE_ENV) {
|
|
169
169
|
process.env.NODE_ENV = "development";
|
|
170
170
|
}
|
|
@@ -183,29 +183,33 @@ async function startDevServer(options, startDevCompile, {
|
|
|
183
183
|
};
|
|
184
184
|
const protocol = https ? "https" : "http";
|
|
185
185
|
let urls = (0, import_shared.getAddressUrls)(protocol, port, (_a = rsbuildConfig.dev) == null ? void 0 : _a.host);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
throw new Error("Please return an array in the `printURLs` function.");
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
(0, import_shared.printServerURLs)(urls, options.context.entry, logger);
|
|
194
|
-
}
|
|
186
|
+
const routes = (0, import_shared.formatRoutes)(
|
|
187
|
+
options.context.entry,
|
|
188
|
+
(_c = (_b = rsbuildConfig.output) == null ? void 0 : _b.distPath) == null ? void 0 : _c.html
|
|
189
|
+
);
|
|
195
190
|
(0, import_shared.debug)("create dev server");
|
|
196
|
-
const devMiddleware = await
|
|
191
|
+
const devMiddleware = await createDevMiddleware(options, compiler);
|
|
197
192
|
const server = new RsbuildDevServer({
|
|
198
193
|
pwd: options.context.rootPath,
|
|
199
194
|
devMiddleware,
|
|
200
195
|
dev: devServerConfig,
|
|
201
196
|
output: {
|
|
202
|
-
distPath: ((
|
|
197
|
+
distPath: ((_e = (_d = rsbuildConfig.output) == null ? void 0 : _d.distPath) == null ? void 0 : _e.root) || import_shared.ROOT_DIST_DIR,
|
|
203
198
|
assetPrefix: typeof devServerConfig.assetPrefix === "string" && !(0, import_shared.isURL)(devServerConfig.assetPrefix) ? devServerConfig.assetPrefix : ""
|
|
204
199
|
}
|
|
205
200
|
});
|
|
206
201
|
(0, import_shared.debug)("create dev server done");
|
|
207
202
|
await options.context.hooks.onBeforeStartDevServerHook.call();
|
|
208
203
|
const httpServer = await server.createHTTPServer();
|
|
204
|
+
if (printURLs) {
|
|
205
|
+
if ((0, import_shared.isFunction)(printURLs)) {
|
|
206
|
+
urls = printURLs(urls);
|
|
207
|
+
if (!Array.isArray(urls)) {
|
|
208
|
+
throw new Error("Please return an array in the `printURLs` function.");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
(0, import_shared.printServerURLs)(urls, routes, logger);
|
|
212
|
+
}
|
|
209
213
|
await server.onInit(httpServer);
|
|
210
214
|
(0, import_shared.debug)("listen dev server");
|
|
211
215
|
return new Promise((resolve) => {
|
|
@@ -219,12 +223,16 @@ async function startDevServer(options, startDevCompile, {
|
|
|
219
223
|
throw err;
|
|
220
224
|
}
|
|
221
225
|
(0, import_shared.debug)("listen dev server done");
|
|
222
|
-
await options.context.hooks.onAfterStartDevServerHook.call({
|
|
226
|
+
await options.context.hooks.onAfterStartDevServerHook.call({
|
|
227
|
+
port,
|
|
228
|
+
routes
|
|
229
|
+
});
|
|
230
|
+
(0, import_restart.registerCleaner)(() => server.close());
|
|
223
231
|
resolve({
|
|
224
232
|
port,
|
|
225
233
|
urls: urls.map((item) => item.url),
|
|
226
234
|
server: {
|
|
227
|
-
close: () => {
|
|
235
|
+
close: async () => {
|
|
228
236
|
server.close();
|
|
229
237
|
}
|
|
230
238
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import type { ListenOptions } from 'net';
|
|
4
4
|
import { Server } from 'http';
|
|
5
|
-
import connect from 'connect';
|
|
6
|
-
import { Context, RsbuildConfig, StartServerResult } from '@rsbuild/shared';
|
|
5
|
+
import connect from '@rsbuild/shared/connect';
|
|
6
|
+
import { Context, RsbuildConfig, StartServerResult, PreviewServerOptions } from '@rsbuild/shared';
|
|
7
7
|
type RsbuildProdServerOptions = {
|
|
8
8
|
pwd: string;
|
|
9
9
|
output: {
|
|
@@ -23,5 +23,7 @@ export declare class RsbuildProdServer {
|
|
|
23
23
|
listen(options?: number | ListenOptions | undefined, listener?: () => void): void;
|
|
24
24
|
close(): void;
|
|
25
25
|
}
|
|
26
|
-
export declare function startProdServer(context: Context, rsbuildConfig: RsbuildConfig
|
|
26
|
+
export declare function startProdServer(context: Context, rsbuildConfig: RsbuildConfig, {
|
|
27
|
+
printURLs
|
|
28
|
+
}?: PreviewServerOptions): Promise<StartServerResult>;
|
|
27
29
|
export {};
|