1

I'm upgrading to Webpack 4 from Webpack 3. In index.html I have the following:

<link rel="manifest" href="<%= require('!file-loader?name=[path][name]-[hash:6].[ext]!static/manifest') %>">

However it had stopped working after the upgrade. The compilation fails saying:

Module parse failed: Unexpected token m in JSON at position 0 while parsing near 'module.exports = __w...'

Seems like Webpack is trying to parse the json file (possibly twice) which is not what I need (the documentation mentions json files are now being parsed by default). Not sure if this change of behavior in 'require' + file-loader is by design or a bug. Trying to use !!file-loader yields the same result.

Another option could be to use copy-webpack-plugin with [hash] but then how to link to the new name in index.html?

Erez Cohen
  • 1,507
  • 2
  • 16
  • 25

1 Answers1

1

I may found here an answer to your question. use app-manifest-loader and update your require statement:

<link rel="manifest" href="<%= require('manifest.webmanifest') %>">

Then add this rule into your webpack.config.js

{
  test: /(manifest\.webmanifest|browserconfig\.xml)$/,
  use: [
    {
      loader: 'file-loader?name=[path][name]-[hash:6].[ext]'
    },
    {
      loader: "app-manifest-loader"
    }
  ]
}

this loader will also parse the manifest file and will load all icons to with Webpack build to dist folder

The important part here is to change the manifest extension from .json to something else like .webmanifest

Elhay Avichzer
  • 836
  • 1
  • 10
  • 14