Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. const Entities = require('html-entities').AllHtmlEntities;
  2.  
  3. const htmlEntities = new Entities();
  4.  
  5. class InlineCssHtmlWebpackPlugin {
  6. apply(compiler) {
  7. compiler.plugin('compilation', compilation => {
  8. compilation.plugin('html-webpack-plugin-before-html-processing', (htmlPluginData, callback) => {
  9. for (let filename of htmlPluginData.assets.css) {
  10. const cssSrc = compilation.assets[filename];
  11.  
  12. htmlPluginData.html = htmlPluginData.html
  13. .replace('</head>', `<style>${htmlEntities.encode(cssSrc.source())}</style></head>`);
  14.  
  15. delete compilation.assets[filename];
  16. }
  17.  
  18. htmlPluginData.assets.css = [];
  19.  
  20. callback(null, htmlPluginData);
  21. });
  22. });
  23. }
  24. }
  25.  
  26. module.exports = InlineCssHtmlWebpackPlugin;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement