@rsbuild/core 0.0.27 → 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/config.js +1 -0
- 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 +10 -10
- package/dist/server/middlewares.d.ts +2 -1
- package/dist/server/middlewares.js +23 -11
- package/dist/server/prodServer.d.ts +7 -3
- package/dist/server/prodServer.js +61 -10
- 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"));
|
|
@@ -26,6 +26,7 @@ module.exports = __toCommonJS(config_exports);
|
|
|
26
26
|
var import_shared = require("@rsbuild/shared");
|
|
27
27
|
const createDefaultConfig = () => ({
|
|
28
28
|
dev: (0, import_shared.getDefaultDevConfig)(),
|
|
29
|
+
server: (0, import_shared.getDefaultServerConfig)(),
|
|
29
30
|
html: (0, import_shared.getDefaultHtmlConfig)(),
|
|
30
31
|
source: (0, import_shared.getDefaultSourceConfig)(),
|
|
31
32
|
output: (0, import_shared.getDefaultOutputConfig)(),
|
|
@@ -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
|
@@ -112,17 +112,19 @@ class RsbuildDevServer {
|
|
|
112
112
|
}
|
|
113
113
|
devMiddleware.init(app);
|
|
114
114
|
devMiddleware.middleware && this.middlewares.use(devMiddleware.middleware);
|
|
115
|
+
const { distPath } = this.output;
|
|
115
116
|
this.middlewares.use(
|
|
116
117
|
(0, import_middlewares.getHtmlFallbackMiddleware)({
|
|
117
|
-
distPath: (0, import_path.join)(this.pwd,
|
|
118
|
+
distPath: (0, import_path.isAbsolute)(distPath) ? distPath : (0, import_path.join)(this.pwd, distPath),
|
|
118
119
|
publicPath: this.output.publicPath,
|
|
119
|
-
callback: devMiddleware.middleware
|
|
120
|
+
callback: devMiddleware.middleware,
|
|
121
|
+
htmlFallback: this.dev.htmlFallback
|
|
120
122
|
})
|
|
121
123
|
);
|
|
122
124
|
if (dev.historyApiFallback) {
|
|
123
125
|
const { default: connectHistoryApiFallback } = await Promise.resolve().then(() => __toESM(require("../../compiled/connect-history-api-fallback")));
|
|
124
126
|
const historyApiFallbackMiddleware = connectHistoryApiFallback(
|
|
125
|
-
|
|
127
|
+
dev.historyApiFallback === true ? {} : dev.historyApiFallback
|
|
126
128
|
);
|
|
127
129
|
this.middlewares.use(historyApiFallbackMiddleware);
|
|
128
130
|
devMiddleware.middleware && this.middlewares.use(devMiddleware.middleware);
|
|
@@ -134,9 +136,7 @@ class RsbuildDevServer {
|
|
|
134
136
|
const { dev } = this;
|
|
135
137
|
const devHttpsOption = typeof dev === "object" && dev.https;
|
|
136
138
|
if (devHttpsOption) {
|
|
137
|
-
|
|
138
|
-
const httpsOptions = await genHttpsOptions(devHttpsOption, this.pwd);
|
|
139
|
-
return (0, import_https.createServer)(httpsOptions, this.middlewares);
|
|
139
|
+
return (0, import_https.createServer)(devHttpsOption, this.middlewares);
|
|
140
140
|
} else {
|
|
141
141
|
return (0, import_http.createServer)(this.middlewares);
|
|
142
142
|
}
|
|
@@ -164,7 +164,7 @@ async function startDevServer(options, createDevMiddleware, {
|
|
|
164
164
|
logger: customLogger,
|
|
165
165
|
getPortSilently
|
|
166
166
|
} = {}) {
|
|
167
|
-
var _a, _b, _c, _d
|
|
167
|
+
var _a, _b, _c, _d;
|
|
168
168
|
if (!process.env.NODE_ENV) {
|
|
169
169
|
process.env.NODE_ENV = "development";
|
|
170
170
|
}
|
|
@@ -182,10 +182,10 @@ async function startDevServer(options, createDevMiddleware, {
|
|
|
182
182
|
open
|
|
183
183
|
};
|
|
184
184
|
const protocol = https ? "https" : "http";
|
|
185
|
-
let urls = (0, import_shared.getAddressUrls)(protocol, port,
|
|
185
|
+
let urls = (0, import_shared.getAddressUrls)(protocol, port, host);
|
|
186
186
|
const routes = (0, import_shared.formatRoutes)(
|
|
187
187
|
options.context.entry,
|
|
188
|
-
(
|
|
188
|
+
(_b = (_a = rsbuildConfig.output) == null ? void 0 : _a.distPath) == null ? void 0 : _b.html
|
|
189
189
|
);
|
|
190
190
|
(0, import_shared.debug)("create dev server");
|
|
191
191
|
const { devMiddleware, compiler } = await createDevMiddleware(
|
|
@@ -198,7 +198,7 @@ async function startDevServer(options, createDevMiddleware, {
|
|
|
198
198
|
devMiddleware,
|
|
199
199
|
dev: devServerConfig,
|
|
200
200
|
output: {
|
|
201
|
-
distPath: ((
|
|
201
|
+
distPath: ((_d = (_c = rsbuildConfig.output) == null ? void 0 : _c.distPath) == null ? void 0 : _d.root) || import_shared.ROOT_DIST_DIR,
|
|
202
202
|
publicPath
|
|
203
203
|
}
|
|
204
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,15 +1,17 @@
|
|
|
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 } from '@rsbuild/shared';
|
|
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: {
|
|
10
11
|
path: string;
|
|
11
12
|
assetPrefix?: string;
|
|
12
13
|
};
|
|
14
|
+
serverConfig: ServerConfig;
|
|
13
15
|
};
|
|
14
16
|
export declare class RsbuildProdServer {
|
|
15
17
|
private app;
|
|
@@ -19,11 +21,13 @@ export declare class RsbuildProdServer {
|
|
|
19
21
|
onInit(app: Server): Promise<void>;
|
|
20
22
|
private applyDefaultMiddlewares;
|
|
21
23
|
private applyStaticAssetMiddleware;
|
|
22
|
-
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>>;
|
|
23
25
|
listen(options?: number | ListenOptions | undefined, listener?: () => void): void;
|
|
24
26
|
close(): void;
|
|
25
27
|
}
|
|
26
28
|
export declare function startProdServer(context: Context, rsbuildConfig: RsbuildConfig, {
|
|
27
|
-
printURLs
|
|
29
|
+
printURLs,
|
|
30
|
+
strictPort,
|
|
31
|
+
getPortSilently
|
|
28
32
|
}?: PreviewServerOptions): Promise<StartServerResult>;
|
|
29
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,18 +51,52 @@ class RsbuildProdServer {
|
|
|
49
51
|
await this.applyDefaultMiddlewares();
|
|
50
52
|
}
|
|
51
53
|
async applyDefaultMiddlewares() {
|
|
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
|
+
}
|
|
64
|
+
if (headers) {
|
|
65
|
+
this.middlewares.use((_req, res, next) => {
|
|
66
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
67
|
+
res.setHeader(key, value);
|
|
68
|
+
}
|
|
69
|
+
next();
|
|
70
|
+
});
|
|
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
|
+
}
|
|
52
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
|
+
}
|
|
53
87
|
this.middlewares.use(import_middlewares.faviconFallbackMiddleware);
|
|
54
88
|
}
|
|
55
89
|
applyStaticAssetMiddleware() {
|
|
56
90
|
const {
|
|
57
91
|
output: { path, assetPrefix },
|
|
92
|
+
serverConfig: { htmlFallback },
|
|
58
93
|
pwd
|
|
59
94
|
} = this.options;
|
|
60
95
|
const assetMiddleware = (0, import_sirv.default)((0, import_path.join)(pwd, path), {
|
|
61
96
|
etag: true,
|
|
62
97
|
dev: true,
|
|
63
|
-
ignores:
|
|
98
|
+
ignores: ["favicon.ico"],
|
|
99
|
+
single: htmlFallback === "index"
|
|
64
100
|
});
|
|
65
101
|
this.middlewares.use((req, res, next) => {
|
|
66
102
|
const url = req.url;
|
|
@@ -76,7 +112,13 @@ class RsbuildProdServer {
|
|
|
76
112
|
});
|
|
77
113
|
}
|
|
78
114
|
async createHTTPServer() {
|
|
79
|
-
|
|
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
|
+
}
|
|
80
122
|
}
|
|
81
123
|
listen(options, listener) {
|
|
82
124
|
const callback = () => {
|
|
@@ -92,30 +134,39 @@ class RsbuildProdServer {
|
|
|
92
134
|
this.app.close();
|
|
93
135
|
}
|
|
94
136
|
}
|
|
95
|
-
async function startProdServer(context, rsbuildConfig, {
|
|
96
|
-
|
|
137
|
+
async function startProdServer(context, rsbuildConfig, {
|
|
138
|
+
printURLs = true,
|
|
139
|
+
strictPort = false,
|
|
140
|
+
getPortSilently
|
|
141
|
+
} = {}) {
|
|
142
|
+
var _a, _b, _c;
|
|
97
143
|
if (!process.env.NODE_ENV) {
|
|
98
144
|
process.env.NODE_ENV = "production";
|
|
99
145
|
}
|
|
100
|
-
const port = await (0, import_shared.
|
|
146
|
+
const { serverConfig, port, host, https } = await (0, import_shared.getServerOptions)({
|
|
147
|
+
rsbuildConfig,
|
|
148
|
+
strictPort,
|
|
149
|
+
getPortSilently
|
|
150
|
+
});
|
|
101
151
|
const server = new RsbuildProdServer({
|
|
102
152
|
pwd: context.rootPath,
|
|
103
153
|
output: {
|
|
104
|
-
path: ((
|
|
105
|
-
assetPrefix: (
|
|
106
|
-
}
|
|
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
|
|
156
|
+
},
|
|
157
|
+
serverConfig
|
|
107
158
|
});
|
|
108
159
|
const httpServer = await server.createHTTPServer();
|
|
109
160
|
await server.onInit(httpServer);
|
|
110
161
|
return new Promise((resolve) => {
|
|
111
162
|
server.listen(
|
|
112
163
|
{
|
|
113
|
-
host
|
|
164
|
+
host,
|
|
114
165
|
port
|
|
115
166
|
},
|
|
116
167
|
() => {
|
|
117
168
|
var _a2, _b2;
|
|
118
|
-
const urls = (0, import_shared.getAddressUrls)("http", port);
|
|
169
|
+
const urls = (0, import_shared.getAddressUrls)(https ? "https" : "http", port);
|
|
119
170
|
if (printURLs) {
|
|
120
171
|
const routes = (0, import_shared.formatRoutes)(
|
|
121
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