-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby): enable modern builds for gatsby #14289
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
16f2ba1
update babel-preset-gatsby with modern option
wardpeet ba811f3
enable gatsby to use new babel-preset
wardpeet 7fb16a5
enable modern builds in build-javascript
wardpeet b2119ce
add module scripts to gatsby
wardpeet 39a60a8
add nomodule safari/edge fix
wardpeet 7a61cf7
Merge branch 'master' into feat/modern-builds
wardpeet 2479897
add flag ENABLE_MODERN_BUILDS to enable modern syntax
wardpeet 8ffefd1
savepoint
wardpeet d964eb0
Fix build
sidharthachatterjee 3c7fcb3
Lint
sidharthachatterjee d801a91
fix stage & modern for dependencies
wardpeet 8d1b31d
fix modern-builds in static-entry
wardpeet 6eb26de
move modern check to javascript
wardpeet bf9ecee
write tests
wardpeet b570b2d
add to circleci
wardpeet d4523b1
fix litn
wardpeet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Project dependencies | ||
.cache | ||
node_modules | ||
yarn-error.log | ||
|
||
# Build directory | ||
/public | ||
.DS_Store | ||
|
||
# Cypress output | ||
cypress/videos/ | ||
cypress/screenshots/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,3 @@ | ||||||
# production-runtime | ||||||
|
||||||
A Gatsby project to test our production runtime for Themes | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"baseUrl": "http://localhost:9000", | ||
"chromeWebSecurity": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* global cy */ | ||
|
||
describe(`Preload`, () => { | ||
it(`preloads on first visit`, () => { | ||
cy.visit(`/`).waitForRouteChange() | ||
|
||
// module preloads should only contain mjs | ||
cy.get(`link[rel="modulepreload"]`).each($el => { | ||
// eslint-disable-next-line no-unused-expressions | ||
expect($el.attr(`href`).endsWith(`.mjs`)).to.be.true | ||
}) | ||
|
||
// No regular script preloads should be here | ||
cy.get(`link[rel="preload"][as="script"]`).should($preloads => { | ||
expect($preloads).to.have.length(0) | ||
}) | ||
|
||
// prefetch of page 2 should still happen and should be an mjs | ||
cy.get( | ||
`link[rel="prefetch"][href^="/component---src-pages-page-2-js"][href$=".mjs"]` | ||
).should(`exist`) | ||
}) | ||
|
||
it(`Initiate script tags on hoverng Gatsby Link Tags`, () => { | ||
cy.get(`a[href="/page-2"`).trigger(`mouseover`) | ||
cy.get( | ||
`script[src^="/component---src-pages-page-2-js"][src$=".mjs"]` | ||
).should(`exist`) | ||
}) | ||
}) | ||
|
||
describe(`Runtime`, () => { | ||
it(`should only load modern scripts`, () => { | ||
cy.window().then(win => { | ||
const scripts = Object.values(win.___chunkMapping).flat() | ||
expect(scripts.filter(path => path.endsWith(`.mjs`)).length).to.equal( | ||
scripts.length | ||
) | ||
}) | ||
|
||
cy.get(`script[src]`).each($el => { | ||
// eslint-disable-next-line no-unused-expressions | ||
expect($el.attr(`src`).endsWith(`.mjs`)).to.be.true | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "gatsby-cypress" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
if (typeof window !== `undefined`) { | ||
window.___PageComponentLifecycleCallsLog = [] | ||
} | ||
|
||
const addLogEntry = (action, location) => { | ||
const idElement = document.querySelector(`[data-testid="dom-marker"]`) | ||
window.___PageComponentLifecycleCallsLog.push({ | ||
action, | ||
pathname: location.pathname, | ||
domContent: idElement ? idElement.innerText : null, | ||
}) | ||
} | ||
|
||
exports.onPreRouteUpdate = ({ location }) => { | ||
addLogEntry(`onPreRouteUpdate`, location) | ||
} | ||
|
||
exports.onRouteUpdate = ({ location }) => { | ||
addLogEntry(`onRouteUpdate`, location) | ||
} | ||
|
||
exports.onPrefetchPathname = ({ pathname }) => { | ||
addLogEntry(`onPrefetchPathname`, pathname) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
siteMetadata: { | ||
title: `Modern Builds are awesome`, | ||
description: `Testing modern builds, yeah!`, | ||
author: `Ward Peeters`, | ||
}, | ||
plugins: [], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "modern-builds", | ||
"description": "Tesing modern builds logic", | ||
"version": "1.0.0", | ||
"author": "Ward Peeters <ward@gatsbyjs.com>", | ||
"dependencies": { | ||
"gatsby": "^2.13.14", | ||
"react": "^16.8.0", | ||
"react-dom": "^16.8.0" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "cross-env ENABLE_MODERN_BUILDS=1 gatsby build", | ||
"develop": "cross-env ENABLE_MODERN_BUILDS=1 gatsby develop", | ||
"format": "prettier --write \"src/**/*.js\"", | ||
"serve": "gatsby serve", | ||
"start": "npm run develop", | ||
"test": "cross-env CYPRESS_SUPPORT=y npm run build && npm run start-server-and-test", | ||
"start-server-and-test": "start-server-and-test serve http://localhost:9000 cy:run", | ||
"cy:open": "cypress open", | ||
"cy:run": "cypress run --browser chrome" | ||
}, | ||
"devDependencies": { | ||
"cross-env": "^5.2.0", | ||
"cypress": "^3.1.3", | ||
"gatsby-cypress": "^0.1.7", | ||
"prettier": "^1.15.2", | ||
"start-server-and-test": "^1.7.11" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react" | ||
import { graphql, Link } from "gatsby" | ||
|
||
export default ({ data }) => ( | ||
<> | ||
<p data-testid="title">{data.site.siteMetadata.title}</p> | ||
<p data-testid="author">{data.site.siteMetadata.author}</p> | ||
|
||
<Link to="/page-2">Go to page 2</Link> | ||
</> | ||
) | ||
|
||
export const pageQuery = graphql` | ||
query { | ||
site { | ||
siteMetadata { | ||
title | ||
author | ||
} | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import React from "react" | ||
|
||
export default () => <p>Page 2</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.