Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds plugin support for CoffeeScript 2.x. #745

Merged
merged 1 commit into from
Mar 21, 2017

Conversation

noahlange
Copy link
Contributor

Additions

  • modifies Webpack config to add appropriate loaders
  • adds '.coffee', '.cjsx' to resolvable extensions
  • transpiles source before Babylon parsing

All right, here's a plugin to add CoffeeScript support to Gatsby.

A few caveats: first, CoffeeScript + React is currently a troubled combination. This plugin relies upon deprecated modules that may someday prove to be dysfunctional or otherwise deficient.

Second, the installed version of CoffeeScript is next. This is not optional - named exports are required for page queries to work properly.

# good
export pageQuery = """
  # blah blah blah...
"""

# bad
module.exports.pageQuery = """
  # blah blah blah
"""

And finally, you will need to manually edit your coffee-loader installation and install coffeescript separately in your project directory to ensure that CoffeeScript@next is being loaded. The very first line of source in the former's index.js should be the following: note the lack of dash.

var coffee = require("coffeescript");

When coffee-loader starts to support CoffeeScript 2.x this hack will no longer be necessary.

That's it. Fairly simple module. Add gatsby-plugin-coffeescript to your gatsby-config.js file and go to town.

- modifies Webpack config to add appropriate loaders
- adds '.coffee', '.cjsx' to resolvable extensions
- transpiles source before Babylon parsing
Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nice! Thanks for working on this :-)

Furthermore, note that the installed version of CoffeeScript is @next. This is
not optional - *named exports are required for page queries to work properly.*

You will need to manually edit your `coffee-loader` installation and install
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this part. Shouldn't this plugin handle this?

Copy link
Contributor Author

@noahlange noahlange Mar 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an issue with the coffee-loader package - it's not (yet) set up to use 2.x (which we need for imports/exports). There's a recently-submitted PR that adds support, so this line of documentation will only be relevant for a couple days.

The repo with the PR could be installed to the project directory as jalavosus/coffee-loader#cs2, and it should all work. ...that's probably be a better solution, albeit one I didn't think of until now.

webpack-contrib/coffee-loader#33
webpack-contrib/coffee-loader#30

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, ok, well let's just add this as-is for now and update as coffee-loader is updated.

@KyleAMathews KyleAMathews merged commit 5e425f6 into gatsbyjs:1.0 Mar 21, 2017
@KyleAMathews
Copy link
Contributor

Published this to NPM in 1.0.0-alpha12-alpha.1b1c742b 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants