# All files / src/webpack/plugins extract-emitted-assets.js

92.86% Statements 13/14
66.67% Branches 4/6
100% Functions 3/3
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    262x
    2x
    2x

    2x
    2x
    2x

    2x

    1x

    1x
    1x
    1x
    1x

    2x
     const path = require("path");
    const fs = require("fs");
    const normalizeAssets = require("../utils/normalizeAssets");

    class ExtractEmittedAssets {
      constructor(options) {

        this.outputPath = options.outputPath;
        this.outputName = options.outputName || "assets.json";
        this.hooks = {};
      }
      apply(compiler) {
        compiler.hooks.done.tap({name: "ExtractEmittedAssets"}, (webpackStatsObj) => {

          Iif (webpackStatsObj.hasErrors()) return false;

          let outputPath = this.outputPath || webpackStatsObj.toJson().outputPath;
          let assetsByChunkName = normalizeAssets(webpackStatsObj);
          const outputFile = path.join(path.resolve(outputPath), this.outputName);
          fs.writeFileSync(outputFile, JSON.stringify(assetsByChunkName), "utf-8");
        });
      }
    }

    module.exports = ExtractEmittedAssets;