UNPKG

html-webpack-static-assets-plugin

Version:

HtmlWebpackPlugin extenstion that allows you to add assets to genereted html file.

1 lines 2.23 kB
!function(t){var e={};function r(o){if(e[o])return e[o].exports;var s=e[o]={i:o,l:!1,exports:{}};return t[o].call(s.exports,s,s.exports,r),s.l=!0,s.exports}r.m=t,r.c=e,r.d=function(t,e,o){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)r.d(o,s,function(e){return t[e]}.bind(null,s));return o},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";t.exports=class{constructor(t,e){this.htmlWebpackPlugin=t,this.options=e}throwError(t){throw new Error(`html-webpack-static-assets-plugin: ${t}`)}logWarning(t){console.warn(`html-webpack-static-assets-plugin: ${t}`)}apply(t){t.hooks.compilation.tap("HtmlWebpackStaticAssetsPlugin",t=>{this.htmlWebpackPlugin||this.throwError("Provide HtmlWebpackPlugin reference as a first parameter"),this.options||this.throwError("Provide options."),this.htmlWebpackPlugin.getHooks(t).alterAssetTagGroups.tapAsync("HtmlWebpackStaticAssetsPlugin",(e,r)=>{const{headTags:o,bodyTags:s}=this.options;o||s||this.throwError("Provide headTags or bodyTags otherwise this plugin is useless. :(");const{assets:n}=t;o&&(e.headTags=this.getNewTagArray(e.headTags,o,n)),s&&(e.bodyTags=this.getNewTagArray(e.bodyTags,o,n)),r(null,e)})})}getNewTagArray(t,e,r){const o=[...t];for(var s in r)e.forEach(({test:t,tagName:e,...r})=>{if(t.constructor!==RegExp&&this.throwError("'test' option value needs to be a type of RegExp."),e||this.throwError("'tagName' is required!"),t.test(s)){const t={},a="script"===e;a?t.scr=s:t.href=s;const i={tagName:e,voidTag:a,attributes:{...t}};for(var n in r)"type"===n&&(r[n]=r[n].replace("[.ext]",s.slice(2+(s.lastIndexOf(".")-1>>>0)))),i.attributes[n]=r[n];o.push(i)}});return o}}}]);