-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasset_manifest.js
36 lines (29 loc) · 1.14 KB
/
asset_manifest.js
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
26
27
28
29
30
31
32
33
34
35
36
const path = require('path');
const exec = require('child_process').exec;
const jsonfile = require('jsonfile');
const fs = require('fs');
function WebpackAssetManifest(options) {
const defaultOptions = {
manifestFileName: 'manifest.json',
assetsFileName: 'assets.js',
assetManifestFileName: 'assets.json'
};
this.options = Object.assign(defaultOptions, options);
}
WebpackAssetManifest.prototype.apply = function(compiler) {
const options = this.options;
const manifestPath = path.resolve(compiler.options.output.path,
options.manifestFileName);
const assetManifestPath = path.resolve(compiler.options.output.path,
options.assetManifestFileName);
compiler.plugin('after-emit', (compilation, callback) => {
const manifest = jsonfile.readFileSync(manifestPath);
const compiledAssetsFile = manifest[options.assetsFileName];
const nodeProcess = exec(`node -e 'require("./${compiledAssetsFile}")'`,
{ cwd: compiler.options.output.path });
nodeProcess.stdout.pipe(fs.createWriteStream(assetManifestPath));
nodeProcess.stderr.pipe(process.stderr);
callback();
});
};
module.exports = WebpackAssetManifest;