This repository was archived by the owner on Aug 24, 2019. It is now read-only.
forked from tidepool-org/blip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildapp.js
More file actions
51 lines (40 loc) · 1.4 KB
/
buildapp.js
File metadata and controls
51 lines (40 loc) · 1.4 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
/* global rm, mkdir, exec, ls*/
require('shelljs/global');
var fs = require('fs');
var ms = require('ms');
var start = new Date();
console.log('Cleaning output directory "dist/"...');
rm('-rf', 'dist');
mkdir('-p', 'dist');
var entry = './app/main.prod.js';
console.log('Building app from "' + entry + '"...');
exec('webpack --entry \'' + entry + '\' --output-filename \'bundle.[hash].js\' --devtool source-map --colors --progress');
function getBundleFilename() {
var matches = ls('dist/bundle.*.js');
if (!(matches && matches.length)) {
throw new Error('Expected to find "dist/bundle.[hash].js"');
}
return matches[0].replace('dist/', '/');
}
function getStyleFilename() {
var matches = ls('dist/style.*.css');
if (!(matches && matches.length)) {
throw new Error('Expected to find "dist/style.[hash].css"');
}
return matches[0].replace('dist/', '/');
}
console.log('Copying "index.html"...');
var indexHtml = fs.readFileSync('index.html', 'utf8');
/**
* Replace bundle.js with hashed filename for cache-busting
*/
indexHtml = indexHtml.replace('/bundle.js', getBundleFilename());
/**
* Replace style place holder with css include with hashed filename for cache-busting
*/
indexHtml = indexHtml.replace('<!-- style -->',
'<link rel="stylesheet" href="' + getStyleFilename() + '" />'
);
indexHtml.to('dist/index.html');
var end = new Date();
console.log('App built in ' + ms(end - start));