@eaglesong/task-panorama
Version:
Eaglesong task for Panorama
47 lines • 2.11 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
const url_1 = require("url");
class HtmlWebpackManifestPlugin {
apply(compiler) {
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
const hooks = compilation.hooks;
hooks.htmlWebpackPluginBeforeHtmlGeneration.tap(this.constructor.name, args => {
const xmlAssets = [];
// eslint-disable-next-line prefer-destructuring
const chunks = compilation.chunks;
chunks.forEach(chunk => {
chunk.files.forEach((file) => {
if (!file.endsWith('.xml') || chunk.__type == null)
return;
xmlAssets.push({
file: args.assets.publicPath + file,
type: chunk.__type,
});
});
});
console.log(args);
args.assets.xml = xmlAssets;
return args;
});
hooks.htmlWebpackPluginAfterHtmlProcessing.tap(this.constructor.name, args => {
const { publicPath } = args.assets;
const images = Object.keys(compilation.assets)
.filter(assetName => /\.(png|je?pg)$/.test(assetName))
.map(assetName => {
const url = new url_1.URL(publicPath);
// TODO: Move publicPath higher?
url.pathname = path_1.default.posix.resolve(url.pathname, assetName);
return url.toString();
});
if (images.length > 0) {
args.html = `<!--\n${images.map(x => `"${x}"`).join('\n')}\n-->\n${args.html}`;
}
return args;
});
});
}
}
exports.HtmlWebpackManifestPlugin = HtmlWebpackManifestPlugin;
//# sourceMappingURL=HtmlWebpackManifestPlugin.js.map
;