From 235da7e4844beb9eb2c795501250e32b3abeb02a Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Sun, 17 Nov 2019 21:27:04 +0100 Subject: [PATCH] chore: format data --- src/GatsbyStaticSitePlugin.js | 41 +++++++++++++++++++---------------- src/gatsby-node.js | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/GatsbyStaticSitePlugin.js b/src/GatsbyStaticSitePlugin.js index 71a02de..d930755 100644 --- a/src/GatsbyStaticSitePlugin.js +++ b/src/GatsbyStaticSitePlugin.js @@ -12,32 +12,35 @@ module.exports = class GatsbyStaticSitePlugin { new ConstDependency.Template() ); - normalModuleFactory.hooks.parser.for('javascript/auto').tap(pluginName, parser => { - parser.hooks.importSpecifier.tap( - pluginName, - (statement, source, id, name) => { - if (source === '@reach/router' && id === 'navigate') { - // remove navigate from import - parser.scope.definitions.delete(name); + normalModuleFactory.hooks.parser + .for('javascript/auto') + .tap(pluginName, parser => { + parser.hooks.importSpecifier.tap( + pluginName, + (statement, source, id, name) => { + if (source === '@reach/router' && id === 'navigate') { + // remove navigate from import + parser.scope.definitions.delete(name); - // Add our own navigation function to gatsby - parser.state.current.addDependency( - new ConstDependency( - `const ${name} = (url, options) => { + // Add our own navigation function to gatsby + parser.state.current.addDependency( + new ConstDependency( + `const ${name} = (url, options) => { // when we do not replace the current url or the replacement is just adding a slash we navigate // this fixes canonical redirects if (!options.replace || window.location.href + '/' === url) { window.location = url; } };`, - 0 - ) - ); - return true; + 0 + ) + ); + return true; + } } - } - ); - }); - }); + ); + }); + } + ); } }; diff --git a/src/gatsby-node.js b/src/gatsby-node.js index e0d02cd..79960f6 100644 --- a/src/gatsby-node.js +++ b/src/gatsby-node.js @@ -1,7 +1,7 @@ const GatsbyStaticSitePlugin = require('./GatsbyStaticSitePlugin'); exports.onCreateWebpackConfig = ({ actions, stage }) => { - // don't add plugin + // don't add plugin if (stage !== 'build-javascript') { return; }