fqborges / webpack-fix-style-only-entries

Webpack plugin to solve the problem of having a style only entry (css/sass/less) generating an extra js file.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support HMR and miscellaneous non-JS entries

jcontonio opened this issue · comments

With the following example, the registration.js file will be created. Note that adding .css to the middlewareScript's name will cause the correct behavior. If I have time I'll do a PR.

// Wrong behavior, doesn't remove the unwanted registration.js bundle
// Add '.css' to the middlewareScript output and it'll work correctly
const middlewareScript = 'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000&name='
const exports = {
  'index': [
    './src/client/js/index.js',
    './src/client/css/index.scss'
  ],
  'registration': [
    './src/client/css/registration.scss'
  ]
}
if (process.env.NODE_ENV === 'development') {
  const entryPoints = Object.keys(exports)
  entryPoints.forEach((entryPoint) => {
    console.log(`Add middleware to ${entryPoint}`)
    exports[entryPoint].push(`${middlewareScript}${entryPoint}`) // change to "${entryPoint}.css" for correct behavior 
  })
}

module.exports = exports

Hello, I got the problem and your use case.

Probably an option for ignoring resources in the entry point, by matching a regex for example, would do. What do you propose?

Also, there is already a somewhat similar request on #7 for adding an include/exclude options to the config.

#7 sounds like a good, flexible solution. Passing a regex to exclude/include would be great 👍

It should be working on v0.3.0 with the new ignore option.

see: https://www.npmjs.com/package/webpack-fix-style-only-entries#i-use-webpack-hot-middleware