Skip to content

Commit 9997823

Browse files
committed
chore(package): bundle with webpack instead of browserify
1 parent 65e9761 commit 9997823

File tree

4 files changed

+2189
-602
lines changed

4 files changed

+2189
-602
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
/npm-debug.log
55
/coverage
66
/cache/data.json
7+
/public/stats.json
8+
/public/schema.js.map

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
"options": {
2121
"mocha": "--require babel-register --require scripts/mocha-bootload src/**/__tests__/*.js"
2222
},
23-
"browserify-shim": {
24-
"react": "global:React"
25-
},
2623
"scripts": {
2724
"postinstall": "npm run download && npm run build",
2825
"test": "npm run lint && npm run check && npm run testonly",
@@ -36,7 +33,8 @@
3633
"coveralls": "babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
3734
"build": "babel src --optional runtime --ignore __tests__,public --out-dir lib/",
3835
"download": "babel-node scripts/download.js cache/data.json",
39-
"build-public": "browserify --standalone Schema -t babelify --outfile public/schema.js src/schema-proxy.js",
36+
"build-public": "webpack -p",
37+
"bundle-stats": "webpack -p --profile --json > public/stats.json && npx webpack-bundle-analyzer public/stats.json",
4038
"serve-public": "babel-node scripts/serve-public",
4139
"deploy": "scripts/build-public && scripts/deploy-public",
4240
"prettier": "prettier --write 'src/**/*.js'",
@@ -55,15 +53,13 @@
5553
"babel-cli": "^6.26.0",
5654
"babel-core": "^6.26.0",
5755
"babel-eslint": "^8.2.2",
56+
"babel-loader": "^7.1.4",
5857
"babel-plugin-syntax-async-functions": "6.13.0",
5958
"babel-plugin-transform-flow-strip-types": "^6.22.0",
6059
"babel-plugin-transform-object-rest-spread": "^6.26.0",
6160
"babel-plugin-transform-runtime": "^6.23.0",
6261
"babel-preset-env": "^1.6.1",
6362
"babel-register": "^6.26.0",
64-
"babelify": "^8.0.0",
65-
"browserify": "^15.0.0",
66-
"browserify-shim": "^3.8.10",
6763
"chai": "^4.1.2",
6864
"coveralls": "^3.0.0",
6965
"eslint": "^4.19.1",
@@ -74,6 +70,8 @@
7470
"isparta": "^4.0.0",
7571
"mocha": "^5.0.5",
7672
"prettier": "^1.11.1",
77-
"sane": "^2.5.0"
73+
"sane": "^2.5.0",
74+
"webpack": "^4.5.0",
75+
"webpack-cli": "^2.0.14"
7876
}
7977
}

webpack.config.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const webpack = require('webpack');
2+
3+
module.exports = {
4+
mode: 'development',
5+
entry: ['./src/schema-proxy'],
6+
module: {
7+
rules: [
8+
{
9+
test: /\.js$/,
10+
exclude: /node_modules/,
11+
use: {
12+
loader: 'babel-loader',
13+
options: {
14+
babelrc: false,
15+
// TODO: Maybe fold this into the main .babelrc as a separate environment
16+
presets: [['env', { modules: false }]],
17+
plugins: [
18+
'transform-flow-strip-types',
19+
'transform-object-rest-spread',
20+
'transform-runtime',
21+
],
22+
},
23+
},
24+
},
25+
],
26+
},
27+
output: {
28+
path: __dirname + '/public',
29+
publicPath: '/',
30+
filename: 'schema.js',
31+
library: 'Schema',
32+
},
33+
devServer: {
34+
contentBase: './public',
35+
},
36+
devtool: 'source-map',
37+
38+
optimization: {
39+
usedExports: true,
40+
providedExports: true,
41+
},
42+
43+
// Work around a Webpack issue triggered by graphql/jsutils/instanceOf
44+
// See https://github.com/webpack/webpack/issues/7032#issuecomment-381404271
45+
node: {
46+
process: false,
47+
},
48+
plugins: [
49+
new webpack.DefinePlugin({
50+
process: {},
51+
}),
52+
],
53+
};

0 commit comments

Comments
 (0)