Compare commits

...

2 Commits

Author SHA1 Message Date
J. Ryan Stinnett 71cac853e2 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.
2019-01-18 15:51:01 -06:00
J. Ryan Stinnett 1d6d059c7b Fix some path math on Windows 2019-01-18 15:17:14 -06:00
1 changed files with 14 additions and 13 deletions

View File

@ -59,27 +59,28 @@ module.exports = {
// lifetime for assets while still delivering changes quickly. // lifetime for assets while still delivering changes quickly.
oneOf: [ oneOf: [
{ {
// Images referenced in HTML files // Images referenced in CSS files
issuer: /\.html$/, issuer: /\.(scss|css)$/,
loader: 'file-loader',
options: {
name: '[name].[hash:7].[ext]',
outputPath: getImgOutputPath,
},
},
{
// Images referenced in JS and CSS files
loader: 'file-loader', loader: 'file-loader',
options: { options: {
name: '[name].[hash:7].[ext]', name: '[name].[hash:7].[ext]',
outputPath: getImgOutputPath, outputPath: getImgOutputPath,
publicPath: function(url, resourcePath) { publicPath: function(url, resourcePath) {
// JS and CSS image usages end up the `bundles/[hash]` output // CSS image usages end up in the `bundles/[hash]` output
// directory, so we adjust the final path to navigate up twice. // directory, so we adjust the final path to navigate up
// twice.
return path.join("../..", getImgOutputPath(url, resourcePath)); return path.join("../..", getImgOutputPath(url, resourcePath));
}, },
}, },
}, },
{
// Images referenced in HTML and JS files
loader: 'file-loader',
options: {
name: '[name].[hash:7].[ext]',
outputPath: getImgOutputPath,
},
},
], ],
}, },
], ],
@ -193,7 +194,7 @@ module.exports = {
* @return {string} The returned paths will look like `img/warning.1234567.svg`. * @return {string} The returned paths will look like `img/warning.1234567.svg`.
*/ */
function getImgOutputPath(url, resourcePath) { function getImgOutputPath(url, resourcePath) {
const prefix = /^.*\/res\//; const prefix = /^.*[/\\]res[/\\]/;
const outputDir = path.dirname(resourcePath).replace(prefix, ""); const outputDir = path.dirname(resourcePath).replace(prefix, "");
return path.join(outputDir, path.basename(url)); return path.join(outputDir, path.basename(url));
} }