ctf0 / laravel-mix-versionhash

Auto append hash to file instead of using virtual one
MIT License
61 stars 18 forks source link

.versionHash() together with .extract() malform paths in manifest #17

Closed ZeroThe2nd closed 5 years ago

ZeroThe2nd commented 5 years ago

When chaining .versionHash() into my mix setup, my JavaScript file paths are being prepended with /./ in the mix manifest and "done" message for my files except the manifest.js file itself

Expected output:

A regular mix-manifest.json file with correct paths:

{
  "/js/app.js": "/js/app.572902.js",
  "/css/bootstrap.css": "/css/bootstrap.css",
  "/css/vuetify.css": "/css/vuetify.css",
  "/js/manifest.js": "/js/manifest.3837fe.js",
  "/js/vendor.js": "/js/vendor.a68674.js"
}

Current output:

A mix-manifest.json file with prepended /./ in its paths:

{
  "/.//js/app.js": "/.//js/app.572902.js",
  "/css/bootstrap.css": "/css/bootstrap.css",
  "/css/vuetify.css": "/css/vuetify.css",
  "/js/manifest.js": "/js/manifest.3837fe.js",
  "/.//js/vendor.js": "/.//js/vendor.a68674.js"
}

Configuration:

I'm using a few extra plugins (clean-webpack-plugin, laravel-mix-bundle-analyzer, laravel-mix-eslint) and 2 resolve aliases in my config file. My full mix config chain:

mix
  .setPublicPath('public')
  .js('resources/js/app.js', 'public/js')
  // Lint files pre-build
  .eslint({
    fix: false,
    cache: false,
    emitWarning: true
  })
  .sass('resources/sass/bootstrap.scss', 'public/css')
  .stylus('resources/stylus/vuetify.styl', 'public/css')
  // Create separated vendor.js file to separate the packages from the app
  .extract()
  // Add version hashes to the filename instead of a []filename].js?[hash]
  .versionHash(4, '-')

Messing around with my mix file, I've thinned it down to the bare bones. The issue still persists:

mix
  .js('resources/js/app.js', 'public/js')
  .sass('resources/sass/bootstrap.scss', 'public/css')
  .stylus('resources/stylus/vuetify.styl', 'public/css')
  // Add version hashes to the filename instead of a []filename].js?[hash]
  .versionHash()

However after removing .extract() from the chain, my JavaScript file does add the hash to the filename and into the manifest as it should. Sidenote that the .CSS files are not getting a hash added to their filename.

TL;DR

Chaining mix.extract().versionHash() together causes an added /./ in front of the JavaScript filenames except for the manifest.js file, and the .css files which does not get a hash at all.

ZeroThe2nd commented 5 years ago

Update: Adding mix.versionHash() instead of chaining it together with the rest of the options does add the hash manifest.js Oddly enough, only this file is also properly added in the mix-manifest.json file, while the others are not:

{
  "/.//js/app.js": "/.//js/app.7c604d.js",
  "/css/bootstrap.css": "/css/bootstrap.css",
  "/css/vuetify.css": "/css/vuetify.css",
  "/js/manifest.js": "/js/manifest.3837fe.js",
  "/.//js/vendor.js": "/.//js/vendor.a68674.js"
}

I have tried setting all options to mix.[option]() instead of chaining them, but this did not work.

bolechen commented 5 years ago

Also running into this problem.