Unverified Commit 7d664d5b authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add stats config for SWC (#28883)

* Add stats config for SWC

* Remove stats for deprecated mode

* Include native binaries in local linking

* Expose minify in next-swc

* Build next-swc binaries

* Only upload changed binary artifact

* Build next-swc binaries

* Expose minify in js binding

* Use new minify function in terser plugin

* Build next-swc binaries

* Build next-swc binaries

* Build next-swc binaries

* Pass pagesDir option to SWC for next/dynamic

* Build next-swc binaries

* Add spans for next-trace-entrypoints-plugin

* Fix linting
Co-authored-by: 's avatarMaia Teegarden <dev@padmaia.rocks>
Co-authored-by: 's avatarpadmaia <padmaia@users.noreply.github.com>
Co-authored-by: 's avatartimneutkens <timneutkens@users.noreply.github.com>
parent 0e29a2d0
...@@ -93,6 +93,10 @@ module.exports = (actionInfo) => { ...@@ -93,6 +93,10 @@ module.exports = (actionInfo) => {
if (!pkgData.dependencies || !pkgData.dependencies[pkg]) continue if (!pkgData.dependencies || !pkgData.dependencies[pkg]) continue
pkgData.dependencies[pkg] = packedPkgPath pkgData.dependencies[pkg] = packedPkgPath
} }
// make sure native binaries are included in local linking
if (pkg === 'next') {
pkgData.files.push('native')
}
await fs.writeFile( await fs.writeFile(
pkgDataPath, pkgDataPath,
JSON.stringify(pkgData, null, 2), JSON.stringify(pkgData, null, 2),
......
...@@ -29,7 +29,13 @@ DEALINGS IN THE SOFTWARE. ...@@ -29,7 +29,13 @@ DEALINGS IN THE SOFTWARE.
import { getOptions } from 'next/dist/compiled/loader-utils' import { getOptions } from 'next/dist/compiled/loader-utils'
import { transform } from '../../swc' import { transform } from '../../swc'
function getSWCOptions({ isTypeScript, isServer, development, isPageFile }) { function getSWCOptions({
isTypeScript,
isServer,
development,
isPageFile,
pagesDir,
}) {
const jsc = { const jsc = {
parser: { parser: {
syntax: isTypeScript ? 'typescript' : 'ecmascript', syntax: isTypeScript ? 'typescript' : 'ecmascript',
...@@ -54,6 +60,7 @@ function getSWCOptions({ isTypeScript, isServer, development, isPageFile }) { ...@@ -54,6 +60,7 @@ function getSWCOptions({ isTypeScript, isServer, development, isPageFile }) {
jsc, jsc,
// Disables getStaticProps/getServerSideProps tree shaking on the server compilation for pages // Disables getStaticProps/getServerSideProps tree shaking on the server compilation for pages
disableNextSsg: true, disableNextSsg: true,
pagesDir,
env: { env: {
targets: { targets: {
// Targets the current version of Node.js // Targets the current version of Node.js
...@@ -64,7 +71,11 @@ function getSWCOptions({ isTypeScript, isServer, development, isPageFile }) { ...@@ -64,7 +71,11 @@ function getSWCOptions({ isTypeScript, isServer, development, isPageFile }) {
} else { } else {
// Matches default @babel/preset-env behavior // Matches default @babel/preset-env behavior
jsc.target = 'es5' jsc.target = 'es5'
return { disableNextSsg: !isPageFile, jsc } return {
disableNextSsg: !isPageFile,
pagesDir,
jsc,
}
} }
} }
...@@ -80,6 +91,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) { ...@@ -80,6 +91,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
const isPageFile = filename.startsWith(pagesDir) const isPageFile = filename.startsWith(pagesDir)
const swcOptions = getSWCOptions({ const swcOptions = getSWCOptions({
pagesDir,
isTypeScript, isTypeScript,
isServer: isServer, isServer: isServer,
isPageFile, isPageFile,
......
...@@ -121,15 +121,22 @@ module.exports = { ...@@ -121,15 +121,22 @@ module.exports = {
}, },
}, },
{ {
title: 'Webpack 4 Mode', title: 'Default Build with SWC',
diff: 'onOutputChange', diff: 'onOutputChange',
diffConfigFiles: [ diffConfigFiles: [
{
path: 'pages/image.js',
content: imagePageData,
},
{ {
path: 'next.config.js', path: 'next.config.js',
content: ` content: `
module.exports = { module.exports = {
generateBuildId: () => 'BUILD_ID', generateBuildId: () => 'BUILD_ID',
webpack5: false, experimental: {
swcLoader: true,
swcMinify: true,
},
webpack(config) { webpack(config) {
config.optimization.minimize = false config.optimization.minimize = false
config.optimization.minimizer = undefined config.optimization.minimizer = undefined
...@@ -139,14 +146,22 @@ module.exports = { ...@@ -139,14 +146,22 @@ module.exports = {
`, `,
}, },
], ],
// renames to apply to make file names deterministic
renames, renames,
configFiles: [ configFiles: [
{
path: 'pages/image.js',
content: imagePageData,
},
{ {
path: 'next.config.js', path: 'next.config.js',
content: ` content: `
module.exports = { module.exports = {
generateBuildId: () => 'BUILD_ID', experimental: {
webpack5: false swcLoader: true,
swcMinify: true
},
generateBuildId: () => 'BUILD_ID'
} }
`, `,
}, },
......
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