-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
22 lines (21 loc) · 830 Bytes
/
index.js
File metadata and controls
22 lines (21 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const fs = require('fs');
const process = require('process');
const { inlineSource } = require('inline-source');
module.exports = bundler => {
if (process.env.NODE_ENV === 'production') {
bundler.on('bundled', bundle => {
const bundles = Array.from(bundle.childBundles).concat([bundle]);
return Promise.all(
bundles.map(async bundle => {
if (bundle.entryAsset && bundle.entryAsset.type === 'html') {
let html = await inlineSource(bundle.name, {
rootpath: bundle.entryAsset.options.outDir,
htmlpath: bundle.name
});
fs.writeFileSync(bundle.name, html);
}
})
);
});
}
};