Skip to content

fix(@angular/cli): allow the use of a base-href with scheme #5527

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

Merged
merged 1 commit into from Mar 24, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/@angular/cli/models/webpack-configs/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
if (deployUrl.match(/:\/\//)) {
// If deployUrl contains a scheme, ignore baseHref use deployUrl as is.
return `${deployUrl.replace(/\/$/, '')}${URL}`;
} else if (baseHref.match(/:\/\//)) {
// If baseHref contains a scheme, include it as is.
return baseHref.replace(/\/$/, '') +
`/${deployUrl}/${URL}`.replace(/\/\/+/g, '/');
} else {
// Join together base-href, deploy-url and the original URL.
// Also dedupe multiple slashes into single ones.
Expand Down
16 changes: 15 additions & 1 deletion tests/e2e/tests/build/css-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,27 @@ export default function () {
.then(() => expectToFail(() => expectFileToExist('dist/component-img-absolute.svg')))
.then(() => expectFileMatchToExist('./dist', /global-img-relative\.[0-9a-f]{20}\.svg/))
.then(() => expectFileMatchToExist('./dist', /component-img-relative\.[0-9a-f]{20}\.svg/))
// Check urls with scheme are used as is.
// Check urls with deploy-url scheme are used as is.
.then(() => ng('build', '--base-href=/base/', '--deploy-url=http://deploy.url/',
'--extract-css'))
.then(() => expectFileToMatch('dist/styles.bundle.css',
/url\(\'http:\/\/deploy\.url\/assets\/global-img-absolute\.svg\'\)/))
.then(() => expectFileToMatch('dist/main.bundle.js',
/url\(\'http:\/\/deploy\.url\/assets\/component-img-absolute\.svg\'\)/))
// Check urls with base-href scheme are used as is (with deploy-url).
.then(() => ng('build', '--base-href=http://base.url/', '--deploy-url=deploy/',
'--extract-css'))
.then(() => expectFileToMatch('dist/styles.bundle.css',
/url\(\'http:\/\/base\.url\/deploy\/assets\/global-img-absolute\.svg\'\)/))
.then(() => expectFileToMatch('dist/main.bundle.js',
/url\(\'http:\/\/base\.url\/deploy\/assets\/component-img-absolute\.svg\'\)/))
// Check urls with deploy-url and base-href scheme only use deploy-url.
.then(() => ng('build', '--base-href=http://base.url/', '--deploy-url=http://deploy.url/',
'--extract-css'))
.then(() => expectFileToMatch('dist/styles.bundle.css',
/url\(\'http:\/\/deploy\.url\/assets\/global-img-absolute\.svg\'\)/))
.then(() => expectFileToMatch('dist/main.bundle.js',
/url\(\'http:\/\/deploy\.url\/assets\/component-img-absolute\.svg\'\)/))
// Check with base-href and deploy-url flags.
.then(() => ng('build', '--base-href=/base/', '--deploy-url=deploy/',
'--extract-css', '--aot'))
Expand Down