forked from glennreyes/graphpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphpack.js
More file actions
executable file
·48 lines (42 loc) · 1.25 KB
/
graphpack.js
File metadata and controls
executable file
·48 lines (42 loc) · 1.25 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
#!/usr/bin/env node
const nodemon = require('nodemon');
const path = require('path');
const { once } = require('ramda');
const webpack = require('webpack');
const { loadWebpackConfig } = require('../config');
const startDevServer = ({ compiler, config }) => {
const serverPaths = Object.keys(compiler.options.entry).map(entry =>
path.join(compiler.options.output.path, `${entry}.js`),
);
compiler.watch(
config.watchOptions,
once((error, stats) => {
if (error || stats.hasErrors()) {
throw Error(error || stats.toJson().errors);
}
nodemon({ script: serverPaths[0], watch: serverPaths }).on(
'quit',
process.exit,
);
}),
);
};
const createProductionBuild = ({ compiler }) => {
compiler.run((error, stats) => {
if (error || stats.hasErrors()) {
throw Error(error || stats.toJson().errors);
}
});
};
const startGraphPack = async () => {
const config = await loadWebpackConfig();
const compiler = webpack(config);
require('yargs')
.command(['$0', 'dev'], 'Start graphpack dev server', {}, () =>
startDevServer({ compiler, config }),
)
.command('build', 'Create production build', {}, () =>
createProductionBuild({ compiler }),
).argv;
};
startGraphPack();