forked from jedwards1211/meteor-webpack-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prod.js
62 lines (51 loc) · 2.17 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
57
58
59
60
61
62
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 addProgressPlugin = require('./addProgressPlugin');
var statsOptions = require('./statsOptions');
var serverConfig = require(path.join(dirs.webpack, 'webpack.config.server.prod'));
var clientConfig = require(path.join(dirs.webpack, 'webpack.config.client.prod'));
addProgressPlugin(serverConfig);
addProgressPlugin(clientConfig);
serverConfig.plugins.push(new webpack.BannerPlugin('var require = Npm.require;\n', {raw: true}));
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 loadClientBundleHtml = path.join(dirs.webpack, 'loadClientBundle.html');
var loadClientBundleLink = path.join(dirs.meteor, 'client/loadClientBundle.html');
var requireServerBundleJs = path.join(dirs.meteor, 'server/require.server.bundle.js');
exec('node core-js-custom-build.js');
if (fs.existsSync(loadClientBundleLink)) rm(loadClientBundleLink);
if (fs.existsSync(requireServerBundleJs)) rm(requireServerBundleJs);
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});
}