Skip to content

Commit

Permalink
feat(babel-preset-mc-app): add ability to disable core-js (#2261)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdeekens authored Jun 10, 2021
1 parent 9aba0c4 commit 481fb8f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .changeset/long-wolves-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@commercetools-frontend/mc-scripts": minor
---

Adds the ability to explicitly disable core-js for `mc-scripts` and the webpack configs

Some environments or build targets might not require core-js. In order to opt-out of it you can specify a `disableCoreJs` option.
7 changes: 7 additions & 0 deletions .changeset/many-doors-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@commercetools-frontend/babel-preset-mc-app": minor
---

Adds the ability to explicitly disable core-js for `babel-preset-mc-app`

Some environments or build targets might not require core-js. In order to opt-out of it you can specify a `disableCoreJs` option.
5 changes: 0 additions & 5 deletions .changeset/perfect-mice-bow.md

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/tender-eggs-joke.md

This file was deleted.

12 changes: 9 additions & 3 deletions packages/babel-preset-mc-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ const defaultOptions = {
// Usually when bundling packages we want to keep the prop types
// but when building the final application we can remove them.
keepPropTypes: false,
disableLooseMode: false,
// plugin-proposal-class-properties, plugin-proposal-private-methods,
// plugin-proposal-private-property-in-object have a loose option which
// needs to be synced. At times, for instance for better debuggability
// the loose option can be disabled at the cost of lowered performance.
disableLooseMode: false,
// Some environemnts do not require `core-js` and can hence disable
// it explicitely. This will disable `core-js` for `preset-env` and the
// `plugin-transform-runtime`.
disableCoreJs: false,
};

/* eslint-disable global-require */
Expand Down Expand Up @@ -55,7 +59,9 @@ module.exports = function getBabePresetConfigForMcApp(api, opts = {}) {
targets: {
browsers: ['last 2 versions'],
},
corejs: { version: 3, proposals: true },
...(options.disableCoreJs
? {}
: { corejs: { version: 3, proposals: true } }),
// `entry` transforms `@babel/polyfill` into individual requires for
// the targeted browsers. This is safer than `usage` which performs
// static code analysis to determine what's required.
Expand Down Expand Up @@ -143,7 +149,7 @@ module.exports = function getBabePresetConfigForMcApp(api, opts = {}) {
{
// corejs messes with jest@27 in tests, due to some
// Promise/Date related polyfills it provides.
corejs: !isEnvTest && 3,
corejs: options.disableCoreJs ? false : 3,
// To be able to use `runtime` in Rollup babel plugin
helpers: true,
regenerator: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const hasJsxRuntime = require('./has-jsx-runtime');
const defaultToggleFlags = {
// Allow to disable index.html generation in case it's not necessary (e.g. for Storybook)
generateIndexHtml: true,
// Some environemnts do not require `core-js` and can hence disable
// it explicitely. This will disable `core-js` for `preset-env` and the
// `plugin-transform-runtime`.
disableCoreJs: false,
};
const defaultOptions = {
distPath: paths.distPath,
Expand Down Expand Up @@ -99,7 +103,8 @@ module.exports = function createWebpackConfigForDevelopment(options = {}) {
entry: {
app: [
require.resolve('./application-runtime'),
require.resolve('core-js/stable'),
!mergedOptions.toggleFlags.disableCoreJs &&
require.resolve('core-js/stable'),
// When using the experimental `react-refresh` integration,
// the webpack plugin takes care of injecting the dev client for us.
!hasReactRefresh &&
Expand Down Expand Up @@ -216,6 +221,7 @@ module.exports = function createWebpackConfigForDevelopment(options = {}) {
),
{
runtime: hasJsxRuntime() ? 'automatic' : 'classic',
disableCoreJs: mergedOptions.toggleFlags.disableCoreJs,
},
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const defaultToggleFlags = {
// `false` to disable any paralelism
// `int` for a specific number of CPUs
parallelism: true,
// Some environemnts do not require `core-js` and can hence disable
// it explicitely. This will disable `core-js` for `preset-env` and the
// `plugin-transform-runtime`.
disableCoreJs: false,
};
const defaultOptions = {
distPath: paths.distPath,
Expand Down Expand Up @@ -141,7 +145,8 @@ module.exports = function createWebpackConfigForProduction(options = {}) {
entry: {
app: [
require.resolve('./application-runtime'),
require.resolve('core-js/stable'),
!mergedOptions.toggleFlags.disableCoreJs &&
require.resolve('core-js/stable'),
mergedOptions.entryPoint,
],
},
Expand Down Expand Up @@ -233,6 +238,7 @@ module.exports = function createWebpackConfigForProduction(options = {}) {
),
{
runtime: hasJsxRuntime() ? 'automatic' : 'classic',
disableCoreJs: mergedOptions.toggleFlags.disableCoreJs,
},
],
],
Expand Down

1 comment on commit 481fb8f

@vercel
Copy link

@vercel vercel bot commented on 481fb8f Jun 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.