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

Target specific node modules with babel. #3566

Closed

Conversation

XerxesNoble
Copy link

The pull request is motivated by: #1125

From what I gathered from the thread, the only reason node_modules was not included in the babel transpile is because of performance, and the make perfect sense. However, app developers should at least be able to specify what modules they need transpiled.

Each module inside node_modules the applications requires to be transpiled can be specified in the applications package.json through the new property transpileDependencies.

Example

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-scripts": "file:../packages/react-scripts/react-scripts-1.0.17.tgz",
    "@my-org/some-es6-module": "^0.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "transpileDependencies": [
    "@my-org/some-es6-module"
  ]
}

According to CONTRIBUTING.md this goes against the Core Ideas of the software, but I couldn't think of a better way (with my limited knowledge of this software) to implement this. Perhaps this will just serve as a concept.

Initially I wanted to make these changes to packages/react-scripts/config/paths.js as that is where most paths are kept, however, this is a dynamic list of paths, so I opted to add the code into each webpack config file.

Test Plan

Not the most ideal, but I verified this change with the following steps

  • npm run create-react-app my-app
  • cd my-app
  • npm install @my-org/some-es6-module
  • npm start / npm run build
  • *Verify the source code was transpiled.

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@gaearon
Copy link
Contributor

gaearon commented Jan 9, 2018

I don't think that's the approach we want to take.

I tried to describe how it should work in #1125 (comment).

If you have any questions about it please don't hesitate to ask in #1125. I agree this is a very important feature but we need to get it right, and just running our Babel transforms over published code is not the right solution.

@gaearon gaearon closed this Jan 9, 2018
@gaearon
Copy link
Contributor

gaearon commented Jan 13, 2018

FYI, we're starting the work to compile deps with babel-preset-env in Create React App: #3776

Let us know if you have feedback about how this should work.

@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants