Skip to content

Commit 19efaa1

Browse files
committed
fix(build): override publicPath for ExtractTextPlugin and add extract-css test
1 parent 394aa05 commit 19efaa1

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/angular-cli/models/webpack-build-utils.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ export function makeCssLoaders(stylePaths: string[] = []) {
8080
include: stylePaths, test, loaders: ExtractTextPlugin.extract({
8181
remove: false,
8282
loader: ['css-loader', ...commonLoaders, ...loaders],
83-
fallbackLoader: 'style-loader'
83+
fallbackLoader: 'style-loader',
84+
// publicPath needed as a workaround https://github.com/angular/angular-cli/issues/4035
85+
publicPath: ''
8486
})
8587
})));
8688
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as glob from 'glob';
2+
import { writeMultipleFiles, expectFileToMatch } from '../../../utils/fs';
3+
import { ng } from '../../../utils/process';
4+
import { stripIndents } from 'common-tags';
5+
6+
export default function () {
7+
return writeMultipleFiles({
8+
'src/styles.css': stripIndents`
9+
div { background: url("./assets/more.svg"); }
10+
`,
11+
'src/assets/more.svg': stripIndents`
12+
<svg width="100" height="100">
13+
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
14+
</svg>
15+
`})
16+
.then(() => ng('build'))
17+
.then(() => expectFileToMatch('dist/styles.bundle.css',
18+
/div\s*{\s*background:\s*url\(more.svg\);\s*}/))
19+
.then(() => ng('build', '--prod'))
20+
.then(() => glob.sync('dist/styles.*.bundle.css').find(file => !!file))
21+
.then((stylesBundle) => expectFileToMatch(stylesBundle,
22+
/div\s*{\s*background:\s*url\(more\..*svg\)\s*}/))
23+
// build with deloyUrl
24+
.then(() => ng('build', '--deploy-url=client/'))
25+
.then(() => expectFileToMatch('dist/styles.bundle.css',
26+
/div\s*{\s*background:\s*url\(more.svg\);\s*}/))
27+
.then(() => ng('build', '--prod', '--deploy-url=client/'))
28+
.then(() => glob.sync('dist/styles.*.bundle.css').find(file => !!file))
29+
.then((stylesBundle) => expectFileToMatch(stylesBundle,
30+
/div\s*{\s*background:\s*url\(more\..*svg\)\s*}/));
31+
}

0 commit comments

Comments
 (0)