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