fix(webpack): publicPath and rebaseRootRelative (#20992)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior <!-- This is the behavior we have today --> can not configure webpack publicPath with NX option. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> make the publicPath work with postcssCliResources. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # --------- Co-authored-by: Colum Ferry <cferry09@gmail.com>
This commit is contained in:
parent
8f705e31e2
commit
8f25ade650
@ -375,6 +375,14 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Path to the babel configuration file of your project. If not provided, Nx will default to the .babelrc file at the root of your project. See https://babeljs.io/docs/en/config-files",
|
"description": "Path to the babel configuration file of your project. If not provided, Nx will default to the .babelrc file at the root of your project. See https://babeljs.io/docs/en/config-files",
|
||||||
"x-completion-type": "file"
|
"x-completion-type": "file"
|
||||||
|
},
|
||||||
|
"publicPath": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Set a public path for assets resources with absolute paths."
|
||||||
|
},
|
||||||
|
"rebaseRootRelative": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Whether to rebase absolute path for assets in postcss cli resources."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [],
|
"required": [],
|
||||||
|
|||||||
@ -84,6 +84,8 @@ export interface WebpackExecutorOptions {
|
|||||||
stylePreprocessorOptions?: any;
|
stylePreprocessorOptions?: any;
|
||||||
styles?: Array<ExtraEntryPointClass | string>;
|
styles?: Array<ExtraEntryPointClass | string>;
|
||||||
subresourceIntegrity?: boolean;
|
subresourceIntegrity?: boolean;
|
||||||
|
publicPath?: string;
|
||||||
|
rebaseRootRelative?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NormalizedWebpackExecutorOptions
|
export interface NormalizedWebpackExecutorOptions
|
||||||
|
|||||||
@ -299,6 +299,14 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Path to the babel configuration file of your project. If not provided, Nx will default to the .babelrc file at the root of your project. See https://babeljs.io/docs/en/config-files",
|
"description": "Path to the babel configuration file of your project. If not provided, Nx will default to the .babelrc file at the root of your project. See https://babeljs.io/docs/en/config-files",
|
||||||
"x-completion-type": "file"
|
"x-completion-type": "file"
|
||||||
|
},
|
||||||
|
"publicPath": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Set a public path for assets resources with absolute paths."
|
||||||
|
},
|
||||||
|
"rebaseRootRelative": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Whether to rebase absolute path for assets in postcss cli resources."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [],
|
"required": [],
|
||||||
|
|||||||
@ -128,6 +128,8 @@ function postcssOptionsCreator(
|
|||||||
deployUrl: options.deployUrl,
|
deployUrl: options.deployUrl,
|
||||||
loader,
|
loader,
|
||||||
filename: `[name]${hashFormat.file}.[ext]`,
|
filename: `[name]${hashFormat.file}.[ext]`,
|
||||||
|
publicPath: options.publicPath,
|
||||||
|
rebaseRootRelative: options.rebaseRootRelative,
|
||||||
}),
|
}),
|
||||||
autoprefixer(),
|
autoprefixer(),
|
||||||
]),
|
]),
|
||||||
|
|||||||
@ -210,6 +210,14 @@ export interface NxAppWebpackPluginOptions {
|
|||||||
* Watch for file changes.
|
* Watch for file changes.
|
||||||
*/
|
*/
|
||||||
watch?: boolean;
|
watch?: boolean;
|
||||||
|
/**
|
||||||
|
* Set a public path for assets resources with absolute paths.
|
||||||
|
*/
|
||||||
|
publicPath?: string;
|
||||||
|
/**
|
||||||
|
* Whether to rebase absolute path for assets in postcss cli resources.
|
||||||
|
*/
|
||||||
|
rebaseRootRelative?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NormalizedNxAppWebpackPluginOptions
|
export interface NormalizedNxAppWebpackPluginOptions
|
||||||
|
|||||||
@ -22,6 +22,7 @@ export interface PostcssCliResourcesOptions {
|
|||||||
rebaseRootRelative?: boolean;
|
rebaseRootRelative?: boolean;
|
||||||
filename: string;
|
filename: string;
|
||||||
loader: LoaderContext<unknown>;
|
loader: LoaderContext<unknown>;
|
||||||
|
publicPath: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resolve(
|
async function resolve(
|
||||||
@ -46,6 +47,7 @@ export function PostcssCliResources(options: PostcssCliResourcesOptions) {
|
|||||||
rebaseRootRelative = false,
|
rebaseRootRelative = false,
|
||||||
filename,
|
filename,
|
||||||
loader,
|
loader,
|
||||||
|
publicPath = '',
|
||||||
} = options;
|
} = options;
|
||||||
const dedupeSlashes = (url: string) => url.replace(/\/\/+/g, '/');
|
const dedupeSlashes = (url: string) => url.replace(/\/\/+/g, '/');
|
||||||
const process = async (
|
const process = async (
|
||||||
@ -85,7 +87,9 @@ export function PostcssCliResources(options: PostcssCliResourcesOptions) {
|
|||||||
dedupeSlashes(`/${deployUrl}/${inputUrl}`);
|
dedupeSlashes(`/${deployUrl}/${inputUrl}`);
|
||||||
} else {
|
} else {
|
||||||
// Join together base-href, deploy-url and the original URL.
|
// Join together base-href, deploy-url and the original URL.
|
||||||
outputUrl = dedupeSlashes(`/${baseHref}/${deployUrl}/${inputUrl}`);
|
outputUrl = dedupeSlashes(
|
||||||
|
`/${baseHref}/${deployUrl}/${publicPath}/${inputUrl}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
resourceCache.set(cacheKey, outputUrl);
|
resourceCache.set(cacheKey, outputUrl);
|
||||||
return outputUrl;
|
return outputUrl;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user