webpack-laravel-mix-manifest
Version:
🐶A webpack plugin that generates Laravel framework compatible mix-manifest.josn file.
53 lines (52 loc) • 1.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebpackLaravelMixManifest = void 0;
const webpack_1 = require("webpack");
const manifest_1 = require("./manifest");
/**
* Webpack plugin that generates a manifest file.
*
* @param endpoint Options for the plugin.
*/
class WebpackLaravelMixManifest {
endpoint;
/**
* Create the webpack plugin.
* @param endpoint Laravel `mix` helper used filename.
*/
constructor(
/**
* Laravel framework `mix` helper filename,
* By default `mix-manifest.json`.
*/
endpoint = 'mix-manifest.json') {
this.endpoint = endpoint;
}
get compilationHookTap() {
return {
name: this.constructor.name,
stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
};
}
/**
* Webpack plugin entry.
* @param compiler webpack compiler
*/
apply(compiler) {
compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation) => {
compilation.hooks.processAssets.tap(this.compilationHookTap, () => this.hookTapFn(compilation));
});
}
hookTapFn(compilation) {
const stats = compilation.getStats().toJson();
const manifest = this.createManifest().transform(stats).rebuild();
compilation.emitAsset(this.endpoint, new webpack_1.sources.RawSource(manifest, false));
}
/**
* Create a manifest instance.
*/
createManifest() {
return new manifest_1.Manifest();
}
}
exports.WebpackLaravelMixManifest = WebpackLaravelMixManifest;