UNPKG

piral-cli-webpack5

Version:

Provides debug and build capabilities for pilets and Piral instances using Webpack v5.

45 lines 2.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = require("path"); const webpack_1 = require("webpack"); const webpack_sources_1 = require("webpack-sources"); class SheetPlugin { constructor(cssName, piletName, entryName) { this.cssName = cssName; this.entryName = entryName; this.loaderPath = (0, path_1.resolve)(__dirname, `SheetLoader?cssName=${cssName}&piletName=${piletName}!`); } apply(compiler) { const { entry } = compiler.options; entry[this.entryName].import = [this.loaderPath, ...entry[this.entryName].import]; compiler.hooks.compilation.tap('SheetPlugin', (compilation) => { if (!compilation.compiler.parentCompilation) { compilation.hooks.processAssets.tap({ name: 'SheetPlugin', stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS }, (assets) => { if (!assets[this.cssName]) { const name = JSON.stringify(this.cssName); const [[, source]] = Object.entries(assets); if (source instanceof webpack_sources_1.CachedSource) { const cs = source.original(); if (cs instanceof webpack_sources_1.ConcatSource && 'children' in cs && Array.isArray(cs.children)) { cs.children = cs.children.filter((m) => { if (m instanceof webpack_sources_1.CachedSource) { const original = m.original(); if (original instanceof webpack_sources_1.ReplaceSource) { const src = original.source(); if (typeof src === 'string') { return !src.includes(name); } } } return true; }); } } } }); } }); } } exports.default = SheetPlugin; //# sourceMappingURL=SheetPlugin.js.map