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

Font optimization for webpack 5 #17450

Merged
merged 24 commits into from Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c7b90c4
fixing font optimization for webpack 5
prateekbh Sep 29, 2020
5a56ccd
fixing comment language
prateekbh Sep 29, 2020
273192f
enable font optimization test for webpack 5
prateekbh Oct 2, 2020
0de4172
Merge branch 'canary' of https://github.com/zeit/next.js into font-we…
prateekbh Oct 2, 2020
cc429a2
changing tests order
prateekbh Oct 2, 2020
3746058
updating webpack version
prateekbh Oct 5, 2020
b11d239
Merge branch 'canary' into font-webpack5
prateekbh Oct 5, 2020
e11dcb8
making webpack version logged
prateekbh Oct 5, 2020
57d6399
Merge branch 'canary' into font-webpack5
prateekbh Oct 5, 2020
8a1b7a2
more logging
prateekbh Oct 6, 2020
8507323
Merge branch 'font-webpack5' of https://github.com/azukaru/next.js in…
prateekbh Oct 6, 2020
5f14ed7
one more log
prateekbh Oct 6, 2020
ac6ec8a
some changes
prateekbh Oct 6, 2020
14bd5da
reverting unwanted changes
prateekbh Oct 6, 2020
eea002a
some changes
prateekbh Oct 6, 2020
6637989
Merge branch 'canary' of https://github.com/azukaru/next.js into font…
prateekbh Oct 6, 2020
9bfcd29
adding resolutions to package/next instead of root
prateekbh Oct 6, 2020
c32dfd7
preview package.json
prateekbh Oct 6, 2020
16bbd70
fixing url
prateekbh Oct 6, 2020
c5e8fe7
Apply suggestions from code review
timneutkens Oct 7, 2020
23d862e
Revert "Apply suggestions from code review"
timneutkens Oct 7, 2020
2a3e1a9
Merge branch 'canary' of https://github.com/zeit/next.js into font-we…
prateekbh Oct 9, 2020
4299ce2
removing unwanted logs
prateekbh Oct 9, 2020
56a8e0d
Merge branch 'canary' into font-webpack5
prateekbh Oct 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/build_test_deploy.yml
Expand Up @@ -107,12 +107,13 @@ jobs:
steps:
- uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- run: cat package.json | jq '.resolutions.webpack = "^5.0.0-beta.30"' > package.json.tmp && mv package.json.tmp package.json
- run: cat package.json | jq '.resolutions.react = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp package.json
- run: cat package.json | jq '.resolutions."react-dom" = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp package.json
- run: cat packages/next/package.json | jq '.resolutions.webpack = "^5.0.0-beta.30"' > package.json.tmp && mv package.json.tmp packages/next/package.json
- run: cat packages/next/package.json | jq '.resolutions.react = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp packages/next/package.json
timneutkens marked this conversation as resolved.
Show resolved Hide resolved
- run: cat packages/next/package.json | jq '.resolutions."react-dom" = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp packages/next/package.json
timneutkens marked this conversation as resolved.
Show resolved Hide resolved
- run: yarn install --check-files
- run: node run-tests.js test/integration/production/test/index.test.js
- run: node run-tests.js test/integration/basic/test/index.test.js
- run: node run-tests.js test/integration/font-optimization/test/index.test.js
- run: node run-tests.js test/acceptance/*

testFirefox:
Expand Down
Expand Up @@ -5,8 +5,6 @@ import {
getFontDefinitionFromNetwork,
FontManifest,
} from '../../../next-server/server/font-utils'
// @ts-ignore
import BasicEvaluatedExpression from 'webpack/lib/BasicEvaluatedExpression'
import postcss from 'postcss'
import minifier from 'cssnano-simple'
import { OPTIMIZED_FONT_PROVIDERS } from '../../../next-server/lib/constants'
Expand All @@ -16,6 +14,13 @@ const { RawSource } = webpack.sources || sources

const isWebpack5 = parseInt(webpack.version!) === 5

let BasicEvaluatedExpression: any
if (isWebpack5) {
BasicEvaluatedExpression = require('webpack/lib/javascript/BasicEvaluatedExpression')
} else {
BasicEvaluatedExpression = require('webpack/lib/BasicEvaluatedExpression')
}

async function minifyCss(css: string): Promise<string> {
return new Promise((resolve) =>
postcss([
Expand Down Expand Up @@ -62,13 +67,20 @@ export class FontStylesheetGatheringPlugin {
if (parser?.state?.module?.resource.includes('node_modules')) {
return
}
return node.name === '__jsx'
? new BasicEvaluatedExpression()
//@ts-ignore
.setRange(node.range)
.setExpression(node)
.setIdentifier('__jsx')
: undefined
let result
if (node.name === '__jsx') {
result = new BasicEvaluatedExpression()
// @ts-ignore
result.setRange(node.range)
result.setExpression(node)
result.setIdentifier('__jsx')

// This was added webpack 5.
if (isWebpack5) {
result.getMembers = () => []
}
}
return result
})

parser.hooks.call
Expand Down