Skip to content

Commit c1077af

Browse files
committed
Add support for custom babel config
1 parent daf7148 commit c1077af

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,23 @@ module.exports = {
249249
};
250250
```
251251

252+
### Customize Babel configuration
253+
254+
Add an optional `babel.config.js` to your project root with the following preset
255+
256+
```js
257+
// babel.config.js
258+
module.exports = api => {
259+
// Cache the returned value forever and don't call this function again
260+
api.cache(true);
261+
262+
return {
263+
presets: ['graphpack/babel'],
264+
// ... Add your plugins and custom config
265+
};
266+
};
267+
```
268+
252269
> Note that this file is not going through babel transformation.
253270
254271
## Acknowledgements

packages/graphpack/config/webpack.config.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
2+
const fs = require('fs');
23
const path = require('path');
34
const webpack = require('webpack');
45
const nodeExternals = require('webpack-node-externals');
56

67
const IS_DEV = process.env.NODE_ENV !== 'production';
8+
const hasBabelRc = fs.existsSync(path.resolve('babel.config.js'));
9+
10+
if (hasBabelRc) {
11+
console.info('🐠 Using .babelrc defined in your app root');
12+
}
713

814
module.exports = {
915
devtool: 'sourcemap',
1016
entry: {
11-
// We take care of setting up entry file under lib/server.js
17+
// We take care of setting up entry file under lib/index.js
1218
index: ['graphpack'],
1319
},
1420
// When bundling with Webpack for the backend you usually don't want to bundle
@@ -30,7 +36,9 @@ module.exports = {
3036
options: {
3137
babelrc: true,
3238
cacheDirectory: true,
33-
presets: [require.resolve('babel-preset-graphpack')],
39+
presets: hasBabelRc
40+
? undefined
41+
: [require.resolve('babel-preset-graphpack')],
3442
},
3543
},
3644
],

packages/graphpack/lib/babel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('babel-preset-graphpack');

0 commit comments

Comments
 (0)