Closed
Description
Take a look at this command/script:
rm -rf src && babel dev -w -d src --presets=es2015,react,stage-0 --plugins=transform-decorators-legacy --copy-files
We are telling Babel to:
- Initialize an empty
src
directory, this is the main CRAsrc
we are used to. - Watch for any changes in all JS files located in the
dev
directory, and compile accordingly (compiled version of alldev
is now located insrc
). - We are interested in supporting some presets (es@2015, react, es@next).
- We are interested in having some plugins/additional functionality (decorators).
- Replicate all non JS files in
dev
, now we have an exact replicated and compiled version of our app insrc
.
app/
-- dev/ .. where all development happens, extended with all the new JS features
-- build/ .. contains final build of the app
-- src/ .. contains compiled JS code generated by Babel
Translating this idea via package.json
:
{
"devDependencies": {
"babel-cli": "6.24.1",
"babel-plugin-transform-decorators-legacy": "1.3.4",
"babel-preset-es2015": "6.24.1",
"babel-preset-react": "6.24.1",
"babel-preset-stage-0": "6.24.1"
},
"scripts": {
"build": "react-scripts build",
"start": "react-scripts start",
"start:babel": "rm -rf src && babel dev -w -d src --presets=es2015,react,stage-0 --plugins=transform-decorators-legacy --copy-files"
}
}
When running yarn start
in parallel with yarn start:babel
, we get the desired result.
Pros
- Use the latest JS features without having to eject. This is not the place to discuss whether we should or shouldn't, let's just take it for granted for now that we are interested in using the latest features available.
Cons
- Limited linting and type checking experience with ESLint and Flow, (any additional features added and not supported by react-scripts would typically throw either a warning or an error), we are unable to utilize these tools to their fullest potential.
- Limited debugging experience, I would say it's almost non existent now because of the extremely verbose compiled code, you get the high level error detection abilities only.
- CRA compiles an already compiled code now? how bad is this?
Would love to hear your thoughts on this.
Metadata
Metadata
Assignees
Labels
No labels