assets-webpack-plugin: integrity configuration not working

Describe the bug According to the docs, setting integrity: true should generate jsIntegrity in the output. But in my case, jsIntegrity is not generated.

To Reproduce I have made a minimal reproducible example. Steps to reproduce the behavior:

  1. Clone https://github.com/niyoko/assets-webpack-plugin-issue
  2. Run npm install
  3. Run npm run build
  4. View dist/webpack-assets.json

Expected behavior In dist/webpack-assets.json should includes integrity hash for the outputed JS.

Webpack Config

const path = require('path');
const AssetsPlugin = require('assets-webpack-plugin');
const SriPlugin = require('webpack-subresource-integrity');

module.exports = {
  mode: 'production',
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name]-bundle-[contenthash].js',
    publicPath: '/js/',
    crossOriginLoading: 'anonymous',
  },
  plugins: [
    new AssetsPlugin({
      path: path.join(__dirname, 'dist'),
      prettyPrint: true,
      integrity: true,
    }),
    new SriPlugin({
      hashFuncNames: ['sha256', 'sha384'],
      enabled: true,
    }),
  ],
};

Desktop (please complete the following information):

  • OS: ArchLinux 5.4.83-1-lts
  • Node version: 14.15.1
  • Plugin version: 7.0.0

Additional context

  • webpack-subresource-integrity version: 1.5.2

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Should be fixed in v7.1.0, let me know otherwise. Thanks again @lebleb!

Content and Map of this Source is no longer available

@markcampbell24 , Webpack 5 replaces the Sources in Compilation.assets with SizeOnlySource variants to reduce memory usage before afterEmit hook call. https://webpack.js.org/blog/2020-10-10-webpack-5-release/#sizeonlysource-after-emit

Is it not possible to update the hooks part for only Webpack 5?

from:

    if (compiler.hooks) {
      const plugin = { name: 'AssetsWebpackPlugin' }

      compiler.hooks.afterEmit.tapAsync(plugin, afterEmit)
    } else {
      compiler.plugin('after-emit', afterEmit)
    }

to:

   if (compiler.hooks) {
     const plugin = { name: 'AssetsWebpackPlugin' }

     compiler.hooks.emit.tapAsync(plugin, emitPlugin)
   } else {
     compiler.plugin('after-emit', emitPlugin)
   }

@markcampbell24 would you mind sharing your config? Going to see if I can figure this out later today.