13

Just wondering how create-react-app uses .js files instead of .jsx for jsx markup. Is it because of the special webpack configuration? Btw, where can I find the webpack and babel configuration of my project created with create-react-app?

1

1 Answer 1

9

There's nothing special about the file extensions; it's just a matter of what's being run through Babel. For example:

  module: {
    loaders: [
      {
        test:    /\.jsx?$/, 
        exclude: /(node_modules)/,
        loader:  'babel',
        query:   {
          presets: [
            'react',
            'es2015',
            'stage-0'
          ],
          plugins: [
            ["transform-decorators-legacy"],
          ]
        },
      }

This runs .js and .jsx through Babel with the React presets.

The Webpack and Babel configs are inside create-react-app.

You can eject them via:

npm run eject to get them "externalized", but only do it if you really want to.

https://github.com/facebookincubator/create-react-app#user-content-converting-to-a-custom-setup

Sign up to request clarification or add additional context in comments.

5 Comments

Won't that pattern match .js or .j? Did you mean /\.jsx?$/?
@Aaron Hm. Yeah. In my defense I didn't write our webpack config :/
@DaveNewton, so you cannot make any changes to those Webpack & Babel configs without ejecting them?
@Horak Technically you could probably reach into node_modules and change it, but that seems like a truly bad idea.
@DaveNewton, I see; so standard protocol is to just eject, eh?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.