From b6895cb5b85b1e6e850f638470cf9b839d421516 Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Thu, 15 Oct 2020 09:28:39 +0200 Subject: [PATCH] feat: use webpack 5 api to add assets --- index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 7d04c256..2c9e6154 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,7 @@ const fs = require('fs'); const _ = require('lodash'); const path = require('path'); const loaderUtils = require('loader-utils'); +const webpack = require('webpack'); const { CachedChildCompilation } = require('./lib/cached-child-compiler'); const { createHtmlTagObject, htmlTagObjectToString, HtmlTagArray } = require('./lib/html-tags'); @@ -329,10 +330,7 @@ function hookIntoCompiler (compiler, options, plugin) { return loaderUtils.getHashDigest(Buffer.from(html, 'utf8'), hashType, digestType, parseInt(maxLength, 10)); }); // Add the evaluated html code to the webpack assets - compilation.assets[finalOutputName] = { - source: () => html, - size: () => html.length - }; + compilation.emitAsset(finalOutputName, new webpack.sources.RawSource(html, false)); return finalOutputName; }) .then((finalOutputName) => getHtmlWebpackPluginHooks(compilation).afterEmit.promise({