mzgoddard / hard-source-webpack-plugin

https://www.npmjs.com/package/hard-source-webpack-plugin
ISC License
2.7k stars 160 forks source link

Webpack 5.x not supportted, because `compiler.hooks` can not add property #546

Open hzsrc opened 3 years ago

hzsrc commented 3 years ago

Expected Behavior

Support webpack 5.x

Actual Behavior

Not supportted.

Is an error being thrown?

Yes, throws an error:


TypeError: Cannot read property 'tap' of undefined
at Object.exports.tap (D:\proj\h5\node_modules\hard-source-webpack-plugin\lib\util\plugin-compat.js:118:25)
at new CacheSerializerFactory (D:\proj\h5\node_modules\hard-source-webpack-plugin\lib\CacheSerializerFactory.js:94:18)
at HardSourceWebpackPlugin.apply (D:\proj\h5\node_modules\hard-source-webpack-plugin\index.js:219:36)
at createCompiler (D:\proj\h5\node_modules\webpack\lib\webpack.js:71:12)
at create (D:\proj\h5\node_modules\webpack\lib\webpack.js:118:16)
at webpack (D:\proj\h5\node_modules\webpack\lib\webpack.js:142:32)
at f (D:\proj\h5\node_modules\webpack\lib\index.js:41:15)

### Steps to Reproduce

> - Use webpack 5.24.3
> - Webpack plugins include: `new HardSourceWebpackPlugin()`

### Operating System, Node, and NPM dependency versions

Windows 10 node@12.12 npm@6.11.3

"devDependencies": { "babel-core": "^6.26.0", "babel-loader": "^7.1.4", "babel-preset-env": "^1.6.1", "css-loader": "^0.27.0", "html-webpack-plugin": "^3.2.0", "mini-css-extract-plugin": "^0.4.0", "style-loader": "^0.14.0", "webpack": "^5.24.3", "webpack-cli": "^1.5.3" }, "dependencies": { "lodash": "^4.15.0" }

hzsrc commented 3 years ago

In webpack 5.x, the compiler.hooks can not add any property into it.
image

So, when get the hardSourceCacheFactory property in tapable.hooks, it returns undefined: image

hzsrc commented 3 years ago

Same error: https://github.com/AnomalyInnovations/serverless-bundle/issues/178

amerllica commented 3 years ago

@hzsrc What's the update?

phillipuniverse commented 3 years ago

@amerllica FYI I was able to remove this plugin completely in favor of native Webpack 5 filesystem caching.

This is what I added to my webpack.config.js to enable it:

    cache: {
      type: 'filesystem',
      buildDependencies: {
        config: [__filename]
      }
    },

On the first run of the dev server it populates the cache and takes ~1min, when I re-run it starts up in ~10s.

Also see https://github.com/mzgoddard/hard-source-webpack-plugin/issues/514#issuecomment-687621600

amerllica commented 3 years ago

@phillipuniverse, Thanks for your comment, my project is so big, very very big, so by using the native Webpack caching system, after the first time, I reduce the re-build time to 1min, I hope to find a way to reduce it below 300ms.

Finally, thanks.