Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: remove output.distPath.server #2696

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion e2e/cases/babel/preset-node/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ rspackOnlyTest(
runServer: true,
});

const { foo } = await import('./dist/server/index.js');
// @ts-ignore .js file
const { foo } = await import('./dist/index.js');
expect(foo).toEqual(1);
},
);
14 changes: 6 additions & 8 deletions e2e/cases/node-addons/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ test('should compile Node addons correctly', async () => {
file.endsWith('test.darwin.node'),
);

expect(addonFile?.includes('server/test.darwin.node')).toBeTruthy();
expect(addonFile?.includes('/test.darwin.node')).toBeTruthy();

expect(
fs.existsSync(join(__dirname, 'dist', 'server', 'test.darwin.node')),
fs.existsSync(join(__dirname, 'dist', 'test.darwin.node')),
).toBeTruthy();

// the `test.darwin.node` is only compatible with darwin
if (process.platform === 'darwin') {
const content = await import('./dist/server/index.js');
const content = await import('./dist/index.js');
expect(typeof (content.default as any).readLength).toEqual('function');
}
});
Expand Down Expand Up @@ -61,14 +61,12 @@ test('should compile Node addons in the node_modules correctly', async () => {
file.endsWith('other.node'),
);

expect(addonFile?.includes('server/other.node')).toBeTruthy();
expect(addonFile?.includes('/other.node')).toBeTruthy();

expect(
fs.existsSync(join(__dirname, 'dist', 'server', 'other.node')),
).toBeTruthy();
expect(fs.existsSync(join(__dirname, 'dist', 'other.node'))).toBeTruthy();

if (process.platform === 'darwin') {
const content = await import('./dist/server/index.js');
const content = await import('./dist/index.js');
expect(typeof (content.default as any).readLength).toEqual('function');
}
});
2 changes: 1 addition & 1 deletion e2e/cases/output/externals/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join, resolve } from 'node:path';
import { resolve } from 'node:path';
import { build, gotoPage } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { pluginReact } from '@rsbuild/plugin-react';
Expand Down
3 changes: 3 additions & 0 deletions e2e/cases/performance/print-file-size/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ test.describe('should print file size correctly', async () => {
node: {
output: {
target: 'node',
distPath: {
root: 'dist/server',
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default {
node: {
output: {
target: 'node',
distPath: {
root: 'dist/server',
},
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions e2e/cases/source/alias-by-target/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export default defineConfig({
},
output: {
target: 'node',
distPath: {
root: 'dist/server',
},
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions e2e/cases/source/multiple-entry/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default defineConfig({
node: {
output: {
target: 'node',
distPath: {
root: 'dist/server',
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
"library": {
"type": "commonjs2",
},
"path": "<ROOT>/packages/compat/webpack/tests/dist/server",
"path": "<ROOT>/packages/compat/webpack/tests/dist",
"pathinfo": false,
"publicPath": "/",
"webassemblyModuleFilename": "static/wasm/[hash].module.wasm",
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
JS_DIST_DIR,
MEDIA_DIST_DIR,
ROOT_DIST_DIR,
SERVER_DIST_DIR,
SVG_DIST_DIR,
TS_CONFIG_FILE,
WASM_DIST_DIR,
Expand Down Expand Up @@ -135,7 +134,6 @@ const getDefaultOutputConfig = (): NormalizedOutputConfig => ({
wasm: WASM_DIST_DIR,
image: IMAGE_DIST_DIR,
media: MEDIA_DIST_DIR,
server: SERVER_DIST_DIR,
},
assetPrefix: DEFAULT_ASSET_PREFIX,
filename: {},
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { join } from 'node:path';
// loaders will be emitted to the same folder of the main bundle
export const ROOT_DIST_DIR = 'dist';
export const HTML_DIST_DIR = '/';
export const SERVER_DIST_DIR = 'server';
export const JS_DIST_DIR = 'static/js';
export const CSS_DIST_DIR = 'static/css';
export const SVG_DIST_DIR = 'static/svg';
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/plugins/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ export const pluginOutput = (): RsbuildPlugin => ({
.hashFunction('xxhash64');

if (isServer) {
const serverPath = config.output.distPath.server;

chain.output
.path(posix.join(distPath, serverPath))
.filename('[name].js')
.chunkFilename('[name].js')
.library({
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/plugins/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export const pluginPerformance = (): RsbuildPlugin => ({
if (rsbuildConfig.performance?.profile) {
applyBundleAnalyzeConfig(rsbuildConfig);
} else if (rsbuildConfig.environments) {
for (const config of Object.values(
rsbuildConfig.environments,
)) {
for (const config of Object.values(rsbuildConfig.environments)) {
if (config.performance?.profile) {
applyBundleAnalyzeConfig(config);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
"library": {
"type": "commonjs2",
},
"path": "<ROOT>/packages/core/tests/dist/server",
"path": "<ROOT>/packages/core/tests/dist",
"pathinfo": false,
"publicPath": "/",
"webassemblyModuleFilename": "static/wasm/[hash].module.wasm",
Expand Down
6 changes: 0 additions & 6 deletions packages/core/tests/__snapshots__/environments.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ exports[`environment config > should normalize environment config correctly 1`]
"js": "static/js",
"media": "static/media",
"root": "dist",
"server": "server",
"svg": "static/svg",
"wasm": "static/wasm",
},
Expand Down Expand Up @@ -201,7 +200,6 @@ exports[`environment config > should print environment config when inspect confi
"js": "static/js",
"media": "static/media",
"root": "dist",
"server": "server",
"svg": "static/svg",
"wasm": "static/wasm",
},
Expand Down Expand Up @@ -319,7 +317,6 @@ exports[`environment config > should print environment config when inspect confi
"js": "static/js",
"media": "static/media",
"root": "dist",
"server": "server",
"svg": "static/svg",
"wasm": "static/wasm",
},
Expand Down Expand Up @@ -442,7 +439,6 @@ exports[`environment config > should support modify environment config by api.mo
"js": "static/js",
"media": "static/media",
"root": "dist",
"server": "server",
"svg": "static/svg",
"wasm": "static/wasm",
},
Expand Down Expand Up @@ -560,7 +556,6 @@ exports[`environment config > should support modify environment config by api.mo
"js": "static/js",
"media": "static/media",
"root": "dist",
"server": "server",
"svg": "static/svg",
"wasm": "static/wasm",
},
Expand Down Expand Up @@ -679,7 +674,6 @@ exports[`environment config > should support modify environment config by api.mo
"js": "static/js",
"media": "static/media",
"root": "dist",
"server": "server",
"svg": "static/svg",
"wasm": "static/wasm",
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/__snapshots__/output.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`plugin-output > should allow to custom server directory with distPath.server 1`] = `
exports[`plugin-output > should allow to custom server directory with distPath.root 1`] = `
{
"output": {
"chunkFilename": "[name].js",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ describe('plugin-output', () => {
expect(bundlerConfigs[0]).toMatchSnapshot();
});

it('should allow to custom server directory with distPath.server', async () => {
it('should allow to custom server directory with distPath.root', async () => {
const rsbuild = await createStubRsbuild({
plugins: [pluginOutput()],
rsbuildConfig: {
output: {
target: 'node',
distPath: {
server: 'server',
root: 'dist/server',
},
},
},
Expand Down
5 changes: 0 additions & 5 deletions packages/shared/src/types/config/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ export type DistPathConfig = {
* @default 'static/media'
*/
media?: string;
/**
* The output directory of server bundles when target is `node`.
* @default 'server'
*/
server?: string;
};

export type FilenameConfig = {
Expand Down
3 changes: 0 additions & 3 deletions website/docs/en/config/output/dist-path.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type DistPathConfig = {
wasm?: string;
image?: string;
media?: string;
server?: string;
};
```

Expand All @@ -34,7 +33,6 @@ const defaultDistPath = {
wasm: 'static/wasm',
image: 'static/image',
media: 'static/media',
server: 'server',
};
```

Expand All @@ -53,7 +51,6 @@ Detail:
- `wasm`: The output directory of WebAssembly files.
- `image`: The output directory of non-SVG images.
- `media`: The output directory of media assets, such as videos.
- `server`: The output directory of server bundles when [target](/config/output/targets) is `node`.

### Root Directory

Expand Down
18 changes: 14 additions & 4 deletions website/docs/en/guide/basic/output-files.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,25 @@ dist

Node.js files usually only contain JS files, no HTML or CSS. Also, JS file names will not contain hash.

You can modify the output path of Node.js files through the [output.distPath.server](/config/output/dist-path) config.
You can modify the output path of Node.js files via the [environments](/config/environments) config.

For example, output Node.js files to the `server` directory:

```ts
export default {
output: {
distPath: {
server: 'server',
environments: {
web: {
output: {
target: 'web',
},
},
node: {
output: {
target: 'node',
distPath: {
root: 'dist/server',
},
},
},
},
};
Expand Down
3 changes: 0 additions & 3 deletions website/docs/zh/config/output/dist-path.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type DistPathConfig = {
wasm?: string;
image?: string;
media?: string;
server?: string;
};
```

Expand All @@ -34,7 +33,6 @@ const defaultDistPath = {
wasm: 'static/wasm',
image: 'static/image',
media: 'static/media',
server: 'server',
};
```

Expand All @@ -53,7 +51,6 @@ const defaultDistPath = {
- `wasm`:表示 WebAssembly 文件的输出目录。
- `image`:表示非 SVG 图片的输出目录。
- `media`:表示视频等媒体资源的输出目录。
- `server`: 表示服务端产物的输出目录,仅在 [target](/config/output/targets) 为 `node` 时有效。

### 根目录

Expand Down
20 changes: 15 additions & 5 deletions website/docs/zh/guide/basic/output-files.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,25 @@ dist

Node.js 产物通常只包含 JS 文件,不包含 HTML、CSS 等文件。此外,Node 产物的 JS 文件名称也不会自动生成哈希值。

你可以通过 [output.distPath.server](/config/output/dist-path) 配置项来修改 Node 产物的输出路径。
你可以通过 [environments](/config/environments) 配置项来修改 Node 产物的输出路径。

比如,将 Node.js 产物输出到 `server` 目录:
比如,将 Node.js 产物输出到 `dist/server` 目录:

```ts
export default {
output: {
distPath: {
server: 'server',
environments: {
web: {
output: {
target: 'web',
},
},
node: {
output: {
target: 'node',
distPath: {
root: 'dist/server',
},
},
},
},
};
Expand Down
Loading