Skip to content

Commit a56d851

Browse files
committed
Add build command
1 parent 8fe05f0 commit a56d851

4 files changed

Lines changed: 307 additions & 195 deletions

File tree

bin/graphpack

Lines changed: 0 additions & 25 deletions
This file was deleted.

bin/graphpack.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env node
2+
const nodemon = require('nodemon');
3+
const path = require('path');
4+
const { once } = require('ramda');
5+
const webpack = require('webpack');
6+
const paths = require('../config/paths');
7+
const webpackConfig = require('../config/webpack.config');
8+
9+
const compiler = webpack(webpackConfig);
10+
11+
const startDevServer = () => {
12+
const serverPaths = Object.keys(compiler.options.entry).map(entry =>
13+
path.join(compiler.options.output.path, `${entry}.js`),
14+
);
15+
compiler.watch(
16+
webpackConfig.watchOptions,
17+
once((error, stats) => {
18+
if (error || stats.hasErrors()) {
19+
throw Error(error || stats.errors);
20+
}
21+
22+
nodemon({ script: serverPaths[0], watch: serverPaths }).on(
23+
'quit',
24+
process.exit,
25+
);
26+
}),
27+
);
28+
};
29+
30+
const createProductionBuild = () => {
31+
compiler.run((error, stats) => {
32+
if (error || stats.hasErrors()) {
33+
throw Error(error || stats.errors);
34+
}
35+
});
36+
};
37+
38+
require('yargs')
39+
.command(['$0', 'dev'], 'Run development mode', {}, startDevServer)
40+
.command('build', 'Create a production build', {}, createProductionBuild)
41+
.argv;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "☄️ A minimalistic zero-config GraphQL server",
55
"license": "MIT",
66
"bin": {
7-
"graphpack": "./cli"
7+
"graphpack": "./bin/graphpack.js"
88
},
99
"main": "server",
1010
"dependencies": {

0 commit comments

Comments
 (0)