Skip to content

Consider transpiling /lib/ to ES5 for use as a library #4887

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

Closed
jaredp opened this issue Feb 8, 2018 · 1 comment
Closed

Consider transpiling /lib/ to ES5 for use as a library #4887

jaredp opened this issue Feb 8, 2018 · 1 comment
Labels

Comments

@jaredp
Copy link

jaredp commented Feb 8, 2018

The create-react-app project recommends publishing all modules to npm as ES5. See https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify.

/lib/ not being ES5 is causing a problem when I try to use coffeescript as a library in my create-react-app based webapp. To be clear, I'm making something like the "Try Coffeescript" tab on coffeescript.org, not just trying to use Coffeescript to write the app itself in.

To reproduce the issue, see https://github.com/jaredp/cs2-as-a-library-demo. The commits are:

  1. a clean create-react-app + npm eject
  2. adding support for coffeescript + coffee-loader in webpack
  3. using Coffeescript as a library to live compile CS2 code for the user of cs2-as-a-library-demo

At the 3rd commit, npm build fails, even though npm start (dev mode) works.

@jaredp jaredp changed the title /lib/ should be compiled into ES6 for use as a library /lib/ should be compiled into ES5 for use as a library Feb 8, 2018
@jaredp jaredp changed the title /lib/ should be compiled into ES5 for use as a library Consider transpiling /lib/ to ES5 for use as a library Feb 8, 2018
@GeoffreyBooth
Copy link
Collaborator

See #4501. You’re going to want to do something like is described in that PR, where the module is imported into your project such that it can be compiled for browser use. That PR made such a thing possible: use the browser entrypoint in package.json. Your build pipeline that’s already transpiling your code for browser use should be able to import this and process it with the rest of your code.

Another option is to add the browser compiler in a separate <script> tag in your HTML: https://cdn.jsdelivr.net/gh/jashkenas/coffeescript/docs/v2/browser-compiler/coffeescript.js

As part of the issues that led up to #4501 we discussed whether lib should be transpiled, or a separate folder transpiled, but the consensus was not to do so. The CoffeeScript NPM module is primarily a Node module (of course) and it explicitly supports Node 6 and above, which is pretty far back for Node. The thinking was that providing a browser-ready entrypoint would be good enough for people, sparing us the need to maintain another set of output files for every version.

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

No branches or pull requests

2 participants