How to speedup babel startup time

268 views Asked by At

I've inherited a React app using NextJS and I've noticed the startup time during development is a bit slow. What are some options for babel to speed up startup time for development?

In my index.js file I have:

require('@babel/register')({
  presets: ['@babel/preset-env'],
  ignore: ['node_modules']
});

module.exports = require('./server.js');

and in server.js I have:

import "@babel/polyfill";
...

My package.json is importing:

...
"@babel/core": "^7.12.7",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.12.7",
"@babel/register": "^7.12.1",
...

I don't see any other use of babel. I determined the slowness to due babel by running my app using DEBUG="*" npm run dev. And I see a flood of babel logs such as:

...
  babel program.body[4].declarations[0].init.left.object MemberExpression: enter +0ms
  babel program.body[4].declarations[0].init.left.object MemberExpression: Recursing into... +0ms
  babel program.body[4].declarations[0].init.left.object.object Identifier: enter +0ms
  babel program.body[4].declarations[0].init.left.object.object Identifier: Recursing into... +0ms
  babel program.body[4].declarations[0].init.left.object.object Identifier: exit +0ms
  babel program.body[4].declarations[0].init.left.object.property Identifier: enter +0ms
  babel program.body[4].declarations[0].init.left.object.property Identifier: Recursing into... +0ms
  babel program.body[4].declarations[0].init.left.object.property Identifier: exit +0ms
  babel program.body[4].declarations[0].init.left.object MemberExpression: exit +0ms
  babel program.body[4].declarations[0].init.left.property Identifier: enter +0ms
  babel program.body[4].declarations[0].init.left.property Identifier: Recursing into... +0ms
...then...
  babel:config:config-chain No config is applied to "/Users/michael/repos/MyApp/node_modules/braces/lib/parse.js" because it matches one of `ignore: ["node_modules"]` from "/Users/michael/repos/MyApp" +0ms
  babel:config:config-chain No config is applied to "/Users/michael/repos/MyApp/node_modules/braces/lib/constants.js" because it matches one of `ignore: ["node_modules"]` from "/Users/michael/repos/MyApp" +1ms
  babel:config:config-chain No config is applied to "/Users/michael/repos/MyApp/node_modules/chokidar/lib/nodefs-handler.js" because it matches one of `ignore: ["node_modules"]` from "/Users/michael/repos/MyApp" +0ms
  babel:config:config-chain No config is applied to "/Users/michael/repos/MyApp/node_modules/is-binary-path/index.js" because it matches one of `ignore: ["node_modules"]` from "/Users/michael/repos/MyApp" +2ms
  babel:config:config-chain No config is applied to "/Users/michael/repos/MyApp/node_modules/binary-extensions/index.js" because it matches one of `ignore: ["node_modules"]` from "/Users/michael/repos/MyApp" +0ms
  babel:config:config-chain No config is applied to "/Users/michael/repos/MyApp/node_modules/chokidar/lib/constants.js" because it matches one of `ignore: ["node_modules"]` from "/Users/michael/repos/MyApp" +1ms
  babel:config:config-chain No config is applied to "/Users/michael/repos/MyApp/node_modules/chokidar/lib/fsevents-handler.js" because it matches one of `ignore: ["node_modules"]` from "/Users/michael/repos/MyApp" +1ms
...
0

There are 0 answers