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

fix(webpack): resolve relative path for assets inputs #21822

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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