webpack-contrib / mini-css-extract-plugin

Lightweight CSS extraction plugin
MIT License
4.67k stars 389 forks source link

feat: add beforeTagInsert hook #1054

Closed msidolphin closed 10 months ago

msidolphin commented 1 year ago

This PR contains a:

Motivation / Use-Case

Breaking Changes

Additional Info

When I tried webpack-subresource-integrity to inject integrities, I found that I couldn't add integrities to the style files if I also used mini-css-extract-plugin. due to the lack of hooks in mini-css-extract-plugin. Due to the lack of hooks in mini-css-extract-plugin, it is not possible to add additional attributes to the link tag.

Related issue

https://github.com/webpack-contrib/mini-css-extract-plugin/issues/40

Usage

import MiniCssExtractPlugin from 'mini-css-extract-plugin'

MiniCssExtractPlugin.getHooks(compiler).beforeTagInsert.tap(
  "YourPluginName",
  (source, varNames) =>
    compiler.webpack.Template.asString([
      source,
      `${varNames.tag}.setAttribute("integrity",  __webpack_require__.sriHashes[${varNames.chunkId}]);`,
    ])
);
linux-foundation-easycla[bot] commented 1 year ago

CLA Signed

The committers listed above are authorized under a signed CLA.

alexander-akait commented 10 months ago

@msidolphin Also can you rebase, sorry for delay

msidolphin commented 10 months ago

@msidolphin Also can you rebase, sorry for delay

The generated version of package-lock is too old, should I update it?

alexander-akait commented 10 months ago

@msidolphin Just rebase

msidolphin commented 10 months ago

@msidolphin Just rebase

Okay, I'm done.

alexander-akait commented 10 months ago

Thank you, I will do release after https://github.com/webpack-contrib/mini-css-extract-plugin/pull/1057

codecov[bot] commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (e3f8375) 90.40% compared to head (e295cc5) 90.31%. Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1054 +/- ## ========================================== - Coverage 90.40% 90.31% -0.09% ========================================== Files 5 6 +1 Lines 875 888 +13 Branches 256 259 +3 ========================================== + Hits 791 802 +11 - Misses 74 76 +2 Partials 10 10 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

alexander-akait commented 10 months ago

I will fix errors in other PR, need more work