Skip to content

Commit

Permalink
feat(core): warn leading slash for output.distPath.html and default t…
Browse files Browse the repository at this point in the history
…o `./` (#3462)

Co-authored-by: neverland <[email protected]>
  • Loading branch information
wjw99830 and chenjiahan authored Sep 13, 2024
1 parent f95a6fc commit b3967b8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/constants.ts
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 = './';
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

0 comments on commit b3967b8

Please sign in to comment.