Skip to content

Commit

Permalink
fix(webpack): resolve relative path for assets inputs (#21822)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Feb 15, 2024
1 parent 8963c4c commit 4be897a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Expand Up @@ -36,7 +36,8 @@ export function normalizeOptions(
normalizedOptions.assets = normalizeAssets(
options.assets,
root,
sourceRoot
sourceRoot,
projectRoot
);
}
return normalizedOptions as NormalizedWebpackExecutorOptions;
Expand Down
Expand Up @@ -64,7 +64,12 @@ export function normalizeOptions(
return {
...options,
assets: options.assets
? normalizeAssets(options.assets, workspaceRoot, sourceRoot)
? normalizeAssets(
options.assets,
workspaceRoot,
sourceRoot,
projectNode.data.root
)
: [],
baseHref: options.baseHref ?? '/',
commonChunk: options.commonChunk ?? true,
Expand Down Expand Up @@ -101,7 +106,8 @@ export function normalizeOptions(
export function normalizeAssets(
assets: any[],
root: string,
sourceRoot: string
sourceRoot: string,
projectRoot: string
): AssetGlobPattern[] {
return assets.map((asset) => {
if (typeof asset === 'string') {
Expand Down Expand Up @@ -134,7 +140,12 @@ export function normalizeAssets(
}

const assetPath = normalizePath(asset.input);
const resolvedAssetPath = resolve(root, assetPath);
let resolvedAssetPath = resolve(root, assetPath);
if (asset.input.startsWith('.')) {
const resolvedProjectRoot = resolve(root, projectRoot);
resolvedAssetPath = resolve(resolvedProjectRoot, assetPath);
}

return {
...asset,
input: resolvedAssetPath,
Expand Down
3 changes: 2 additions & 1 deletion packages/webpack/src/utils/with-nx.ts
Expand Up @@ -32,7 +32,8 @@ export function withNx(
? normalizeAssets(
pluginOptions.assets,
options.root,
options.sourceRoot
options.sourceRoot,
options.projectRoot
)
: [],
root: context.root,
Expand Down

0 comments on commit 4be897a

Please sign in to comment.