Skip to content
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

fix(gatsby): correctly pick up browserslist overrides #9669

Merged
merged 6 commits into from
Nov 14, 2018

Conversation

DSchau
Copy link
Contributor

@DSchau DSchau commented Nov 2, 2018

Just to get some 👀 on this early, this is somewhat working. It's fairly challenging to test this, so I've been using gatsby-plugin-webpack-bundle-analyzer and inspecting the size of the bundled assets. Currently, can't seem to get it to change with the browserslist query, but it is picked up (correctly) and added to .cache/babelState.json.

More to do here 🙃

Begins to fix #7003, in that enabling browserslist functionality should clean up IE specific stuff.

@DSchau DSchau requested a review from a team as a code owner November 2, 2018 19:07
Copy link
Contributor Author

@DSchau DSchau left a comment

Choose a reason for hiding this comment

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

Left a few comments

@@ -25,16 +25,14 @@ function preset(context, options = {}) {
node: `current`,
}
} else {
targets = {
browsers: pluginBabelConfig.browserslist,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this will be removed in later version in favor of just setting "targets" to a query directly.

https://babeljs.io/docs/en/babel-preset-env#targetsbrowsers


let siteInfo = { directory, browserslist: DEFAULT_BROWSERS }
const useYarn = existsSync(path.join(directory, `yarn.lock`))
if (isLocalSite) {
const json = require(path.join(directory, `package.json`))
siteInfo.sitePackageJson = json
siteInfo.browserslist = json.browserslist || siteInfo.browserslist
siteInfo.browserslist = getBrowsersList(directory, DEFAULT_BROWSERS)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems kind of weird to have the set up working like this, i.e. gatsby-cli sets up some program stuff, and then other plugins use it. Might try to improve this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, can't remember why gatsby-cli does this

@DSchau DSchau changed the title [WIP]: fix: start ironing out browserslist issues fix(gatsby): start ironing out browserslist issues Nov 14, 2018
@DSchau DSchau changed the title fix(gatsby): start ironing out browserslist issues fix(gatsby): correctly pick up browserslist overrides Nov 14, 2018
@DSchau
Copy link
Contributor Author

DSchau commented Nov 14, 2018

Alright, so this PR is ready, although I plan to make the improvements to not requiring browserslist in gatsby-cli--which seems weird.

After testing, this change does work like we'd expect, but it appears there's at least one weird thing.

We use useBuiltIns: 'usage', which means that babel will intelligently detect what polyfills it needs to load from JS, which works great for our source code. You can add something in the src/ directory, e.g. new Set() and then use webpack-bundle-analyzer to see the collections utility from core-js get added to the bundle. This will be fixed and work like we'd expect in this PR.

Currently the only check we were making was with the users package.json browserslist key, rather than the order of checks that browserslist actually uses, e.g. env var, browserslistrc file, package.json key, etc.

However - the gotcha is that we don't parse node_modules with babel. This means that useBuiltIns can't know what polyfills we could need to include for e.g. some third party dep. It may be worth doing that in the future, but it doesn't seem like other projects are doing that quite yet. Might be nice to make this opt-in with a plugin or something in the future.

@DSchau
Copy link
Contributor Author

DSchau commented Nov 14, 2018

Just need to fix the tests 😅 Doing that now.

@KyleAMathews
Copy link
Contributor

CRA v2 now compiles node_modules facebook/create-react-app#1125

@DSchau
Copy link
Contributor Author

DSchau commented Nov 14, 2018

@KyleAMathews I knew I saw something about that! That's probably slightly out of scope for this PR, but that could be worth following a similar approach to how they've done it!

@KyleAMathews
Copy link
Contributor

Sounds good!

@DSchau
Copy link
Contributor Author

DSchau commented Nov 14, 2018

Also @souporserious this may fix the issue you were running into in development mode! It's kinda hard to validate Windows stuff 😅

Any interest in checking it out?

@pieh
Copy link
Contributor

pieh commented Nov 14, 2018

screen shot 2018-11-15 at 00 13 42
IE still won't work with gatsby develop - it fails in react-hot-loader currently, but this PR does fix browserlist, so let's merge it!

@pieh pieh merged commit 0f0feac into gatsbyjs:master Nov 14, 2018
@DSchau DSchau deleted the browserslist/fixes branch November 15, 2018 15:18
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
* fix: start ironing out browserslist issues

* chore: make linter happy

* chore: change to expected shape

* refactor: move browserslist functionality into gatsby core
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v2] IE11 throws Objects are not valid as a React child
3 participants