From cf0b2816c1d117f8775571b3588f4a60ddea4e36 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 18 Jan 2019 15:47:14 -0600 Subject: [PATCH] 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. --- webpack.config.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 9864498229..e02c105047 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -59,27 +59,28 @@ module.exports = { // lifetime for assets while still delivering changes quickly. oneOf: [ { - // Images referenced in HTML files - issuer: /\.html$/, - loader: 'file-loader', - options: { - name: '[name].[hash:7].[ext]', - outputPath: getImgOutputPath, - }, - }, - { - // Images referenced in JS and CSS files + // Images referenced in CSS files + issuer: /\.(scss|css)$/, loader: 'file-loader', options: { name: '[name].[hash:7].[ext]', outputPath: getImgOutputPath, publicPath: function(url, resourcePath) { - // JS and CSS image usages end up the `bundles/[hash]` output - // directory, so we adjust the final path to navigate up twice. + // CSS image usages end up in the `bundles/[hash]` output + // directory, so we adjust the final path to navigate up + // twice. return path.join("../..", getImgOutputPath(url, resourcePath)); }, }, }, + { + // Images referenced in HTML and JS files + loader: 'file-loader', + options: { + name: '[name].[hash:7].[ext]', + outputPath: getImgOutputPath, + }, + }, ], }, ],