waysact / webpack-subresource-integrity

Webpack plugin for enabling Subresource Integrity.
MIT License
357 stars 46 forks source link

Fix the same chunkId is overwritten after using mini-css-extract-plugin #225

Open msidolphin opened 12 months ago

msidolphin commented 12 months ago

Related issue

216

Usage

Since mini-css-extract-plugin does not currently provide some hooks, developers can only inject their own integrity attributes via the insert function, I plan to inject integrity via the beforeTagInsert hook

new MiniCssExtractPlugin({
  // Options similar to the same options in webpackOptions.output
  // both options are optional
  filename: "[name].css",
  chunkFilename: "[id].css",
  insert: (link) => {
    link.integrity =
      __webpack_require__.sriHashes[chunkId + "_css/mini-extract"];
    document.head.appendChild(link);
  },
}),
msidolphin commented 11 months ago

Thanks for your contribution. Please could you add a test case that fails without the code changes? Tests still pass after I remove your change from examples/mini-css-extract-plugin/webpack.config.js.

Ok, I'll remove this change and add additional unit tests