-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
30 lines (25 loc) · 902 Bytes
/
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
'use strict';
const path = require('path');
const fs = require('fs');
const loaderUtils = require('loader-utils');
const transform = require('./transform');
function ChunkHashReplacePlugin(options) {
this.src = options.src;
this.dest = options.dest;
}
ChunkHashReplacePlugin.prototype.apply = function (compiler) {
const self = this;
const folder = compiler.options.context;
const src = path.join(folder, self.src);
const dest = path.join(folder, self.dest);
const cssFilePaths = self.cssFilePaths;
fs.readFile(src, 'utf8', function (err, data) {
compiler.plugin('done', function (statsData) {
const stats = statsData.toJson();
const template = fs.readFileSync(src, 'utf8');
const htmlOutput = transform(template, stats.chunks);
fs.writeFileSync(dest, htmlOutput);
});
});
};
module.exports = ChunkHashReplacePlugin;