@rsbuild/shared
Advanced tools
Comparing version 0.3.9 to 0.3.10
@@ -199,2 +199,4 @@ import type { BundlerChain, RspackConfig, RsbuildConfig, RsbuildContext, CreateAsyncHook, BundlerChainRule, NormalizedConfig, RsbuildPluginAPI, ModifyBundlerChainFn, ModifyBundlerChainUtils, BuiltinSwcLoaderOptions } from './types'; | ||
}): void; | ||
export declare const formatPublicPath: (publicPath: string, withSlash?: boolean) => string; | ||
export declare const getPublicPathFromChain: (chain: BundlerChain, withSlash?: boolean) => string; | ||
export declare function applyOutputPlugin(api: RsbuildPluginAPI): void; | ||
@@ -201,0 +203,0 @@ export declare function applyResolvePlugin(api: RsbuildPluginAPI): void; |
@@ -36,3 +36,5 @@ "use strict"; | ||
chainToConfig: () => chainToConfig, | ||
formatPublicPath: () => formatPublicPath, | ||
getBundlerChain: () => getBundlerChain, | ||
getPublicPathFromChain: () => getPublicPathFromChain, | ||
modifyBundlerChain: () => modifyBundlerChain, | ||
@@ -269,29 +271,42 @@ modifySwcLoaderOptions: () => modifySwcLoaderOptions | ||
} | ||
function applyOutputPlugin(api) { | ||
function getPublicPath({ | ||
config, | ||
isProd, | ||
context | ||
}) { | ||
const { dev, output } = config; | ||
let publicPath = import_constants.DEFAULT_ASSET_PREFIX; | ||
if (isProd) { | ||
if (output.assetPrefix) { | ||
publicPath = output.assetPrefix; | ||
} | ||
} else if (typeof dev.assetPrefix === "string") { | ||
publicPath = dev.assetPrefix; | ||
} else if (dev.assetPrefix === true) { | ||
const protocol = context.devServer?.https ? "https" : "http"; | ||
const hostname = context.devServer?.hostname || import_constants.DEFAULT_DEV_HOST; | ||
const port = context.devServer?.port || import_constants.DEFAULT_PORT; | ||
if (hostname === import_constants.DEFAULT_DEV_HOST) { | ||
const localHostname = "localhost"; | ||
publicPath = `${protocol}://${localHostname}:${port}/`; | ||
} else { | ||
publicPath = `${protocol}://${hostname}:${port}/`; | ||
} | ||
const formatPublicPath = (publicPath, withSlash = true) => { | ||
if (publicPath === "auto") { | ||
return publicPath; | ||
} | ||
return withSlash ? (0, import_utils.addTrailingSlash)(publicPath) : (0, import_utils.removeTailingSlash)(publicPath); | ||
}; | ||
const getPublicPathFromChain = (chain, withSlash = true) => { | ||
const publicPath = chain.output.get("publicPath"); | ||
if (typeof publicPath === "string") { | ||
return formatPublicPath(publicPath, withSlash); | ||
} | ||
return formatPublicPath(import_constants.DEFAULT_ASSET_PREFIX, withSlash); | ||
}; | ||
function getPublicPath({ | ||
config, | ||
isProd, | ||
context | ||
}) { | ||
const { dev, output } = config; | ||
let publicPath = import_constants.DEFAULT_ASSET_PREFIX; | ||
if (isProd) { | ||
if (typeof output.assetPrefix === "string") { | ||
publicPath = output.assetPrefix; | ||
} | ||
return (0, import_utils.addTrailingSlash)(publicPath); | ||
} else if (typeof dev.assetPrefix === "string") { | ||
publicPath = dev.assetPrefix; | ||
} else if (dev.assetPrefix === true) { | ||
const protocol = context.devServer?.https ? "https" : "http"; | ||
const hostname = context.devServer?.hostname || import_constants.DEFAULT_DEV_HOST; | ||
const port = context.devServer?.port || import_constants.DEFAULT_PORT; | ||
if (hostname === import_constants.DEFAULT_DEV_HOST) { | ||
const localHostname = "localhost"; | ||
publicPath = `${protocol}://${localHostname}:${port}/`; | ||
} else { | ||
publicPath = `${protocol}://${hostname}:${port}/`; | ||
} | ||
} | ||
return formatPublicPath(publicPath); | ||
} | ||
function applyOutputPlugin(api) { | ||
api.modifyBundlerChain( | ||
@@ -434,5 +449,7 @@ async (chain, { isProd, isServer, isServiceWorker }) => { | ||
chainToConfig, | ||
formatPublicPath, | ||
getBundlerChain, | ||
getPublicPathFromChain, | ||
modifyBundlerChain, | ||
modifySwcLoaderOptions | ||
}); |
@@ -108,3 +108,3 @@ import type { Configuration } from '@rspack/core'; | ||
export interface BaseSplitRules { | ||
strategy: string; | ||
strategy?: string; | ||
forceSplitting?: ForceSplitting; | ||
@@ -114,3 +114,3 @@ override?: SplitChunks; | ||
export interface BaseChunkSplit extends BaseSplitRules { | ||
strategy: 'split-by-module' | 'split-by-experience' | 'all-in-one' | 'single-vendor'; | ||
strategy?: 'split-by-module' | 'split-by-experience' | 'all-in-one' | 'single-vendor'; | ||
} | ||
@@ -117,0 +117,0 @@ export interface SplitBySize extends BaseSplitRules { |
@@ -22,3 +22,3 @@ /// <reference types="node" /> | ||
export declare const removeLeadingSlash: (s: string) => string; | ||
export declare const removeTailSlash: (s: string) => string; | ||
export declare const removeTailingSlash: (s: string) => string; | ||
export declare const addTrailingSlash: (s: string) => string; | ||
@@ -25,0 +25,0 @@ export interface AwaitableGetter<T> extends PromiseLike<T[]> { |
@@ -72,3 +72,3 @@ "use strict"; | ||
removeLeadingSlash: () => removeLeadingSlash, | ||
removeTailSlash: () => removeTailSlash, | ||
removeTailingSlash: () => removeTailingSlash, | ||
resolvePackage: () => resolvePackage, | ||
@@ -101,3 +101,3 @@ setNodeEnv: () => setNodeEnv, | ||
const removeLeadingSlash = (s) => s.replace(/^\/+/, ""); | ||
const removeTailSlash = (s) => s.replace(/\/+$/, ""); | ||
const removeTailingSlash = (s) => s.replace(/\/+$/, ""); | ||
const addTrailingSlash = (s) => s.endsWith("/") ? s : `${s}/`; | ||
@@ -199,3 +199,6 @@ const awaitableGetter = (promises) => { | ||
const { publicPath } = compiler.options.output; | ||
if (typeof publicPath === "string" && publicPath !== "auto") { | ||
if (typeof publicPath === "string") { | ||
if (publicPath === "auto") { | ||
return ""; | ||
} | ||
return addTrailingSlash(publicPath); | ||
@@ -314,3 +317,3 @@ } | ||
removeLeadingSlash, | ||
removeTailSlash, | ||
removeTailingSlash, | ||
resolvePackage, | ||
@@ -317,0 +320,0 @@ setNodeEnv, |
{ | ||
"name": "@rsbuild/shared", | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"description": "The internal shared modules and dependencies of Rsbuild.", | ||
@@ -126,3 +126,3 @@ "homepage": "https://rsbuild.dev", | ||
"dependencies": { | ||
"@rspack/core": "0.5.2", | ||
"@rspack/core": "0.5.3", | ||
"caniuse-lite": "^1.0.30001559", | ||
@@ -129,0 +129,0 @@ "lodash": "^4.17.21", |
7745336
23333
+ Added@rspack/binding@0.5.3(transitive)
+ Added@rspack/binding-darwin-arm64@0.5.3(transitive)
+ Added@rspack/binding-darwin-x64@0.5.3(transitive)
+ Added@rspack/binding-linux-arm64-gnu@0.5.3(transitive)
+ Added@rspack/binding-linux-arm64-musl@0.5.3(transitive)
+ Added@rspack/binding-linux-x64-gnu@0.5.3(transitive)
+ Added@rspack/binding-linux-x64-musl@0.5.3(transitive)
+ Added@rspack/binding-win32-arm64-msvc@0.5.3(transitive)
+ Added@rspack/binding-win32-ia32-msvc@0.5.3(transitive)
+ Added@rspack/binding-win32-x64-msvc@0.5.3(transitive)
+ Added@rspack/core@0.5.3(transitive)
- Removed@rspack/binding@0.5.2(transitive)
- Removed@rspack/binding-darwin-arm64@0.5.2(transitive)
- Removed@rspack/binding-darwin-x64@0.5.2(transitive)
- Removed@rspack/binding-linux-arm64-gnu@0.5.2(transitive)
- Removed@rspack/binding-linux-arm64-musl@0.5.2(transitive)
- Removed@rspack/binding-linux-x64-gnu@0.5.2(transitive)
- Removed@rspack/binding-linux-x64-musl@0.5.2(transitive)
- Removed@rspack/binding-win32-arm64-msvc@0.5.2(transitive)
- Removed@rspack/binding-win32-ia32-msvc@0.5.2(transitive)
- Removed@rspack/binding-win32-x64-msvc@0.5.2(transitive)
- Removed@rspack/core@0.5.2(transitive)
Updated@rspack/core@0.5.3