Skip to content

Commit cf0b281

Browse files
committed
Only CSS references need to traverse
The path adjustment for assets in bundles is only needed with CSS files. Paths referenced in JS files are written to elements, where they are relative to the document.
1 parent 7418815 commit cf0b281

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎webpack.config.js‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,26 @@ module.exports = {
5959
// lifetime for assets while still delivering changes quickly.
6060
oneOf: [
6161
{
62-
// Images referenced in HTML files
63-
issuer: /\.html$/,
62+
// Images referenced in CSS files
63+
issuer: /\.(scss|css)$/,
6464
loader: 'file-loader',
6565
options: {
6666
name: '[name].[hash:7].[ext]',
6767
outputPath: getImgOutputPath,
68+
publicPath: function(url, resourcePath) {
69+
// CSS image usages end up in the `bundles/[hash]` output
70+
// directory, so we adjust the final path to navigate up
71+
// twice.
72+
return path.join("../..", getImgOutputPath(url, resourcePath));
73+
},
6874
},
6975
},
7076
{
71-
// Images referenced in JS and CSS files
77+
// Images referenced in HTML and JS files
7278
loader: 'file-loader',
7379
options: {
7480
name: '[name].[hash:7].[ext]',
7581
outputPath: getImgOutputPath,
76-
publicPath: function(url, resourcePath) {
77-
// JS and CSS image usages end up the `bundles/[hash]` output
78-
// directory, so we adjust the final path to navigate up twice.
79-
return path.join("../..", getImgOutputPath(url, resourcePath));
80-
},
8182
},
8283
},
8384
],

0 commit comments

Comments
 (0)