webdiscus / html-bundler-webpack-plugin

Renders Eta, EJS, Handlebars, Nunjucks, Pug, Twig templates "out of the box". Uses HTML template as entry point. Resolves source files of scripts, styles, images in HTML. Supports for Vue.
ISC License
119 stars 12 forks source link

Style Sheets break Integrity "AssetCompiler.js" #42

Closed SteffenBlake closed 8 months ago

SteffenBlake commented 8 months ago

Current behaviour

Setting integrity to true (or auto in production mode), causes the following error to occur if you reference .css or .scss files, whether it is from a .ejs or a .js file:

[webpack-cli] Error: TypeError: Cannot read properties of undefined (reading 'source')
    at Plugin.done (C:\Users\steff\Desktop\html-bundler-webpack-plugin-bug-examples\node_modules\html-bundler-webpack-plugin\src\Plugin\AssetCompiler.js:1224:13)
    at Hook.eval [as callAsync] (eval at create (C:\Users\steff\Desktop\html-bundler-webpack-plugin-bug-examples\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:9:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (C:\Users\steff\Desktop\html-bundler-webpack-plugin-bug-examples\node_modules\tapable\lib\Hook.js:18:14)
    at C:\Users\steff\Desktop\html-bundler-webpack-plugin-bug-examples\node_modules\webpack\lib\Compiler.js:498:23
    at Compiler.emitRecords (C:\Users\steff\Desktop\html-bundler-webpack-plugin-bug-examples\node_modules\webpack\lib\Compiler.js:919:5)
    at C:\Users\steff\Desktop\html-bundler-webpack-plugin-bug-examples\node_modules\webpack\lib\Compiler.js:490:11
    at C:\Users\steff\Desktop\html-bundler-webpack-plugin-bug-examples\node_modules\webpack\lib\Compiler.js:885:14
    at Hook.eval [as callAsync] (eval at create (C:\Users\steff\Desktop\html-bundler-webpack-plugin-bug-examples\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:24:1)    
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (C:\Users\steff\Desktop\html-bundler-webpack-plugin-bug-examples\node_modules\tapable\lib\Hook.js:18:14)
    at C:\Users\steff\Desktop\html-bundler-webpack-plugin-bug-examples\node_modules\webpack\lib\Compiler.js:882:27

Expected behaviour

Integrity should work for css/scss files.

Reproduction Example

https://github.com/SteffenBlake/html-bundler-webpack-plugin-bug-examples/blob/29131635a37f9be1bd0e9187734d609d3178da99/webpack.config.js#L24

If you enable integrity and execute npm run build the error is produced.

If you delete this line, the error no longer will be produced and output will occur: https://github.com/SteffenBlake/html-bundler-webpack-plugin-bug-examples/blob/29131635a37f9be1bd0e9187734d609d3178da99/src/views/home.ejs#L3

Environment

webdiscus commented 8 months ago

Hello @SteffenBlake,

thanks for the issue report. Yes, I can reproduce the bug.

Workaround

Try to remove the output.publicPath option or set as auto or as the empty string:

This is a bug, I will fix it for the use case publicPath: '/'.

webdiscus commented 8 months ago

The bug is fixed with v2.15.1. Please check it. Maybe it fixes the #43 too.

SteffenBlake commented 8 months ago

Confirmed resolved in 2.15.1, thanks for the fix!