Skip to content

Commit

Permalink
fix typo and update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
nihgwu committed Apr 9, 2019
1 parent afd833a commit 56e80ad
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
6 changes: 2 additions & 4 deletions docs/docs/browser-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ By default, Gatsby emulates the following config:
If you only support newer browsers, make sure to specify this in your
`package.json`. This will often enable you to ship smaller JavaScript files.

## Note about IE < 11
## Note about IE support

React depends on collection types `Map` and `Set`. While these are not used by Gatsby, Gatsby uses React and you will need to polyfill these if you support older browsers and devices including IE < 11.

Read more about this in [https://reactjs.org/docs/javascript-environment-requirements.html](https://reactjs.org/docs/javascript-environment-requirements.html)
Gatsby will polyfil minimum requirements for IE support according to the `browserslist` config.
39 changes: 17 additions & 22 deletions packages/gatsby/src/utils/__tests__/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const { DefinePlugin } = require(`webpack`)
const { readFileSync } = require(`fs-extra`)
const webpackConfig = require(`../webpack.config`)
const { store } = require(`../../redux`)
const { joinPath } = require(`../path`)

beforeEach(() => {
DefinePlugin.mockClear()
Expand Down Expand Up @@ -119,53 +120,47 @@ describe(`environment variables`, () => {
})
})

describe(`polyfil for ie support`, () => {
it(`should not add ie polyfil if ie is not supported`, async () => {
describe(`polyfill for ie support`, () => {
const directory = `gatsby-app`
const appEntry = joinPath(directory, `.cache/production-app`)

it(`should not add ie polyfill if ie is not supported`, async () => {
const config = await getConfig(
{ browserslist: `defaults, not ie >= 9` },
`gatsby-app`,
directory,
`build-javascript`
)

expect(config.entry.app).toEqual([`gatsby-app/.cache/production-app`])
expect(config.entry.app).toEqual([appEntry])
})

it(`should add ie9 polyfil if ie >= 9 is supported`, async () => {
it(`should add ie9 polyfill if ie >= 9 is supported`, async () => {
const config = await getConfig(
{ browserslist: `defaults, ie >= 9` },
`gatsby-app`,
directory,
`build-javascript`
)

expect(config.entry.app).toEqual([
`react-app-polyfill/ie9`,
`gatsby-app/.cache/production-app`,
])
expect(config.entry.app).toEqual([`react-app-polyfill/ie9`, appEntry])
})

it(`should add ie9 polyfil if ie >= 10 is supported`, async () => {
it(`should add ie9 polyfill if ie >= 10 is supported`, async () => {
const config = await getConfig(
{ browserslist: `defaults, ie >= 10` },
`gatsby-app`,
directory,
`build-javascript`
)

expect(config.entry.app).toEqual([
`react-app-polyfill/ie9`,
`gatsby-app/.cache/production-app`,
])
expect(config.entry.app).toEqual([`react-app-polyfill/ie9`, appEntry])
})

it(`should add ie11 polyfil if ie >= 11 is supported`, async () => {
it(`should add ie11 polyfill if ie >= 11 is supported`, async () => {
const config = await getConfig(
{ browserslist: `defaults, ie >= 11` },
`gatsby-app`,
directory,
`build-javascript`
)

expect(config.entry.app).toEqual([
`react-app-polyfill/ie11`,
`gatsby-app/.cache/production-app`,
])
expect(config.entry.app).toEqual([`react-app-polyfill/ie11`, appEntry])
})
})
12 changes: 6 additions & 6 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ module.exports = async (
) => {
const directoryPath = withBasePath(directory)

// Polyfil for IE support
// Polyfill for IE support
const supportedBrowsers = browserslist(program.browserslist)
let iePolyfil = false
let iePolyfill = false
if (
supportedBrowsers.includes(`ie 9`) ||
supportedBrowsers.includes(`ie 10`)
) {
iePolyfil = `react-app-polyfill/ie9`
iePolyfill = `react-app-polyfill/ie9`
} else if (supportedBrowsers.includes(`ie 11`)) {
iePolyfil = `react-app-polyfill/ie11`
iePolyfill = `react-app-polyfill/ie11`
}

process.env.GATSBY_BUILD_STAGE = suppliedStage
Expand Down Expand Up @@ -164,7 +164,7 @@ module.exports = async (
case `develop`:
return {
commons: [
iePolyfil,
iePolyfill,
`event-source-polyfill`,
`${require.resolve(
`webpack-hot-middleware/client`
Expand All @@ -182,7 +182,7 @@ module.exports = async (
}
case `build-javascript`:
return {
app: [iePolyfil, directoryPath(`.cache/production-app`)].filter(
app: [iePolyfill, directoryPath(`.cache/production-app`)].filter(
Boolean
),
}
Expand Down

0 comments on commit 56e80ad

Please sign in to comment.