Skip to content

Commit

Permalink
chore: format data
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Nov 17, 2019
1 parent 3e451dd commit 235da7e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
41 changes: 22 additions & 19 deletions src/GatsbyStaticSitePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
);
});
});
);
});
}
);
}
};
2 changes: 1 addition & 1 deletion src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down

0 comments on commit 235da7e

Please sign in to comment.