neutrinojs / neutrino

Create and build modern JavaScript projects with zero initial configuration.
https://neutrinojs.org
Mozilla Public License 2.0
3.95k stars 213 forks source link

Make it easier to use `useBuiltIns: 'usage'` #1470

Closed timkelty closed 4 years ago

timkelty commented 5 years ago

AFAIK, if you want to change @babel/preset-env's useBuiltIns option, you have to pass the preset config in its entirety, e.g.:

const web = require('@neutrinojs/web');
module.exports = {
  use: [
    (neutrino) => neutrino.use(
      web({
        babel: {
          presets: [
            [
              require.resolve('@babel/preset-env'),
              {
                useBuiltIns: 'usage',
                debug: neutrino.options.debug,
                corejs: 3,
              },
            ],
          ],
        },
      })
    )
  ]
}

…would it be worth it to make this easier to change via options (similar to how we have options.targets)?

edmorley commented 5 years ago

Perhaps we should switch from entry to usage by default? iirc the reason I didn't use usage in the past (which upgrading to Babel 7) was that (a) it was more buggy then, (b) it was harder for people to opt out if they didn't need to use a polyfill at all.

However since then, I'm presuming the bugs have been worked out solving (a), and we now dynamically set it to false based on whether core-js is found, which resolves (b).

Either way we should probably also now replace the @babel/polyfill references in the docs with core-js.

The description of entry vs usage can be seen here.

timkelty commented 5 years ago

Perhaps we should switch from entry to usage by default

Sounds like that could be a good move. It used to be noted as "experimental" in Babel docs, but doesn't seem to be any longer.

I just started using it has seemed to work great so far, and dropped my bundle size significantly.

Either way we should probably also now replace the @babel/polyfill references in the docs with core-js.

Yep!

timkelty commented 5 years ago

@edmorley I can squeeze in a PR tomorrow if you think changing this to usage would be good for v9. /cc @neutrinojs/core-contributors

edmorley commented 4 years ago

@timkelty yeah let's do it :-)

timkelty commented 4 years ago

K, I'll PR today!