-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (33 loc) · 1.28 KB
/
index.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
37
38
39
var _ = require('lodash');
var fs = require('fs');
var path = require('path');
function RailsManifestPlugin(opts) {
this.opts = _.assign({
fileName: 'manifest.json',
outputAssetsPath: path.join(process.cwd(), 'public', 'assets')
}, opts || {});
}
RailsManifestPlugin.prototype.apply = function(compiler) {
var outputAssetsPath = this.opts.outputAssetsPath;
var outputManifestFile = path.join(outputAssetsPath, this.opts.fileName);
compiler.plugin('done', function(stats) {
var manifest = { 'files': {}, 'assets': {} };
// Loop through all compiled assets,
for (var filename in stats.compilation.assets) {
ext = '.' + filename.split('.').pop();
digest = filename.split('-').pop().split('.')[0];
logicalPath = filename.split('-').slice(0, -1).join('-') + ext;
absolutePath = path.join(outputAssetsPath, filename);
// logicalPath = filename.replace("-" + digest, "");
manifest['assets'][logicalPath] = filename;
manifest['files'][filename] = {
'logical_path': logicalPath,
'mtime': new Date(),
'size': fs.statSync(absolutePath)['size'],
'digest': digest
};
}
fs.writeFileSync(outputManifestFile, JSON.stringify(manifest, null, 2))
});
};
module.exports = RailsManifestPlugin;