piral-cli-webpack5
Version:
Provides debug and build capabilities for pilets and Piral instances using Webpack v5.
35 lines • 1.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const webpack_1 = require("webpack");
const webpack_sources_1 = require("webpack-sources");
class StylesPlugin {
constructor(cssName, entryName) {
this.cssName = cssName;
this.entryName = entryName;
}
apply(compiler) {
const { entry } = compiler.options;
const entries = entry[this.entryName].import.map((e) => e.split('\\').join(path_1.posix.sep));
const query = `cssName=${this.cssName}&entries=${entries.join(',')}!`;
const setPath = (0, path_1.resolve)(__dirname, '..', 'set-path');
const loaderBasePath = (0, path_1.resolve)(__dirname, `StylesLoader`);
const loaderPath = `${loaderBasePath}?${query}`;
entry[this.entryName].import = [setPath, loaderPath];
compiler.hooks.compilation.tap('StylesPlugin', (compilation) => {
if (!compilation.compiler.parentCompilation) {
compilation.hooks.processAssets.tap({
name: 'StylesPlugin',
stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
}, (assets) => {
if (!assets[this.cssName]) {
const source = new webpack_sources_1.RawSource('');
compilation.emitAsset(this.cssName, source);
}
});
}
});
}
}
exports.default = StylesPlugin;
//# sourceMappingURL=StylesPlugin.js.map