diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index f059fa407a..7aeb1a0c98 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -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'; diff --git a/packages/core/src/initPlugins.ts b/packages/core/src/initPlugins.ts index 42494d161b..a8ded4eeb9 100644 --- a/packages/core/src/initPlugins.ts +++ b/packages/core/src/initPlugins.ts @@ -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, @@ -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 = ( diff --git a/packages/core/tests/__snapshots__/environments.test.ts.snap b/packages/core/tests/__snapshots__/environments.test.ts.snap index bbc4147add..e0d9382554 100644 --- a/packages/core/tests/__snapshots__/environments.test.ts.snap +++ b/packages/core/tests/__snapshots__/environments.test.ts.snap @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/website/docs/en/config/output/dist-path.mdx b/website/docs/en/config/output/dist-path.mdx index 167712f286..95997c4958 100644 --- a/website/docs/en/config/output/dist-path.mdx +++ b/website/docs/en/config/output/dist-path.mdx @@ -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', diff --git a/website/docs/zh/config/output/dist-path.mdx b/website/docs/zh/config/output/dist-path.mdx index 83763acbd7..14b0eaeea9 100644 --- a/website/docs/zh/config/output/dist-path.mdx +++ b/website/docs/zh/config/output/dist-path.mdx @@ -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',