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

feat(core): warn leading slash for output.distPath.html and default to ./ #3462

Merged
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
2 changes: 1 addition & 1 deletion packages/core/src/constants.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title can be updated~

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from 'node:path';
// Paths
// 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 HTML_DIST_DIR = './';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value in documentation can be updated too

export const JS_DIST_DIR = 'static/js';
export const CSS_DIST_DIR = 'static/css';
export const SVG_DIST_DIR = 'static/svg';
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/initPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LOADER_PATH } from './constants';
import { createPublicContext } from './createContext';
import { removeLeadingSlash } from './helpers';
import type { TransformLoaderOptions } from './loader/transformLoader';
import { logger } from './logger';
import { isPluginMatchEnvironment } from './pluginManager';
import type {
GetRsbuildConfig,
Expand Down Expand Up @@ -34,7 +35,15 @@ export function getHTMLPathByEntry(
filename = `${entryName}/index.html`;
}

return removeLeadingSlash(posix.join(config.output.distPath.html, filename));
const prefix = config.output.distPath.html;

if (prefix.startsWith('/')) {
logger.warn(
`Absolute path is not recommended at \`output.distPath.html\`: "${prefix}", please use relative path instead.`,
);
}

return removeLeadingSlash(posix.join(prefix, filename));
}

const mapProcessAssetsStage = (
Expand Down
18 changes: 9 additions & 9 deletions packages/core/tests/__snapshots__/environments.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ exports[`environment config > should normalize environment config correctly 1`]
"distPath": {
"css": "static/css",
"font": "static/font",
"html": "/",
"html": "./",
"image": "static/image",
"js": "static/js",
"media": "static/media",
Expand Down Expand Up @@ -175,7 +175,7 @@ exports[`environment config > should normalize environment config correctly 2`]
"distPath": {
"css": "static/css",
"font": "static/font",
"html": "/",
"html": "./",
"image": "static/image",
"js": "",
"media": "static/media",
Expand Down Expand Up @@ -300,7 +300,7 @@ exports[`environment config > should print environment config when inspect confi
"distPath": {
"css": "static/css",
"font": "static/font",
"html": "/",
"html": "./",
"image": "static/image",
"js": "static/js",
"media": "static/media",
Expand Down Expand Up @@ -457,7 +457,7 @@ exports[`environment config > should print environment config when inspect confi
"distPath": {
"css": "static/css",
"font": "static/font",
"html": "/",
"html": "./",
"image": "static/image",
"js": "static/js",
"media": "static/media",
Expand Down Expand Up @@ -632,7 +632,7 @@ exports[`environment config > should support modify environment config by api.mo
"distPath": {
"css": "static/css",
"font": "static/font",
"html": "/",
"html": "./",
"image": "static/image",
"js": "static/js",
"media": "static/media",
Expand Down Expand Up @@ -790,7 +790,7 @@ exports[`environment config > should support modify environment config by api.mo
"distPath": {
"css": "static/css",
"font": "static/font",
"html": "/",
"html": "./",
"image": "static/image",
"js": "static/js",
"media": "static/media",
Expand Down Expand Up @@ -949,7 +949,7 @@ exports[`environment config > should support modify environment config by api.mo
"distPath": {
"css": "static/css",
"font": "static/font",
"html": "/",
"html": "./",
"image": "static/image",
"js": "static/js",
"media": "static/media",
Expand Down Expand Up @@ -1111,7 +1111,7 @@ exports[`environment config > should support modify single environment config by
"distPath": {
"css": "static/css",
"font": "static/font",
"html": "/",
"html": "./",
"image": "static/image",
"js": "static/js",
"media": "static/media",
Expand Down Expand Up @@ -1269,7 +1269,7 @@ exports[`environment config > should support modify single environment config by
"distPath": {
"css": "static/css",
"font": "static/font",
"html": "/",
"html": "./",
"image": "static/image",
"js": "static/js",
"media": "static/media",
Expand Down
2 changes: 1 addition & 1 deletion website/docs/en/config/output/dist-path.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type DistPathConfig = {
```js
const defaultDistPath = {
root: 'dist',
html: '/',
html: './',
js: isServer ? '' : 'static/js',
jsAsync: isServer ? '' : 'static/js/async',
css: 'static/css',
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/config/output/dist-path.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type DistPathConfig = {
```js
const defaultDistPath = {
root: 'dist',
html: '/',
html: './',
js: isServer ? '' : 'static/js',
jsAsync: isServer ? '' : 'static/js/async',
css: 'static/css',
Expand Down
Loading