Skip to content

Commit

Permalink
Fix cross-platform issue when loading nested files (#2730)
Browse files Browse the repository at this point in the history
- nested files would be given incorrect names in the webpack manifest
- for instance, a file like `images/icons/a.svg` would end up at
  `icons/a.svg`, but a file like `images/b.svg` would end up at
  `images/b.svg` (correctly)
- webpacker.yml config files generally follow a POSIX path naming
  convention (so source_path might be something like 'app/javascript')
- the webpacker file loader config checks to see if a given file is in
  the source path by calling `includes` and passing the source path
- on Windows, the file names resolve to strings with backslashes as
  separators, but the source path has a forward slash
- the issue *could* be fixed by just changing the .yml file to have a
  backslash for the source path, but it would then break on POSIX
  systems
- instead, we check that the *normalized* source path is contained
  within the file, which fixes the issue
  • Loading branch information
aardvarkk authored Sep 22, 2020
1 parent 395ecf7 commit 38d2039
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package/rules/file.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { join } = require('path')
const { join, normalize } = require('path')
const { source_path: sourcePath, static_assets_extensions: fileExtensions } = require('../config')

module.exports = {
Expand All @@ -8,7 +8,7 @@ module.exports = {
loader: 'file-loader',
options: {
name(file) {
if (file.includes(sourcePath)) {
if (file.includes(normalize(sourcePath))) {
return 'media/[path][name]-[hash].[ext]'
}
return 'media/[folder]/[name]-[hash:8].[ext]'
Expand Down

0 comments on commit 38d2039

Please sign in to comment.