Skip to content

Commit 2806ba9

Browse files
committed
fix vars in eject
1 parent 2584931 commit 2806ba9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/@angular/cli/models/webpack-configs/styles.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
4545
const cssnanoPlugin = cssnano({ safe: true, autoprefixer: false });
4646

4747
// Convert absolute resource URLs to account for base-href and deploy-url.
48+
const baseHref = wco.buildOptions.baseHref;
49+
const deployUrl = wco.buildOptions.deployUrl;
4850
const postcssUrlOptions = {
4951
url: (URL: string) => {
5052
// Only convert absolute URLs, which CSS-Loader won't process into require().
@@ -53,11 +55,14 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
5355
}
5456
// Join together base-href, deploy-url and the original URL.
5557
// Also dedupe multiple slashes into single ones.
56-
return `/${wco.buildOptions.baseHref || ''}/${wco.buildOptions.deployUrl || ''}/${URL}`
57-
.replace(/\/\/+/g, '/');
58+
return `/${baseHref || ''}/${deployUrl || ''}/${URL}`.replace(/\/\/+/g, '/');
5859
}
5960
};
6061
const urlPlugin = postcssUrl(postcssUrlOptions);
62+
// We need to save baseHref and deployUrl for the Ejected webpack config to work (we reuse
63+
// the function defined above).
64+
(postcssUrlOptions as any).baseHref = baseHref;
65+
(postcssUrlOptions as any).deployUrl = deployUrl;
6166
// Save the original options as arguments for eject.
6267
urlPlugin[postcssArgs] = postcssUrlOptions;
6368

packages/@angular/cli/tasks/eject.ts

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class JsonWebpackSerializer {
141141
this.variableImports['postcss-url'] = 'postcssUrl';
142142
let args = '';
143143
if (x[postcssArgs] && x[postcssArgs].url) {
144+
this.variables['baseHref'] = JSON.stringify(x[postcssArgs].baseHref);
145+
this.variables['deployUrl'] = JSON.stringify(x[postcssArgs].deployUrl);
144146
args = `{"url": ${x[postcssArgs].url.toString()}}`;
145147
}
146148
return this._escape(`postcssUrl(${args})`);

0 commit comments

Comments
 (0)