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 Answer
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
5 Comments
Aaron Beall
Won't that pattern match
.js or .j? Did you mean /\.jsx?$/?Dave Newton
@Aaron Hm. Yeah. In my defense I didn't write our webpack config :/
Karoh
@DaveNewton, so you cannot make any changes to those Webpack & Babel configs without ejecting them?
Dave Newton
@Horak Technically you could probably reach into
node_modules and change it, but that seems like a truly bad idea.Karoh
@DaveNewton, I see; so standard protocol is to just eject, eh?
.jsxworks out of the box with create react app. Just restart the server.