-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.js
77 lines (62 loc) · 2.64 KB
/
dev.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
67
68
69
70
71
72
73
74
75
76
77
require('shelljs/global');
var fs = require('fs');
var path = require('path');
var dirs = require('./dirs');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var addProgressPlugin = require('./addProgressPlugin');
var statsOptions = require('./statsOptions');
var serverConfig = require(path.join(dirs.webpack, 'webpack.config.server.dev'));
var clientConfig = require(path.join(dirs.webpack, 'webpack.config.client.dev'));
if (!clientConfig.devServer) clientConfig.devServer = {};
if (!clientConfig.devServer.stats) clientConfig.devServer.stats = statsOptions;
addProgressPlugin(serverConfig);
addProgressPlugin(clientConfig);
serverConfig.plugins.push(new webpack.BannerPlugin(
'require("source-map-support/register");\n' +
'var Npm = Meteor.__mwrContext__.Npm;\n' +
'var Assets = Meteor.__mwrContext__.Assets;\n' +
'delete Meteor.__mwrContext__;\n' +
'var require = Npm.require;\n',
{raw: true}
));
var serverBundlePath = path.join(dirs.assets, 'server.bundle.js');
var serverBundleRequirePath = serverBundlePath.replace(/\\/g, '\\\\');
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(clientBundleLink)) rm(clientBundleLink);
if (fs.existsSync(serverBundleLink)) rm(serverBundleLink);
var serverCompiler = webpack(serverConfig);
var serverBundleReady = false;
serverCompiler.watch({
progress: true,
colors: true,
}, function(err, stats) {
console.log(stats.toString(statsOptions)) ;
updateRequireServerBundleJs(stats);
if (!serverBundleReady) {
serverBundleReady = true;
compileClient();
runMeteor();
}
});
function compileClient() {
var clientCompiler = webpack(clientConfig);
var clientDevServer = new WebpackDevServer(clientCompiler, clientConfig.devServer);
clientDevServer.listen(clientConfig.devServer.port, clientConfig.devServer.host, function() {});
ln('-sf', loadClientBundleHtml, loadClientBundleLink);
}
function runMeteor() {
cd(dirs.meteor);
exec('meteor --settings ../settings/devel.json', {async: true});
}
function updateRequireServerBundleJs(stats) {
var jsonStats = stats.toJson({hash: true});
('//' + jsonStats.hash + '\n' +
'Meteor.__mwrContext__ = {Npm: Npm, Assets: Assets};\n' +
'Npm.require("' + serverBundleRequirePath + '");').to(requireServerBundleJs);
}