dilanx / craco

Create React App Configuration Override, an easy and comprehensible configuration layer for Create React App.
https://craco.js.org
Apache License 2.0
7.44k stars 499 forks source link

Babel 7.13 compiler assumptions #350

Closed hyperknot closed 2 years ago

hyperknot commented 2 years ago

Hi, will it be possible to use the Babel 7.13 compiler assumptions with an assumptions key? https://babeljs.io/docs/en/assumptions

For example MobX docs say the following:

{
    "plugins": [["@babel/plugin-proposal-class-properties", { "loose": false }]],
    // Babel >= 7.13.0 (https://babeljs.io/docs/en/assumptions)
    "assumptions": {
        "setPublicClassFields": false
    }
}

It'd be nice to use this syntax in CRACO.

DronDima commented 2 years ago

Hello, i also have issue with assumptions. I'm trying to use decorator inside react class component, but babel overrides it. So, from different sources(one, two and others) it looks like i need to add @babel/plugin-proposal-decorators with legacy: true. But In official documentation they have note that we need to add setPublicClassFields assumption in babel config when using legacy: true.

hyperknot commented 2 years ago

@DronDima I don't think the assumption is needed as of today, as the current Babel is 7.12 in CRA.

This works for decorators:

module.exports = {
  babel: {
    plugins: [
      ['@babel/plugin-proposal-decorators', { legacy: true }],
      ['@babel/plugin-proposal-class-properties', { loose: false }],
    ]
  },
}
hyperknot commented 2 years ago

OK, the new CRA 5.x actually ships Babel 7.16, so we'd need these assumptions. Has anyone managed to get this right?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

hyperknot commented 2 years ago

Not stale

On 2022. May 1., Sun at 0:29, stale[bot] @.***> wrote:

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

— Reply to this email directly, view it on GitHub https://github.com/gsoft-inc/craco/issues/350#issuecomment-1114064281, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADYVD5RJ7UZPGW53CKA3LDVHWX4DANCNFSM5JTXV4MQ . You are receiving this because you authored the thread.Message ID: @.***>

dilanx commented 2 years ago

@hyperknot sorry for such a long delay. I've added this functionality and will release it in alpha 8. I haven't tested it, but if you'd like to ensure that it works for you as you expect once alpha 8 is out, that would be great!

hyperknot commented 2 years ago

I've done the upgrade to test this. It seems to be working, at least I get a warning message if I add assumptions. There are other errors with react-scripts@5.x which I won't start debugging, but the CRACO part seems to be working.

dilanx commented 2 years ago

Thanks @hyperknot. If the craco part seems to be working, I'll close this issue. Feel free to leave a comment if there are any problems.