From 8968a6c48c64d91f5a32d8a60dbd0f04d80cc9b4 Mon Sep 17 00:00:00 2001 From: rakannimer Date: Mon, 2 Sep 2019 14:39:09 +0300 Subject: [PATCH] fix(docz-core): make onCreateWebpackConfig extendable --- core/docz-core/templates/gatsby-node.tpl.js | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/core/docz-core/templates/gatsby-node.tpl.js b/core/docz-core/templates/gatsby-node.tpl.js index 8acb7619d..64c6a3461 100644 --- a/core/docz-core/templates/gatsby-node.tpl.js +++ b/core/docz-core/templates/gatsby-node.tpl.js @@ -1,11 +1,29 @@ const path = require('path') +const get = require('lodash/get') -exports.onCreateWebpackConfig = ({ actions }) => { - actions.setWebpackConfig({ +const NO_OP = () => {} + +let gatsbyNodeCustom +try { + gatsbyNodeCustom = require('./gatsby-node.custom') +} catch (err) { + gatsbyNodeCustom = { + onCreateWebpackConfig: NO_OP, + } +} + +exports.onCreateWebpackConfig = args => { + args.actions.setWebpackConfig({ resolve: { alias: { react: path.resolve('../node_modules/react'), }, }, }) + const onCreateWebpackConfig = get( + gatsbyNodeCustom, + 'onCreateWebpackConfig', + NO_OP + ) + onCreateWebpackConfig(args) }