-
Notifications
You must be signed in to change notification settings - Fork 75
/
prod.js
56 lines (46 loc) · 1.83 KB
/
prod.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require('shelljs/global');
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = env.NODE_ENV = 'production';
}
var fs = require('fs');
var path = require('path');
var dirs = require('./dirs');
var webpack = require('webpack');
var statsOptions = require('./statsOptions');
var makeConfig = require(path.join(dirs.webpack, 'make-webpack-config'));
var serverConfig = makeConfig({target: 'server', mode: 'production'});
var clientConfig = makeConfig({target: 'client', mode: 'production'});
var serverBundlePath = path.join(dirs.assets, 'server.bundle.js');
var clientBundlePath = path.join(dirs.assets, 'client.bundle.js');
var serverBundleLink = path.join(dirs.meteor, 'server/server.bundle.min.js');
var clientBundleLink = path.join(dirs.meteor, 'client/client.bundle.min.js');
var loadClientBundleLink = path.join(dirs.meteor, 'client/loadClientBundle.html');
exec('node core-js-custom-build.js');
if (fs.existsSync(loadClientBundleLink)) rm(loadClientBundleLink);
if (fs.existsSync(serverBundleLink)) rm(serverBundleLink);
var serverCompiler = webpack(serverConfig);
var serverBundleReady = false;
var clientBundleReady = false;
serverCompiler.watch(serverConfig.watchOptions || {}, function(err, stats) {
console.log(stats.toString(statsOptions));
if (!serverBundleReady) {
serverBundleReady = true;
ln('-sf', serverBundlePath, serverBundleLink);
compileClient();
}
});
function compileClient() {
var clientCompiler = webpack(clientConfig);
clientCompiler.watch(clientConfig.watchOptions || {}, function(err, stats) {
console.log(stats.toString(statsOptions));
if (!clientBundleReady) {
clientBundleReady = true;
ln('-sf', clientBundlePath, clientBundleLink);
runMeteor();
}
});
}
function runMeteor() {
cd(dirs.meteor);
exec('meteor run --production --settings ../settings/prod.json', {async: true});
}