@rsbuild/core 0.0.28 → 0.1.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.
- package/compiled/dotenv/index.js +1 -0
- package/compiled/dotenv/lib/main.d.ts +156 -0
- package/compiled/dotenv/license +23 -0
- package/compiled/dotenv/package.json +1 -0
- package/compiled/dotenv-expand/index.js +1 -0
- package/compiled/dotenv-expand/lib/main.d.ts +29 -0
- package/compiled/dotenv-expand/license +24 -0
- package/compiled/dotenv-expand/package.json +1 -0
- package/dist/cli/commands.d.ts +7 -1
- package/dist/cli/commands.js +33 -20
- package/dist/cli/config.js +28 -16
- package/dist/cli/prepare.js +1 -1
- package/dist/loadEnv.d.ts +5 -0
- package/dist/loadEnv.js +58 -0
- package/dist/plugins/asset.js +1 -1
- package/dist/plugins/bundleAnalyzer.js +1 -1
- package/dist/plugins/cache.js +1 -1
- package/dist/plugins/cleanOutput.js +1 -1
- package/dist/plugins/define.js +1 -1
- package/dist/plugins/devtool.js +1 -1
- package/dist/plugins/entry.js +1 -1
- package/dist/plugins/externals.js +1 -1
- package/dist/plugins/fileSize.js +1 -1
- package/dist/plugins/html.js +1 -1
- package/dist/plugins/inlineChunk.js +8 -12
- package/dist/plugins/moment.js +1 -1
- package/dist/plugins/nodeAddons.js +1 -1
- package/dist/plugins/performance.js +1 -1
- package/dist/plugins/splitChunks.js +1 -1
- package/dist/plugins/startUrl.js +1 -1
- package/dist/plugins/target.js +1 -1
- package/dist/plugins/toml.js +1 -1
- package/dist/plugins/wasm.js +1 -1
- package/dist/plugins/yaml.js +1 -1
- package/dist/rspack-provider/core/createContext.js +1 -1
- package/dist/rspack-provider/plugins/basic.js +1 -1
- package/dist/rspack-provider/plugins/css.js +1 -1
- package/dist/rspack-provider/plugins/hmr.js +1 -1
- package/dist/rspack-provider/plugins/less.js +1 -1
- package/dist/rspack-provider/plugins/minimize.js +1 -1
- package/dist/rspack-provider/plugins/output.js +1 -1
- package/dist/rspack-provider/plugins/progress.js +1 -1
- package/dist/rspack-provider/plugins/resolve.js +1 -1
- package/dist/rspack-provider/plugins/rspackProfile.d.ts +1 -0
- package/dist/rspack-provider/plugins/rspackProfile.js +1 -1
- package/dist/rspack-provider/plugins/sass.js +1 -1
- package/dist/rspack-provider/plugins/swc.js +1 -1
- package/dist/rspack-provider/plugins/transition.js +1 -1
- package/dist/server/dev-middleware/index.js +1 -1
- package/dist/server/devServer.js +8 -9
- package/dist/server/middlewares.d.ts +2 -1
- package/dist/server/middlewares.js +23 -11
- package/dist/server/prodServer.d.ts +6 -3
- package/dist/server/prodServer.js +52 -11
- package/dist/server/proxy.d.ts +4 -3
- package/dist/server/restart.js +4 -1
- package/package.json +4 -4
- package/dist/server/https.d.ts +0 -6
- package/dist/server/https.js +0 -50
|
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(nodeAddons_exports);
|
|
|
24
24
|
var import_path = require("path");
|
|
25
25
|
var import_shared = require("@rsbuild/shared");
|
|
26
26
|
const pluginNodeAddons = () => ({
|
|
27
|
-
name: "
|
|
27
|
+
name: "rsbuild:node-addons",
|
|
28
28
|
setup(api) {
|
|
29
29
|
api.modifyBundlerChain(
|
|
30
30
|
async (chain, { isServer, isServiceWorker, CHAIN_ID }) => {
|
|
@@ -172,7 +172,7 @@ const SPLIT_STRATEGY_DISPATCHER = {
|
|
|
172
172
|
};
|
|
173
173
|
function pluginSplitChunks() {
|
|
174
174
|
return {
|
|
175
|
-
name: "
|
|
175
|
+
name: "rsbuild:split-chunks",
|
|
176
176
|
setup(api) {
|
|
177
177
|
api.modifyBundlerChain(
|
|
178
178
|
async (chain, { isServer, isWebWorker, isServiceWorker }) => {
|
package/dist/plugins/startUrl.js
CHANGED
|
@@ -93,7 +93,7 @@ const replacePlaceholder = (url, port) => url.replace(/<port>/g, String(port));
|
|
|
93
93
|
const openedURLs = [];
|
|
94
94
|
function pluginStartUrl() {
|
|
95
95
|
return {
|
|
96
|
-
name: "
|
|
96
|
+
name: "rsbuild:start-url",
|
|
97
97
|
setup(api) {
|
|
98
98
|
api.onAfterStartDevServer(async (params) => {
|
|
99
99
|
const { port, routes } = params;
|
package/dist/plugins/target.js
CHANGED
|
@@ -23,7 +23,7 @@ __export(target_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(target_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginTarget = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:target",
|
|
27
27
|
setup(api) {
|
|
28
28
|
api.modifyBundlerChain(async (chain, { target }) => {
|
|
29
29
|
if (target === "node") {
|
package/dist/plugins/toml.js
CHANGED
|
@@ -23,7 +23,7 @@ __export(toml_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(toml_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginToml = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:toml",
|
|
27
27
|
setup(api) {
|
|
28
28
|
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
|
29
29
|
chain.module.rule(CHAIN_ID.RULE.TOML).type("javascript/auto").test(/\.toml$/).use(CHAIN_ID.USE.TOML).loader((0, import_shared.getSharedPkgCompiledPath)("toml-loader"));
|
package/dist/plugins/wasm.js
CHANGED
|
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(wasm_exports);
|
|
|
24
24
|
var import_path = require("path");
|
|
25
25
|
var import_shared = require("@rsbuild/shared");
|
|
26
26
|
const pluginWasm = () => ({
|
|
27
|
-
name: "
|
|
27
|
+
name: "rsbuild:wasm",
|
|
28
28
|
setup(api) {
|
|
29
29
|
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
30
30
|
const config = api.getNormalizedConfig();
|
package/dist/plugins/yaml.js
CHANGED
|
@@ -23,7 +23,7 @@ __export(yaml_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(yaml_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginYaml = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:yaml",
|
|
27
27
|
setup(api) {
|
|
28
28
|
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
|
29
29
|
chain.module.rule(CHAIN_ID.RULE.YAML).type("javascript/auto").test(/\.ya?ml$/).use(CHAIN_ID.USE.YAML).loader((0, import_shared.getSharedPkgCompiledPath)("yaml-loader"));
|
|
@@ -64,7 +64,7 @@ function createContextByConfig(options, bundlerType, sourceConfig = {}, outputCo
|
|
|
64
64
|
entry: sourceConfig.entry || // TODO: remove sourceConfig.entries in v0.2.0
|
|
65
65
|
// compat with previous config
|
|
66
66
|
sourceConfig.entries || getDefaultEntry(rootPath),
|
|
67
|
-
version: "0.0
|
|
67
|
+
version: "0.1.0",
|
|
68
68
|
target,
|
|
69
69
|
rootPath,
|
|
70
70
|
distPath,
|
|
@@ -23,7 +23,7 @@ __export(basic_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(basic_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginBasic = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:basic",
|
|
27
27
|
setup(api) {
|
|
28
28
|
(0, import_shared.applyBasicPlugin)(api);
|
|
29
29
|
}
|
|
@@ -143,7 +143,7 @@ const applyCSSModuleRule = (rules, ruleTest, config) => {
|
|
|
143
143
|
};
|
|
144
144
|
const pluginCss = () => {
|
|
145
145
|
return {
|
|
146
|
-
name: "
|
|
146
|
+
name: "rsbuild:css",
|
|
147
147
|
setup(api) {
|
|
148
148
|
api.modifyBundlerChain(async (chain, utils) => {
|
|
149
149
|
const config = api.getNormalizedConfig();
|
|
@@ -23,7 +23,7 @@ __export(hmr_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(hmr_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginHMR = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:hmr",
|
|
27
27
|
setup(api) {
|
|
28
28
|
api.modifyRspackConfig((rspackConfig, utils) => {
|
|
29
29
|
const config = api.getNormalizedConfig();
|
|
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(less_exports);
|
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
35
|
function pluginLess() {
|
|
36
36
|
return {
|
|
37
|
-
name: "
|
|
37
|
+
name: "rsbuild:less",
|
|
38
38
|
setup(api) {
|
|
39
39
|
api.modifyBundlerChain(async (chain, utils) => {
|
|
40
40
|
const config = api.getNormalizedConfig();
|
|
@@ -56,7 +56,7 @@ function applyCSSMinimizer(chain) {
|
|
|
56
56
|
chain.optimization.minimizer(import_shared.CHAIN_ID.MINIMIZER.CSS).use(import_core.SwcCssMinimizerRspackPlugin, []).end();
|
|
57
57
|
}
|
|
58
58
|
const pluginMinimize = () => ({
|
|
59
|
-
name: "
|
|
59
|
+
name: "rsbuild:minimize",
|
|
60
60
|
setup(api) {
|
|
61
61
|
api.modifyBundlerChain((chain, { isProd }) => {
|
|
62
62
|
const config = api.getNormalizedConfig();
|
|
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(output_exports);
|
|
|
34
34
|
var import_path = require("path");
|
|
35
35
|
var import_shared = require("@rsbuild/shared");
|
|
36
36
|
const pluginOutput = () => ({
|
|
37
|
-
name: "
|
|
37
|
+
name: "rsbuild:output",
|
|
38
38
|
setup(api) {
|
|
39
39
|
(0, import_shared.applyOutputPlugin)(api);
|
|
40
40
|
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
@@ -33,7 +33,7 @@ __export(progress_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(progress_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
35
|
const pluginProgress = () => ({
|
|
36
|
-
name: "
|
|
36
|
+
name: "rsbuild:progress",
|
|
37
37
|
setup(api) {
|
|
38
38
|
api.modifyBundlerChain(async (chain, { target, CHAIN_ID }) => {
|
|
39
39
|
var _a;
|
|
@@ -23,7 +23,7 @@ __export(resolve_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(resolve_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginResolve = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:resolve",
|
|
27
27
|
setup(api) {
|
|
28
28
|
(0, import_shared.applyResolvePlugin)(api);
|
|
29
29
|
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
@@ -50,7 +50,7 @@ const stopProfiler = (output, profileSession) => {
|
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
const pluginRspackProfile = () => ({
|
|
53
|
-
name: "
|
|
53
|
+
name: "rsbuild:rspack-profile",
|
|
54
54
|
setup(api) {
|
|
55
55
|
var _a;
|
|
56
56
|
const RSPACK_PROFILE = (_a = process.env.RSPACK_PROFILE) == null ? void 0 : _a.toUpperCase();
|
|
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(sass_exports);
|
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
35
|
function pluginSass() {
|
|
36
36
|
return {
|
|
37
|
-
name: "
|
|
37
|
+
name: "rsbuild:sass",
|
|
38
38
|
setup(api) {
|
|
39
39
|
api.onAfterCreateCompiler(({ compiler }) => {
|
|
40
40
|
(0, import_shared.patchCompilerGlobalLocation)(compiler);
|
|
@@ -60,7 +60,7 @@ async function getDefaultSwcConfig(config, rootPath, target) {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
const pluginSwc = () => ({
|
|
63
|
-
name: "
|
|
63
|
+
name: "rsbuild:swc",
|
|
64
64
|
setup(api) {
|
|
65
65
|
api.modifyBundlerChain(
|
|
66
66
|
async (chain, { CHAIN_ID, target, isServer, isServiceWorker }) => {
|
|
@@ -23,7 +23,7 @@ __export(transition_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(transition_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginTransition = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:transition",
|
|
27
27
|
setup(api) {
|
|
28
28
|
process.env.RSPACK_CONFIG_VALIDATE = "loose-silent";
|
|
29
29
|
api.modifyBundlerChain(async (chain, { isProd }) => {
|
|
@@ -84,7 +84,7 @@ class DevMiddleware extends import_events.EventEmitter {
|
|
|
84
84
|
callbacks,
|
|
85
85
|
hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0,
|
|
86
86
|
serverSideRender: true,
|
|
87
|
-
|
|
87
|
+
writeToDisk: devOptions.writeToDisk
|
|
88
88
|
});
|
|
89
89
|
return middleware;
|
|
90
90
|
}
|
package/dist/server/devServer.js
CHANGED
|
@@ -117,13 +117,14 @@ class RsbuildDevServer {
|
|
|
117
117
|
(0, import_middlewares.getHtmlFallbackMiddleware)({
|
|
118
118
|
distPath: (0, import_path.isAbsolute)(distPath) ? distPath : (0, import_path.join)(this.pwd, distPath),
|
|
119
119
|
publicPath: this.output.publicPath,
|
|
120
|
-
callback: devMiddleware.middleware
|
|
120
|
+
callback: devMiddleware.middleware,
|
|
121
|
+
htmlFallback: this.dev.htmlFallback
|
|
121
122
|
})
|
|
122
123
|
);
|
|
123
124
|
if (dev.historyApiFallback) {
|
|
124
125
|
const { default: connectHistoryApiFallback } = await Promise.resolve().then(() => __toESM(require("../../compiled/connect-history-api-fallback")));
|
|
125
126
|
const historyApiFallbackMiddleware = connectHistoryApiFallback(
|
|
126
|
-
|
|
127
|
+
dev.historyApiFallback === true ? {} : dev.historyApiFallback
|
|
127
128
|
);
|
|
128
129
|
this.middlewares.use(historyApiFallbackMiddleware);
|
|
129
130
|
devMiddleware.middleware && this.middlewares.use(devMiddleware.middleware);
|
|
@@ -135,9 +136,7 @@ class RsbuildDevServer {
|
|
|
135
136
|
const { dev } = this;
|
|
136
137
|
const devHttpsOption = typeof dev === "object" && dev.https;
|
|
137
138
|
if (devHttpsOption) {
|
|
138
|
-
|
|
139
|
-
const httpsOptions = await genHttpsOptions(devHttpsOption, this.pwd);
|
|
140
|
-
return (0, import_https.createServer)(httpsOptions, this.middlewares);
|
|
139
|
+
return (0, import_https.createServer)(devHttpsOption, this.middlewares);
|
|
141
140
|
} else {
|
|
142
141
|
return (0, import_http.createServer)(this.middlewares);
|
|
143
142
|
}
|
|
@@ -165,7 +164,7 @@ async function startDevServer(options, createDevMiddleware, {
|
|
|
165
164
|
logger: customLogger,
|
|
166
165
|
getPortSilently
|
|
167
166
|
} = {}) {
|
|
168
|
-
var _a, _b, _c, _d
|
|
167
|
+
var _a, _b, _c, _d;
|
|
169
168
|
if (!process.env.NODE_ENV) {
|
|
170
169
|
process.env.NODE_ENV = "development";
|
|
171
170
|
}
|
|
@@ -183,10 +182,10 @@ async function startDevServer(options, createDevMiddleware, {
|
|
|
183
182
|
open
|
|
184
183
|
};
|
|
185
184
|
const protocol = https ? "https" : "http";
|
|
186
|
-
let urls = (0, import_shared.getAddressUrls)(protocol, port,
|
|
185
|
+
let urls = (0, import_shared.getAddressUrls)(protocol, port, host);
|
|
187
186
|
const routes = (0, import_shared.formatRoutes)(
|
|
188
187
|
options.context.entry,
|
|
189
|
-
(
|
|
188
|
+
(_b = (_a = rsbuildConfig.output) == null ? void 0 : _a.distPath) == null ? void 0 : _b.html
|
|
190
189
|
);
|
|
191
190
|
(0, import_shared.debug)("create dev server");
|
|
192
191
|
const { devMiddleware, compiler } = await createDevMiddleware(
|
|
@@ -199,7 +198,7 @@ async function startDevServer(options, createDevMiddleware, {
|
|
|
199
198
|
devMiddleware,
|
|
200
199
|
dev: devServerConfig,
|
|
201
200
|
output: {
|
|
202
|
-
distPath: ((
|
|
201
|
+
distPath: ((_d = (_c = rsbuildConfig.output) == null ? void 0 : _c.distPath) == null ? void 0 : _d.root) || import_shared.ROOT_DIST_DIR,
|
|
203
202
|
publicPath
|
|
204
203
|
}
|
|
205
204
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { RequestHandler as Middleware } from '@rsbuild/shared';
|
|
1
|
+
import { RequestHandler as Middleware, HtmlFallback } from '@rsbuild/shared';
|
|
2
2
|
export declare const faviconFallbackMiddleware: Middleware;
|
|
3
3
|
export declare const notFoundMiddleware: Middleware;
|
|
4
4
|
export declare const getHtmlFallbackMiddleware: (params: {
|
|
5
5
|
distPath: string;
|
|
6
6
|
publicPath: string;
|
|
7
7
|
callback?: Middleware;
|
|
8
|
+
htmlFallback?: HtmlFallback;
|
|
8
9
|
}) => Middleware;
|
|
@@ -48,14 +48,14 @@ const notFoundMiddleware = (_req, res, _next) => {
|
|
|
48
48
|
res.statusCode = 404;
|
|
49
49
|
res.end();
|
|
50
50
|
};
|
|
51
|
-
const getHtmlFallbackMiddleware = ({ publicPath, distPath, callback }) => {
|
|
51
|
+
const getHtmlFallbackMiddleware = ({ htmlFallback, publicPath, distPath, callback }) => {
|
|
52
52
|
return (req, res, next) => {
|
|
53
53
|
if (
|
|
54
54
|
// Only accept GET or HEAD
|
|
55
55
|
req.method !== "GET" && req.method !== "HEAD" || // Require Accept header
|
|
56
56
|
!req.headers || typeof req.headers.accept !== "string" || // Ignore JSON requests
|
|
57
57
|
req.headers.accept.includes("application/json") || // Require Accept: text/html or */*
|
|
58
|
-
!(req.headers.accept.includes("text/html") || req.headers.accept.includes("*/*")) || !req.url
|
|
58
|
+
!(req.headers.accept.includes("text/html") || req.headers.accept.includes("*/*")) || !req.url || ["/favicon.ico"].includes(req.url)
|
|
59
59
|
) {
|
|
60
60
|
return next();
|
|
61
61
|
}
|
|
@@ -66,31 +66,43 @@ const getHtmlFallbackMiddleware = ({ publicPath, distPath, callback }) => {
|
|
|
66
66
|
const { devMiddleware } = res.locals.webpack;
|
|
67
67
|
outputFileSystem = devMiddleware.outputFileSystem;
|
|
68
68
|
}
|
|
69
|
-
const
|
|
69
|
+
const rewrite = (newUrl) => {
|
|
70
70
|
var _a;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
newUrl = (0, import_shared.urlJoin)(publicPath, newUrl);
|
|
72
|
+
(_a = import_shared.debug) == null ? void 0 : _a(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
|
|
73
|
+
req.url = newUrl;
|
|
74
|
+
if (callback) {
|
|
75
75
|
return callback(req, res, (...args) => {
|
|
76
|
-
req.url = url;
|
|
77
76
|
next(...args);
|
|
78
77
|
});
|
|
78
|
+
} else {
|
|
79
|
+
return next();
|
|
79
80
|
}
|
|
80
81
|
};
|
|
81
82
|
if (pathname.endsWith("/")) {
|
|
82
83
|
const newUrl = url + "index.html";
|
|
83
84
|
const filePath = import_path.default.join(distPath, pathname, "index.html");
|
|
84
|
-
|
|
85
|
+
if (outputFileSystem.existsSync(filePath)) {
|
|
86
|
+
return rewrite(newUrl);
|
|
87
|
+
}
|
|
85
88
|
} else if (
|
|
86
89
|
// '/main' => '/main.html'
|
|
87
90
|
!pathname.endsWith(".html")
|
|
88
91
|
) {
|
|
89
92
|
const newUrl = url + ".html";
|
|
90
93
|
const filePath = import_path.default.join(distPath, pathname + ".html");
|
|
91
|
-
|
|
94
|
+
if (outputFileSystem.existsSync(filePath)) {
|
|
95
|
+
return rewrite(newUrl);
|
|
96
|
+
}
|
|
92
97
|
} else {
|
|
93
|
-
|
|
98
|
+
if (outputFileSystem.existsSync(import_path.default.join(distPath, pathname))) {
|
|
99
|
+
return rewrite(url);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (htmlFallback === "index") {
|
|
103
|
+
if (outputFileSystem.existsSync(import_path.default.join(distPath, "index.html"))) {
|
|
104
|
+
return rewrite("/index.html");
|
|
105
|
+
}
|
|
94
106
|
}
|
|
95
107
|
next();
|
|
96
108
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
3
4
|
import type { ListenOptions } from 'net';
|
|
4
5
|
import { Server } from 'http';
|
|
5
6
|
import connect from '@rsbuild/shared/connect';
|
|
6
|
-
import { Context, RsbuildConfig, StartServerResult, PreviewServerOptions
|
|
7
|
+
import { type Context, type ServerConfig, type RsbuildConfig, type StartServerResult, type PreviewServerOptions } from '@rsbuild/shared';
|
|
7
8
|
type RsbuildProdServerOptions = {
|
|
8
9
|
pwd: string;
|
|
9
10
|
output: {
|
|
@@ -20,11 +21,13 @@ export declare class RsbuildProdServer {
|
|
|
20
21
|
onInit(app: Server): Promise<void>;
|
|
21
22
|
private applyDefaultMiddlewares;
|
|
22
23
|
private applyStaticAssetMiddleware;
|
|
23
|
-
createHTTPServer(): Promise<Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>;
|
|
24
|
+
createHTTPServer(): Promise<Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>;
|
|
24
25
|
listen(options?: number | ListenOptions | undefined, listener?: () => void): void;
|
|
25
26
|
close(): void;
|
|
26
27
|
}
|
|
27
28
|
export declare function startProdServer(context: Context, rsbuildConfig: RsbuildConfig, {
|
|
28
|
-
printURLs
|
|
29
|
+
printURLs,
|
|
30
|
+
strictPort,
|
|
31
|
+
getPortSilently
|
|
29
32
|
}?: PreviewServerOptions): Promise<StartServerResult>;
|
|
30
33
|
export {};
|
|
@@ -33,11 +33,13 @@ __export(prodServer_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(prodServer_exports);
|
|
35
35
|
var import_http = require("http");
|
|
36
|
+
var import_https = require("https");
|
|
36
37
|
var import_connect = __toESM(require("@rsbuild/shared/connect"));
|
|
37
38
|
var import_path = require("path");
|
|
38
39
|
var import_sirv = __toESM(require("../../compiled/sirv"));
|
|
39
40
|
var import_shared = require("@rsbuild/shared");
|
|
40
41
|
var import_middlewares = require("./middlewares");
|
|
42
|
+
var import_proxy = require("./proxy");
|
|
41
43
|
class RsbuildProdServer {
|
|
42
44
|
constructor(options) {
|
|
43
45
|
this.middlewares = (0, import_connect.default)();
|
|
@@ -49,7 +51,16 @@ class RsbuildProdServer {
|
|
|
49
51
|
await this.applyDefaultMiddlewares();
|
|
50
52
|
}
|
|
51
53
|
async applyDefaultMiddlewares() {
|
|
52
|
-
const { headers } = this.options.serverConfig;
|
|
54
|
+
const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
|
|
55
|
+
if (compress) {
|
|
56
|
+
const { default: compression } = await Promise.resolve().then(() => __toESM(require("../../compiled/http-compression")));
|
|
57
|
+
this.middlewares.use((req, res, next) => {
|
|
58
|
+
compression({
|
|
59
|
+
gzip: true,
|
|
60
|
+
brotli: false
|
|
61
|
+
})(req, res, next);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
53
64
|
if (headers) {
|
|
54
65
|
this.middlewares.use((_req, res, next) => {
|
|
55
66
|
for (const [key, value] of Object.entries(headers)) {
|
|
@@ -58,18 +69,34 @@ class RsbuildProdServer {
|
|
|
58
69
|
next();
|
|
59
70
|
});
|
|
60
71
|
}
|
|
72
|
+
if (proxy) {
|
|
73
|
+
const { middlewares } = (0, import_proxy.createProxyMiddleware)(proxy, this.app);
|
|
74
|
+
middlewares.forEach((middleware) => {
|
|
75
|
+
this.middlewares.use(middleware);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
61
78
|
this.applyStaticAssetMiddleware();
|
|
79
|
+
if (historyApiFallback) {
|
|
80
|
+
const { default: connectHistoryApiFallback } = await Promise.resolve().then(() => __toESM(require("../../compiled/connect-history-api-fallback")));
|
|
81
|
+
const historyApiFallbackMiddleware = connectHistoryApiFallback(
|
|
82
|
+
historyApiFallback === true ? {} : historyApiFallback
|
|
83
|
+
);
|
|
84
|
+
this.middlewares.use(historyApiFallbackMiddleware);
|
|
85
|
+
this.applyStaticAssetMiddleware();
|
|
86
|
+
}
|
|
62
87
|
this.middlewares.use(import_middlewares.faviconFallbackMiddleware);
|
|
63
88
|
}
|
|
64
89
|
applyStaticAssetMiddleware() {
|
|
65
90
|
const {
|
|
66
91
|
output: { path, assetPrefix },
|
|
92
|
+
serverConfig: { htmlFallback },
|
|
67
93
|
pwd
|
|
68
94
|
} = this.options;
|
|
69
95
|
const assetMiddleware = (0, import_sirv.default)((0, import_path.join)(pwd, path), {
|
|
70
96
|
etag: true,
|
|
71
97
|
dev: true,
|
|
72
|
-
ignores:
|
|
98
|
+
ignores: ["favicon.ico"],
|
|
99
|
+
single: htmlFallback === "index"
|
|
73
100
|
});
|
|
74
101
|
this.middlewares.use((req, res, next) => {
|
|
75
102
|
const url = req.url;
|
|
@@ -85,7 +112,13 @@ class RsbuildProdServer {
|
|
|
85
112
|
});
|
|
86
113
|
}
|
|
87
114
|
async createHTTPServer() {
|
|
88
|
-
|
|
115
|
+
const { serverConfig } = this.options;
|
|
116
|
+
const httpsOption = serverConfig.https;
|
|
117
|
+
if (httpsOption) {
|
|
118
|
+
return (0, import_https.createServer)(httpsOption, this.middlewares);
|
|
119
|
+
} else {
|
|
120
|
+
return (0, import_http.createServer)(this.middlewares);
|
|
121
|
+
}
|
|
89
122
|
}
|
|
90
123
|
listen(options, listener) {
|
|
91
124
|
const callback = () => {
|
|
@@ -101,31 +134,39 @@ class RsbuildProdServer {
|
|
|
101
134
|
this.app.close();
|
|
102
135
|
}
|
|
103
136
|
}
|
|
104
|
-
async function startProdServer(context, rsbuildConfig, {
|
|
105
|
-
|
|
137
|
+
async function startProdServer(context, rsbuildConfig, {
|
|
138
|
+
printURLs = true,
|
|
139
|
+
strictPort = false,
|
|
140
|
+
getPortSilently
|
|
141
|
+
} = {}) {
|
|
142
|
+
var _a, _b, _c;
|
|
106
143
|
if (!process.env.NODE_ENV) {
|
|
107
144
|
process.env.NODE_ENV = "production";
|
|
108
145
|
}
|
|
109
|
-
const port = await (0, import_shared.
|
|
146
|
+
const { serverConfig, port, host, https } = await (0, import_shared.getServerOptions)({
|
|
147
|
+
rsbuildConfig,
|
|
148
|
+
strictPort,
|
|
149
|
+
getPortSilently
|
|
150
|
+
});
|
|
110
151
|
const server = new RsbuildProdServer({
|
|
111
152
|
pwd: context.rootPath,
|
|
112
153
|
output: {
|
|
113
|
-
path: ((
|
|
114
|
-
assetPrefix: (
|
|
154
|
+
path: ((_b = (_a = rsbuildConfig.output) == null ? void 0 : _a.distPath) == null ? void 0 : _b.root) || import_shared.ROOT_DIST_DIR,
|
|
155
|
+
assetPrefix: (_c = rsbuildConfig.output) == null ? void 0 : _c.assetPrefix
|
|
115
156
|
},
|
|
116
|
-
serverConfig
|
|
157
|
+
serverConfig
|
|
117
158
|
});
|
|
118
159
|
const httpServer = await server.createHTTPServer();
|
|
119
160
|
await server.onInit(httpServer);
|
|
120
161
|
return new Promise((resolve) => {
|
|
121
162
|
server.listen(
|
|
122
163
|
{
|
|
123
|
-
host
|
|
164
|
+
host,
|
|
124
165
|
port
|
|
125
166
|
},
|
|
126
167
|
() => {
|
|
127
168
|
var _a2, _b2;
|
|
128
|
-
const urls = (0, import_shared.getAddressUrls)("http", port);
|
|
169
|
+
const urls = (0, import_shared.getAddressUrls)(https ? "https" : "http", port);
|
|
129
170
|
if (printURLs) {
|
|
130
171
|
const routes = (0, import_shared.formatRoutes)(
|
|
131
172
|
context.entry,
|
package/dist/server/proxy.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import http from 'http';
|
|
2
3
|
import { RequestHandler } from '@rsbuild/shared/http-proxy-middleware';
|
|
3
|
-
import { type ProxyDetail, type RequestHandler as Middleware, type
|
|
4
|
-
export declare function formatProxyOptions(proxyOptions:
|
|
4
|
+
import { type ProxyDetail, type RequestHandler as Middleware, type ProxyOptions } from '@rsbuild/shared';
|
|
5
|
+
export declare function formatProxyOptions(proxyOptions: ProxyOptions): ProxyDetail[];
|
|
5
6
|
export type HttpUpgradeHandler = NonNullable<RequestHandler['upgrade']>;
|
|
6
|
-
export declare const createProxyMiddleware: (proxyOptions:
|
|
7
|
+
export declare const createProxyMiddleware: (proxyOptions: ProxyOptions, app: http.Server) => {
|
|
7
8
|
middlewares: Middleware[];
|
|
8
9
|
};
|
package/dist/server/restart.js
CHANGED
|
@@ -52,7 +52,10 @@ const restartDevServer = async ({ filePath }) => {
|
|
|
52
52
|
for (const cleaner of cleaners) {
|
|
53
53
|
await cleaner();
|
|
54
54
|
}
|
|
55
|
-
const rsbuild = await (0, import_commands.init)();
|
|
55
|
+
const rsbuild = await (0, import_commands.init)({ isRestart: true });
|
|
56
|
+
if (!rsbuild) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
56
59
|
await rsbuild.startDevServer();
|
|
57
60
|
};
|
|
58
61
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/core",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Unleash the power of Rspack with the out-of-the-box build tool.",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"bugs": {
|
|
@@ -58,19 +58,19 @@
|
|
|
58
58
|
"types.d.ts"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@rspack/core": "0.
|
|
61
|
+
"@rspack/core": "0.4.0",
|
|
62
62
|
"core-js": "~3.32.2",
|
|
63
63
|
"html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
|
|
64
64
|
"postcss": "8.4.31",
|
|
65
65
|
"semver": "^7.5.4",
|
|
66
66
|
"ws": "^8.2.0",
|
|
67
|
-
"@rsbuild/shared": "0.0
|
|
67
|
+
"@rsbuild/shared": "0.1.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@types/node": "^16",
|
|
71
71
|
"@types/ws": "^8.2.0",
|
|
72
72
|
"@types/semver": "^7.5.4",
|
|
73
|
-
"typescript": "^5.
|
|
73
|
+
"typescript": "^5.3.0"
|
|
74
74
|
},
|
|
75
75
|
"engines": {
|
|
76
76
|
"node": ">=14.0.0"
|
package/dist/server/https.d.ts
DELETED
package/dist/server/https.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var https_exports = {};
|
|
20
|
-
__export(https_exports, {
|
|
21
|
-
genHttpsOptions: () => genHttpsOptions
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(https_exports);
|
|
24
|
-
var import_shared = require("@rsbuild/shared");
|
|
25
|
-
const genHttpsOptions = async (userOptions, pwd) => {
|
|
26
|
-
const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
|
|
27
|
-
if (!httpsOptions.key || !httpsOptions.cert) {
|
|
28
|
-
let devcertPath;
|
|
29
|
-
try {
|
|
30
|
-
devcertPath = require.resolve("devcert", { paths: [pwd, __dirname] });
|
|
31
|
-
} catch (err) {
|
|
32
|
-
const command = import_shared.color.bold(import_shared.color.yellow(`npm add devcert@1.2.2 -D`));
|
|
33
|
-
import_shared.logger.error(
|
|
34
|
-
`You have enabled "dev.https" option, but the "devcert" package is not installed.`
|
|
35
|
-
);
|
|
36
|
-
import_shared.logger.error(
|
|
37
|
-
`Please run ${command} to install manually, otherwise the https can not work.`
|
|
38
|
-
);
|
|
39
|
-
throw new Error('[https] "devcert" is not found.');
|
|
40
|
-
}
|
|
41
|
-
const devcert = require(devcertPath);
|
|
42
|
-
const selfsign = await devcert.certificateFor(["localhost"]);
|
|
43
|
-
return selfsign;
|
|
44
|
-
}
|
|
45
|
-
return httpsOptions;
|
|
46
|
-
};
|
|
47
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
-
0 && (module.exports = {
|
|
49
|
-
genHttpsOptions
|
|
50
|
-
});
|