-
-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set useBuiltIns to false by default and allow to set core-js version #545
Conversation
Thanks for this very detailed outline! I have one question, or possible alternative approach to ask you about. Can we (and should we) detect if corejs is installed and set the useBuiltIns option and I core-js version based on that. The idea would be: if you install core-js, we just start using it, by default. Let me know what you think. There is a cost to this magic. However, most users won’t know this option exists, and our job is to give them a great setup without them needing to know about everything before they start. Another possibility is to update the Encore Flex recipe to instal core-js and set the necessary Babel config in the default webpack.config.js file |
I thought about that but wasn't sure it was the right thing to do. The first thing I don't really like with that solution is that we'll be modifying Webpack's conf based on which packages are installed, which means that if something goes wrong a build could break because a package was installed/updated, even if it's not used anywhere (or not in the context we expect it to). Also it's a bit like saying "we'll check if The second thing that could be a bit annoying is detecting Here is a more concrete example that I think could be an issue: imagine that a lib imported by the user requires Then the user decides to install another dependency which relies on
Well, that's also an issue right now: when using I think that it would be better to add that to the recipe and either:
|
@Lyrkan Ok, let's merge this (set the default to |
8829d3f
to
2799fbf
Compare
@weaverryan About the recipe: should we go for |
On second thought maybe we could use
And if people encounter issues they could still switch to |
2799fbf
to
85896ef
Compare
Excellent! That always seemed like the best mode anyways, except for the unstable part. Let's go with it. |
* Set the "useBuiltIns" option of @babel/preset-env that changes | ||
* how it handles polyfills (https://babeljs.io/docs/en/babel-preset-env#usebuiltins) | ||
* Using it with 'entry' will require you to import @babel/polyfill | ||
* Using it with 'entry' will require you to import core-js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't core-js also required when using the option usage
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is required (= you have to yarn add core-js
) but you don't need to import it into your files.
Thank you @Lyrkan! |
… version (Lyrkan) This PR was merged into the master branch. Discussion ---------- Set useBuiltIns to false by default and allow to set core-js version While working on #544 I noticed that the latest version of `@babel/preset-env` displayed a warning (which luckily made [one of the tests](https://travis-ci.org/symfony/webpack-encore/jobs/509655320) fail): ``` WARNING: We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option. You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands: npm install --save core-js@2 npm install --save core-js@3 yarn add core-js@2 yarn add core-js@3 ``` This is related to the `core-js` 3 update that happened recently (see babel/babel#7646). As explained in parcel-bundler/parcel#2819 (comment) the issue is that users are normally supposed to add `core-js` in their root `package.json` when setting `useBuiltIns` (which is currently already set by Encore to `entry` by default). This is a problem for us since it means that: * we are requiring users to add `core-js` to their project by default (or manually setting `useBuiltIns` to `false`) * if they do they'll still have a warning because the new `corejs` option of `@babel/preset-env` won't be set (we can't do that because we won't know which version they choose to install). For now I suggest that we set `useBuiltIns` to `false` by default and add a new option to `Encore.configureBabel()` that allows to set the `corejs` option. Commits ------- 85896ef Set useBuiltIns to false by default and allow to set corejs version
While working on #544 I noticed that the latest version of
@babel/preset-env
displayed a warning (which luckily made one of the tests fail):This is related to the
core-js
3 update that happened recently (see babel/babel#7646).As explained in parcel-bundler/parcel#2819 (comment) the issue is that users are normally supposed to add
core-js
in their rootpackage.json
when settinguseBuiltIns
(which is currently already set by Encore toentry
by default).This is a problem for us since it means that:
core-js
to their project by default (or manually settinguseBuiltIns
tofalse
)corejs
option of@babel/preset-env
won't be set (we can't do that because we won't know which version they choose to install).For now I suggest that we set
useBuiltIns
tofalse
by default and add a new option toEncore.configureBabel()
that allows to set thecorejs
option.