Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Remove dependency on babel #434

Open
kumikumi opened this issue Oct 23, 2018 · 2 comments
Open

Remove dependency on babel #434

kumikumi opened this issue Oct 23, 2018 · 2 comments

Comments

@kumikumi
Copy link

I have created some projects using create-react-app-typescipt, and would like to get rid of babel as a dependency.

From #394 I have understood that babel is not (meant to be?) used in this project at all. However, this package seems to have dependencies on "babel-jest", "babel-loader" and "babel-preset-react-app", which cause "babel-core" and all its subdependencies to be included. I understand that babel is an ES2015+ transpiler and should therefore have no real use in a pure TypeScript project, or having a dependency on it should at most be optional.

I did a quick experiment to see if babel is really required, and turns out you can indeed create a new react app and get away with removing almost all babel-related packages (by hand) from node_modules and keep a working setup.

For some reason npm start command still requires these 4 babel modules to be present:

babel-code-frame
babel-loader
babel-preset-react-app
babel-runtime

npm run test probably requires more.

What is going on here?

@DorianGrey
Copy link
Collaborator

The statement you mentioned isn't an official one, and it's ... wrong.
Just take a look at the webpack configurations ...
E.g.:

test: /\.(js|jsx|mjs)$/,
include: paths.appSrc,
loader: require.resolve('babel-loader'),
options: {
// @remove-on-eject-begin
babelrc: false,
presets: [require.resolve('babel-preset-react-app')],
// @remove-on-eject-end
compact: true,
},

It's still allowed to import and use js files, which might be quite common during migrations. At least there were quite a lot of requests for this. Since require.resolve is used to avoid clunky webpack message when a loader could not be found, it is enforced that these packages are present - they are resolved before the build.
babel-code-frame is used by the type checker to generate a code frame for each reported error.
babel-jest is referenced by jest by default, and thus cannot be omitted.

@danielkcz
Copy link

danielkcz commented Nov 2, 2018

Isn't TypeScript capable of transforming JavaScript as well? It's just a file without types, so it shouldn't be a problem, right?

That said, if we would remove Babel completely, we would close the path for babel-plugin-macros which is extremely handy and used by more and more projects now and included in CRA2. However, in the and it means that we need to use babel-loader for TypeScript files as well.

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

No branches or pull requests

3 participants