forked from jedwards1211/meteor-webpack-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
predeploy.js
66 lines (55 loc) · 2.26 KB
/
predeploy.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
63
64
65
66
require('shelljs/global');
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');
module.exports = function(callback) {
exec('node core-js-custom-build.js');
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = env.NODE_ENV = 'production';
}
if (fs.existsSync(loadClientBundleLink)) rm(loadClientBundleLink);
if (fs.existsSync(requireServerBundleJs)) rm(requireServerBundleJs);
var serverCompiler = webpack(serverConfig);
serverCompiler.run(function(err, stats) {
if (err) {
console.error(error);
return callback(err);
}
console.log(stats.toString(statsOptions));
if (stats.toJson().errors.length) {
return callback(new Error('Webpack reported compilation errors'));
}
ln('-sf', serverBundlePath, serverBundleLink);
compileClient();
});
function compileClient() {
var clientCompiler = webpack(clientConfig);
clientCompiler.run(function(err, stats) {
if (err) {
console.error(error);
return callback(err);
}
console.log(stats.toString(statsOptions));
if (stats.toJson().errors.length) {
return callback(new Error('Webpack reported compilation errors'));
}
ln('-sf', clientBundlePath, clientBundleLink);
return callback();
});
}
};