Skip to content

Commit 54fde96

Browse files
committed
Fix binary
1 parent d711c81 commit 54fde96

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

bin/json-graphql-server.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ require('reify');
33
const path = require('path');
44
const express = require('express');
55
const cors = require('cors');
6-
const JsonGraphqlServer = require('../src/');
6+
const JsonGraphqlServer = require('../lib/json-graphql-server.node.min').default;
77

8-
// fixme the build fails without those
9-
global.window = false;
10-
global.document = false;
11-
global.navigator = false;
12-
13-
var dataFilePath = process.argv.length > 2 ? process.argv[2] : './data.json';
14-
var data = require(path.join(process.cwd(), dataFilePath));
15-
var PORT = 3000;
16-
var app = express();
8+
const dataFilePath = process.argv.length > 2 ? process.argv[2] : './data.json';
9+
const data = require(path.join(process.cwd(), dataFilePath));
10+
const PORT = 3000;
11+
const app = express();
1712

1813
app.use(cors());
19-
app.use('/', JsonGraphqlServer.jsonGraphqlExpress(data));
14+
app.use('/', JsonGraphqlServer(data));
2015
app.listen(PORT);
21-
var msg = `GraphQL server running with your data at http://localhost:${PORT}/`;
16+
const msg = `GraphQL server running with your data at http://localhost:${PORT}/`;
2217
console.log(msg); // eslint-disable-line no-console
18+
19+
process.on('unhandledRejection', (reason, p) => {
20+
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
21+
});

example/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<!doctype html>
22
<html lang="en">
3-
<head></head>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
46
<body>
57
<button id="button">Load posts</button>
68
<script src="../lib/json-graphql-server.client.min.js"></script>
@@ -42,7 +44,6 @@
4244
});
4345
window.document.getElementById('button').addEventListener('click', function () {
4446
const xhr = new XMLHttpRequest();
45-
xhr.responseType = 'json';
4647
xhr.open("POST", "http://localhost:3000/graphql", true);
4748
xhr.setRequestHeader("Content-Type", "application/json");
4849
xhr.setRequestHeader("Accept", "application/json");

webpack.config.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,13 @@ if (process.env.NODE_ENV === 'production') {
1818
'process.env.NODE_ENV': JSON.stringify('production'),
1919
})
2020
);
21-
outputFile = libraryName + '.[name].min.js';
21+
outputFile = target => `${libraryName}.${target}.min.js`;
2222
} else {
23-
outputFile = libraryName + '.[name].js';
23+
outputFile = target => `${libraryName}.${target}.js`;
2424
}
2525

26-
const config = {
27-
entry: {
28-
node: __dirname + '/src/node.js',
29-
client: __dirname + '/src/client.js',
30-
},
26+
const defaultConfig = {
3127
devtool: 'source-map',
32-
output: {
33-
path: __dirname + '/lib',
34-
filename: outputFile,
35-
library: libraryName,
36-
libraryTarget: 'umd',
37-
umdNamedDefine: true,
38-
},
3928
module: {
4029
rules: [
4130
{
@@ -52,4 +41,28 @@ const config = {
5241
plugins,
5342
};
5443

55-
module.exports = config;
44+
const serverConfig = Object.assign({}, defaultConfig, {
45+
target: 'node',
46+
entry: __dirname + '/src/node.js',
47+
output: {
48+
path: path.resolve(__dirname, 'lib'),
49+
filename: outputFile('node'),
50+
library: libraryName,
51+
libraryTarget: 'umd',
52+
umdNamedDefine: true,
53+
}
54+
});
55+
56+
const clientConfig = Object.assign({}, defaultConfig, {
57+
target: 'web',
58+
entry: __dirname + '/src/client.js',
59+
output: {
60+
path: path.resolve(__dirname, 'lib'),
61+
filename: outputFile('client'),
62+
library: libraryName,
63+
libraryTarget: 'umd',
64+
umdNamedDefine: true,
65+
}
66+
});
67+
68+
module.exports = [serverConfig, clientConfig];

0 commit comments

Comments
 (0)