diff --git a/docs/generated/packages/webpack/executors/webpack.json b/docs/generated/packages/webpack/executors/webpack.json index 08bf0d706f..360d67dfca 100644 --- a/docs/generated/packages/webpack/executors/webpack.json +++ b/docs/generated/packages/webpack/executors/webpack.json @@ -375,6 +375,14 @@ "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", "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": [], diff --git a/packages/webpack/src/executors/webpack/schema.d.ts b/packages/webpack/src/executors/webpack/schema.d.ts index 8fe6a0eddb..29118edb08 100644 --- a/packages/webpack/src/executors/webpack/schema.d.ts +++ b/packages/webpack/src/executors/webpack/schema.d.ts @@ -84,6 +84,8 @@ export interface WebpackExecutorOptions { stylePreprocessorOptions?: any; styles?: Array; subresourceIntegrity?: boolean; + publicPath?: string; + rebaseRootRelative?: boolean; } export interface NormalizedWebpackExecutorOptions diff --git a/packages/webpack/src/executors/webpack/schema.json b/packages/webpack/src/executors/webpack/schema.json index ec76624b4f..ab14561d44 100644 --- a/packages/webpack/src/executors/webpack/schema.json +++ b/packages/webpack/src/executors/webpack/schema.json @@ -299,6 +299,14 @@ "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", "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": [], diff --git a/packages/webpack/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.ts b/packages/webpack/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.ts index b44a3e5039..99c6262993 100644 --- a/packages/webpack/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.ts +++ b/packages/webpack/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.ts @@ -128,6 +128,8 @@ function postcssOptionsCreator( deployUrl: options.deployUrl, loader, filename: `[name]${hashFormat.file}.[ext]`, + publicPath: options.publicPath, + rebaseRootRelative: options.rebaseRootRelative, }), autoprefixer(), ]), diff --git a/packages/webpack/src/plugins/nx-webpack-plugin/nx-app-webpack-plugin-options.ts b/packages/webpack/src/plugins/nx-webpack-plugin/nx-app-webpack-plugin-options.ts index 7e67a0f157..3aaff6a697 100644 --- a/packages/webpack/src/plugins/nx-webpack-plugin/nx-app-webpack-plugin-options.ts +++ b/packages/webpack/src/plugins/nx-webpack-plugin/nx-app-webpack-plugin-options.ts @@ -210,6 +210,14 @@ export interface NxAppWebpackPluginOptions { * Watch for file changes. */ 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 diff --git a/packages/webpack/src/utils/webpack/plugins/postcss-cli-resources.ts b/packages/webpack/src/utils/webpack/plugins/postcss-cli-resources.ts index a8d6926dbc..f93f726df8 100644 --- a/packages/webpack/src/utils/webpack/plugins/postcss-cli-resources.ts +++ b/packages/webpack/src/utils/webpack/plugins/postcss-cli-resources.ts @@ -22,6 +22,7 @@ export interface PostcssCliResourcesOptions { rebaseRootRelative?: boolean; filename: string; loader: LoaderContext; + publicPath: string; } async function resolve( @@ -46,6 +47,7 @@ export function PostcssCliResources(options: PostcssCliResourcesOptions) { rebaseRootRelative = false, filename, loader, + publicPath = '', } = options; const dedupeSlashes = (url: string) => url.replace(/\/\/+/g, '/'); const process = async ( @@ -85,7 +87,9 @@ export function PostcssCliResources(options: PostcssCliResourcesOptions) { dedupeSlashes(`/${deployUrl}/${inputUrl}`); } else { // 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); return outputUrl;