Unverified Commit 71d798ce authored by Prateek Bhatnagar's avatar Prateek Bhatnagar Committed by GitHub

Font optimization for webpack 5 (#17450)

Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
Co-authored-by: 's avatarTim Neutkens <timneutkens@me.com>
parent 1c4aecbe
...@@ -107,12 +107,13 @@ jobs: ...@@ -107,12 +107,13 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - 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 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 package.json | jq '.resolutions.react = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp 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
- 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."react-dom" = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp packages/next/package.json
- run: yarn install --check-files - run: yarn install --check-files
- run: node run-tests.js test/integration/production/test/index.test.js - 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/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/* - run: node run-tests.js test/acceptance/*
testFirefox: testFirefox:
......
...@@ -5,8 +5,6 @@ import { ...@@ -5,8 +5,6 @@ import {
getFontDefinitionFromNetwork, getFontDefinitionFromNetwork,
FontManifest, FontManifest,
} from '../../../next-server/server/font-utils' } from '../../../next-server/server/font-utils'
// @ts-ignore
import BasicEvaluatedExpression from 'webpack/lib/BasicEvaluatedExpression'
import postcss from 'postcss' import postcss from 'postcss'
import minifier from 'cssnano-simple' import minifier from 'cssnano-simple'
import { OPTIMIZED_FONT_PROVIDERS } from '../../../next-server/lib/constants' import { OPTIMIZED_FONT_PROVIDERS } from '../../../next-server/lib/constants'
...@@ -16,6 +14,13 @@ const { RawSource } = webpack.sources || sources ...@@ -16,6 +14,13 @@ const { RawSource } = webpack.sources || sources
const isWebpack5 = parseInt(webpack.version!) === 5 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> { async function minifyCss(css: string): Promise<string> {
return new Promise((resolve) => return new Promise((resolve) =>
postcss([ postcss([
...@@ -62,13 +67,20 @@ export class FontStylesheetGatheringPlugin { ...@@ -62,13 +67,20 @@ export class FontStylesheetGatheringPlugin {
if (parser?.state?.module?.resource.includes('node_modules')) { if (parser?.state?.module?.resource.includes('node_modules')) {
return return
} }
return node.name === '__jsx' let result
? new BasicEvaluatedExpression() if (node.name === '__jsx') {
//@ts-ignore result = new BasicEvaluatedExpression()
.setRange(node.range) // @ts-ignore
.setExpression(node) result.setRange(node.range)
.setIdentifier('__jsx') result.setExpression(node)
: undefined result.setIdentifier('__jsx')
// This was added webpack 5.
if (isWebpack5) {
result.getMembers = () => []
}
}
return result
}) })
parser.hooks.call parser.hooks.call
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment