Skip to content

Commit

Permalink
fix(gatsby): remove .js suffixes in require() to allow transpilation
Browse files Browse the repository at this point in the history
In earlier v1, one could write files such as `gatsby-config` in typescript and
use babel to transpile the file into js on the fly via
`babel-node --presets @babel/preset-typescript --extensions '.ts' gatsby
develop`. However, it's no longer possible in recent releases.

The reason is that the current implementation put a `.js` suffix on each
require(`gatsby-${env}.js`), which blocks `gatsby-{$env}` files being transpiled
from other languages via babel. The PR addresses this problem by removing the
unnecessary suffix and preserving the integrity.

Signed-off-by: Alvis HT Tang <alvis@hilbert.space>
  • Loading branch information
alvis committed Apr 23, 2018
1 parent 408d76e commit 2c3aed6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ module.exports = async (args: BootstrapArgs) => {
activity.end()

// Try opening the site's gatsby-config.js file.
activity = report.activityTimer(`open and validate gatsby-config.js`)
activity = report.activityTimer(`open and validate gatsby-config`)
activity.start()
const config = await preferDefault(
getConfigFile(program.directory, `gatsby-config.js`)
getConfigFile(program.directory, `gatsby-config`)
)

store.dispatch({
Expand Down Expand Up @@ -182,7 +182,7 @@ module.exports = async (args: BootstrapArgs) => {

const envAPIs = plugin[`${env}APIs`]
if (envAPIs && Array.isArray(envAPIs) && envAPIs.length > 0) {
return slash(path.join(plugin.resolve, `gatsby-${env}.js`))
return slash(path.join(plugin.resolve, `gatsby-${env}`))
}
return undefined
}
Expand Down

0 comments on commit 2c3aed6

Please sign in to comment.