diff --git a/packages/gatsby/src/utils/__tests__/browserslist.js b/packages/gatsby/src/utils/__tests__/browserslist.js index 2b37953e10f30..0014f4003cff3 100644 --- a/packages/gatsby/src/utils/__tests__/browserslist.js +++ b/packages/gatsby/src/utils/__tests__/browserslist.js @@ -28,7 +28,14 @@ describe(`browserslist`, () => { const list = getBrowsersList(BASE) - expect(list).toEqual([`>0.25%`, `not dead`]) + if (_CFLAGS_.GATSBY_MAJOR === `5`) { + expect(list).toEqual([ + `>0.25% and supports es6-module`, + `not dead and supports es6-module`, + ]) + } else { + expect(list).toEqual([`>0.25%`, `not dead`]) + } }) it(`hasES6ModuleSupport returns true if all browsers support es6 modules`, () => { diff --git a/packages/gatsby/src/utils/browserslist.ts b/packages/gatsby/src/utils/browserslist.ts index aa841976f9966..9b06bd6168a44 100644 --- a/packages/gatsby/src/utils/browserslist.ts +++ b/packages/gatsby/src/utils/browserslist.ts @@ -18,10 +18,17 @@ const installedGatsbyVersion = (directory: string): number | undefined => { } export const getBrowsersList = (directory: string): Array => { + const fallbackV1 = [`>1%`, `last 2 versions`, `IE >= 9`] + let fallbackOthers = [`>0.25%`, `not dead`] + + if (_CFLAGS_.GATSBY_MAJOR === `5`) { + fallbackOthers = fallbackOthers.map( + fallback => fallback + ` and supports es6-module` + ) + } + const fallback = - installedGatsbyVersion(directory) === 1 - ? [`>1%`, `last 2 versions`, `IE >= 9`] - : [`>0.25%`, `not dead`] + installedGatsbyVersion(directory) === 1 ? fallbackV1 : fallbackOthers const config = browserslist.findConfig(directory)