-
Notifications
You must be signed in to change notification settings - Fork 1
/
manifest-loader.js
37 lines (28 loc) · 1.33 KB
/
manifest-loader.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
//manifest loader for replacing rev'd sources
var loaderUtils = require('loader-utils');
var path = require('path');
var mime = require('mime');
var gutil = require('gulp-util');
module.exports = function(content) {
this.cacheable && this.cacheable();
var callback = this.async();
var options = loaderUtils.parseQuery(this.query);
var manifest = require(path.join(options.outputDir, options.manifest));
var relativeSplit = options.relativeSplit || '/';
var fileName = this.resourcePath.split(relativeSplit)[1] || '';
var prefix = options.prefix || '';
var result = manifest[fileName] ? path.join(prefix, manifest[fileName]) : '';
var limit = 0;
if(options.limit) {
limit = parseInt(options.limit, 10);
}
var mimetype = options.mimetype || options.minetype || mime.lookup(this.resourcePath);
if(limit <= 0 || content.length < limit) {
gutil.log('manifest loader:', gutil.colors.gray(fileName), '>', gutil.colors.green('to base64'));
callback(null, "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64")));
} else {
gutil.log('manifest loader:', gutil.colors.gray(fileName), '>', gutil.colors.green(result));
callback(null, 'module.exports = "' + result + '"');
}
};
module.exports.raw = true;