@zohodesk/client_build_tool
Version:
A CLI tool to build web applications and client libraries
60 lines (51 loc) • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.InitialHtmlPlugin = void 0;
var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const pluginName = 'InitialHtmlPlugin';
class InitialHtmlPlugin {
constructor(options) {
this.options = options;
}
apply(compiler) {
const {
filename,
template,
minify,
inject,
mainChunkName
} = this.options;
new _htmlWebpackPlugin.default({
filename,
template,
minify,
chunks: [mainChunkName],
inject,
scriptLoading: 'defer'
}).apply(compiler);
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
_htmlWebpackPlugin.default.getHooks(compilation).alterAssetTagGroups.tapAsync(pluginName, (data, cb) => {
const headTags = [];
const bodyTags = [];
data.headTags.forEach(tag => {
Object.assign(tag.attributes, {
nonce: '{{--CSP-nonce}}'
});
if (tag.tagName === 'link') {
headTags.push(tag);
} else {
bodyTags.push(tag);
}
});
cb(null, { ...data,
headTags,
bodyTags
});
});
});
}
}
exports.InitialHtmlPlugin = InitialHtmlPlugin;