Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
326 lines
12 KiB
JavaScript
326 lines
12 KiB
JavaScript
const webpack = require('@rspack/core')
|
|
const path = require('path')
|
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
|
|
const DevToolsIgnoreListPlugin = require('./webpack-plugins/devtools-ignore-list-plugin')
|
|
|
|
function shouldIgnorePath(modulePath) {
|
|
// For consumers, everything will be considered 3rd party dependency if they use
|
|
// the bundles we produce here.
|
|
// In other words, this is all library code and should therefore be ignored.
|
|
return true
|
|
}
|
|
|
|
const pagesExternals = [
|
|
'react',
|
|
'react/package.json',
|
|
'react/jsx-runtime',
|
|
'react/jsx-dev-runtime',
|
|
'react/compiler-runtime',
|
|
'react-dom',
|
|
'react-dom/package.json',
|
|
'react-dom/client',
|
|
'react-dom/server',
|
|
'react-dom/server.browser',
|
|
'react-dom/server.edge',
|
|
'react-server-dom-webpack/client',
|
|
'react-server-dom-webpack/server',
|
|
'react-server-dom-webpack/server.node',
|
|
'react-server-dom-webpack/static',
|
|
]
|
|
|
|
const appExternals = []
|
|
|
|
function makeAppAliases({ experimental, bundler }) {
|
|
const reactChannel = experimental ? '-experimental' : ''
|
|
|
|
return {
|
|
react$: `next/dist/compiled/react${reactChannel}`,
|
|
'react/react.react-server$': `next/dist/compiled/react${reactChannel}/react.react-server`,
|
|
'react-dom$': `next/dist/compiled/react-dom${reactChannel}`,
|
|
'react/jsx-runtime$': `next/dist/compiled/react${reactChannel}/jsx-runtime`,
|
|
'react/jsx-dev-runtime$': `next/dist/compiled/react${reactChannel}/jsx-dev-runtime`,
|
|
'react/compiler-runtime$': `next/dist/compiled/react${reactChannel}/compiler-runtime`,
|
|
'react-dom/client$': `next/dist/compiled/react-dom${reactChannel}/client`,
|
|
// optimizations to ignore the legacy APIs in react-dom/server
|
|
'react-dom/server$': `next/dist/build/webpack/alias/react-dom-server${reactChannel}.js`,
|
|
'react-dom/static$': `next/dist/compiled/react-dom${reactChannel}/static.node`,
|
|
// react-server-dom-webpack alias
|
|
'react-server-dom-turbopack/client$': `next/dist/compiled/react-server-dom-turbopack${reactChannel}/client.node`,
|
|
'react-server-dom-turbopack/server$': `next/dist/compiled/react-server-dom-turbopack${reactChannel}/server.node`,
|
|
'react-server-dom-turbopack/server.node$': `next/dist/compiled/react-server-dom-turbopack${reactChannel}/server.node`,
|
|
'react-server-dom-turbopack/static$': `next/dist/compiled/react-server-dom-turbopack${reactChannel}/static.node`,
|
|
'react-server-dom-webpack/client$': `next/dist/compiled/react-server-dom-${bundler}${reactChannel}/client.node`,
|
|
'react-server-dom-webpack/server$': `next/dist/compiled/react-server-dom-${bundler}${reactChannel}/server.node`,
|
|
'react-server-dom-webpack/server.node$': `next/dist/compiled/react-server-dom-${bundler}${reactChannel}/server.node`,
|
|
'react-server-dom-webpack/static$': `next/dist/compiled/react-server-dom-${bundler}${reactChannel}/static.node`,
|
|
'@vercel/turbopack-ecmascript-runtime/browser/dev/hmr-client/hmr-client.ts':
|
|
'next/dist/client/dev/noop-turbopack-hmr',
|
|
}
|
|
}
|
|
|
|
const sharedExternals = [
|
|
'styled-jsx',
|
|
'styled-jsx/style',
|
|
'@opentelemetry/api',
|
|
'next/dist/compiled/@ampproject/toolbox-optimizer',
|
|
'next/dist/compiled/edge-runtime',
|
|
'next/dist/compiled/@edge-runtime/ponyfill',
|
|
'next/dist/compiled/undici',
|
|
'next/dist/compiled/raw-body',
|
|
'next/dist/server/capsize-font-metrics.json',
|
|
'critters',
|
|
'next/dist/compiled/node-html-parser',
|
|
'next/dist/compiled/compression',
|
|
'next/dist/compiled/jsonwebtoken',
|
|
'next/dist/compiled/@opentelemetry/api',
|
|
'next/dist/compiled/@mswjs/interceptors/ClientRequest',
|
|
'next/dist/compiled/ws',
|
|
]
|
|
|
|
const externalsMap = {
|
|
'./web/sandbox': 'next/dist/server/web/sandbox',
|
|
'next/dist/compiled/next-devtools':
|
|
'commonjs next/dist/next-devtools/dev-overlay.shim.js',
|
|
}
|
|
|
|
const externalsRegexMap = {
|
|
'(.*)trace/tracer$': 'next/dist/server/lib/trace/tracer',
|
|
}
|
|
|
|
const bundleTypes = {
|
|
app: {
|
|
'app-page': path.join(
|
|
__dirname,
|
|
'dist/esm/server/route-modules/app-page/module.js'
|
|
),
|
|
'app-route': path.join(
|
|
__dirname,
|
|
'dist/esm/server/route-modules/app-route/module.js'
|
|
),
|
|
},
|
|
pages: {
|
|
pages: path.join(
|
|
__dirname,
|
|
'dist/esm/server/route-modules/pages/module.js'
|
|
),
|
|
'pages-api': path.join(
|
|
__dirname,
|
|
'dist/esm/server/route-modules/pages-api/module.js'
|
|
),
|
|
},
|
|
server: {
|
|
server: path.join(__dirname, 'dist/esm/server/next-server.js'),
|
|
},
|
|
}
|
|
|
|
/**
|
|
* @param {Object} options
|
|
* @param {boolean} options.dev
|
|
* @param {boolean} options.turbo
|
|
* @param {keyof typeof bundleTypes} options.bundleType
|
|
* @param {boolean} options.experimental
|
|
* @param {Partial<webpack.Configuration>} options.rest
|
|
* @returns {webpack.Configuration}
|
|
*/
|
|
module.exports = ({ dev, turbo, bundleType, experimental, ...rest }) => {
|
|
const externalHandler = ({ context, request, getResolve }, callback) => {
|
|
;(async () => {
|
|
if (
|
|
request.match(
|
|
/next[/\\]dist[/\\]compiled[/\\](babel|webpack|source-map|semver|jest-worker|stacktrace-parser|@ampproject\/toolbox-optimizer)/
|
|
)
|
|
) {
|
|
callback(null, 'commonjs ' + request)
|
|
return
|
|
}
|
|
|
|
if (request.match(/(server\/image-optimizer|experimental\/testmode)/)) {
|
|
callback(null, 'commonjs ' + request)
|
|
return
|
|
}
|
|
|
|
if (request.match(/\.external(\.js)?$/)) {
|
|
const resolve = getResolve()
|
|
const resolved = await resolve(context, request)
|
|
const relative = path.relative(
|
|
path.join(__dirname, '..'),
|
|
resolved.replace('esm' + path.sep, '')
|
|
)
|
|
callback(null, `commonjs ${relative}`)
|
|
} else {
|
|
const regexMatch = Object.keys(externalsRegexMap).find((regex) =>
|
|
new RegExp(regex).test(request)
|
|
)
|
|
if (regexMatch) {
|
|
return callback(null, 'commonjs ' + externalsRegexMap[regexMatch])
|
|
}
|
|
callback()
|
|
}
|
|
})()
|
|
}
|
|
|
|
const bundledReactChannel = experimental ? '-experimental' : ''
|
|
|
|
const alias =
|
|
bundleType === 'app'
|
|
? makeAppAliases({
|
|
experimental,
|
|
bundler: turbo ? 'turbopack' : 'webpack',
|
|
})
|
|
: {}
|
|
|
|
return {
|
|
entry: bundleTypes[bundleType],
|
|
target: 'node',
|
|
mode:
|
|
process.env.NEXT_DEBUG_INTERNALS === 'true'
|
|
? 'development'
|
|
: dev
|
|
? 'development'
|
|
: 'production',
|
|
output: {
|
|
path: path.join(__dirname, 'dist/compiled/next-server'),
|
|
filename: `[name]${turbo ? '-turbo' : ''}${
|
|
experimental ? '-experimental' : ''
|
|
}.runtime.${dev ? 'dev' : 'prod'}.js`,
|
|
libraryTarget: 'commonjs2',
|
|
},
|
|
devtool: 'source-map',
|
|
optimization:
|
|
process.env.NEXT_DEBUG_INTERNALS === 'true'
|
|
? undefined
|
|
: {
|
|
moduleIds: 'named',
|
|
minimize: true,
|
|
concatenateModules: true,
|
|
minimizer: [
|
|
new webpack.SwcJsMinimizerRspackPlugin({
|
|
minimizerOptions: {
|
|
mangle:
|
|
dev || process.env.NEXT_SERVER_NO_MANGLE ? false : true,
|
|
},
|
|
}),
|
|
],
|
|
},
|
|
plugins: [
|
|
new DevToolsIgnoreListPlugin({ shouldIgnorePath }),
|
|
new webpack.DefinePlugin({
|
|
'typeof window': JSON.stringify('undefined'),
|
|
'process.env.NEXT_MINIMAL': JSON.stringify('true'),
|
|
'this.serverOptions.experimentalTestProxy': JSON.stringify(false),
|
|
'this.minimalMode': JSON.stringify(true),
|
|
// Only inline __NEXT_DEV_SERVER in prod bundles (for dead-code
|
|
// elimination). Dev bundles must keep it as a runtime check because
|
|
// they're shared between `next dev` (where it's set) and `next build
|
|
// --debug-prerender` (where it's not).
|
|
...(dev ? {} : { 'process.env.__NEXT_DEV_SERVER': JSON.stringify('') }),
|
|
'process.env.NODE_ENV': JSON.stringify(
|
|
dev ? 'development' : 'production'
|
|
),
|
|
'process.env.__NEXT_EXPERIMENTAL_REACT': JSON.stringify(
|
|
experimental ? true : false
|
|
),
|
|
'process.env.NEXT_RUNTIME': JSON.stringify('nodejs'),
|
|
'process.turbopack': JSON.stringify(turbo),
|
|
'process.env.TURBOPACK': JSON.stringify(turbo),
|
|
}),
|
|
!!process.env.ANALYZE &&
|
|
new BundleAnalyzerPlugin({
|
|
analyzerPort: calculateUniquePort(
|
|
dev,
|
|
turbo,
|
|
experimental,
|
|
bundleType
|
|
),
|
|
openAnalyzer: false,
|
|
...(process.env.CI
|
|
? {
|
|
analyzerMode: 'static',
|
|
reportFilename: path.join(
|
|
__dirname,
|
|
`dist/compiled/next-server/report.${dev ? 'dev' : 'prod'}-${
|
|
turbo ? 'turbo' : 'webpack'
|
|
}-${
|
|
experimental ? 'experimental' : 'stable'
|
|
}-${bundleType}.html`
|
|
),
|
|
}
|
|
: {}),
|
|
}),
|
|
].filter(Boolean),
|
|
stats: {
|
|
optimizationBailout: true,
|
|
},
|
|
resolve: {
|
|
alias,
|
|
},
|
|
module: {
|
|
rules: [
|
|
{ test: /\.m?js$/, loader: `source-map-loader`, enforce: `pre` },
|
|
{
|
|
include: /[\\/]react-server\.node/,
|
|
layer: 'react-server',
|
|
},
|
|
{
|
|
include: /vendored[\\/]rsc[\\/]entrypoints/,
|
|
resolve: {
|
|
conditionNames: ['react-server', '...'],
|
|
alias: {
|
|
react$: `next/dist/compiled/react${bundledReactChannel}/react.react-server`,
|
|
[`next/dist/compiled/react${bundledReactChannel}$`]: `next/dist/compiled/react${bundledReactChannel}/react.react-server`,
|
|
'react/jsx-runtime$': `next/dist/compiled/react${bundledReactChannel}/jsx-runtime.react-server`,
|
|
[`next/dist/compiled/react${bundledReactChannel}/jsx-runtime$`]: `next/dist/compiled/react${bundledReactChannel}/jsx-runtime.react-server`,
|
|
'react/jsx-dev-runtime$': `next/dist/compiled/react${bundledReactChannel}/jsx-dev-runtime.react-server`,
|
|
[`next/dist/compiled/react${bundledReactChannel}/jsx-dev-runtime$`]: `next/dist/compiled/react${bundledReactChannel}/jsx-dev-runtime.react-server`,
|
|
'react/compiler-runtime$': `next/dist/compiled/react${bundledReactChannel}/compiler-runtime`,
|
|
[`next/dist/compiled/react${bundledReactChannel}/compiler-runtime$`]: `next/dist/compiled/react${bundledReactChannel}/compiler-runtime`,
|
|
'react-dom$': `next/dist/compiled/react-dom${bundledReactChannel}/react-dom.react-server`,
|
|
[`next/dist/compiled/react-dom${bundledReactChannel}$`]: `next/dist/compiled/react-dom${bundledReactChannel}/react-dom.react-server`,
|
|
},
|
|
},
|
|
layer: 'react-server',
|
|
},
|
|
{
|
|
issuerLayer: 'react-server',
|
|
resolve: {
|
|
conditionNames: ['react-server', '...'],
|
|
alias: {
|
|
react$: `next/dist/compiled/react${bundledReactChannel}/react.react-server`,
|
|
[`next/dist/compiled/react${bundledReactChannel}$`]: `next/dist/compiled/react${bundledReactChannel}/react.react-server`,
|
|
'react-dom$': `next/dist/compiled/react-dom${bundledReactChannel}/react-dom.react-server`,
|
|
[`next/dist/compiled/react-dom${bundledReactChannel}$`]: `next/dist/compiled/react-dom${bundledReactChannel}/react-dom.react-server`,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
externals: [
|
|
...sharedExternals,
|
|
...(bundleType === 'pages' ? pagesExternals : appExternals),
|
|
externalsMap,
|
|
externalHandler,
|
|
],
|
|
...rest,
|
|
}
|
|
}
|
|
|
|
function calculateUniquePort(dev, turbo, experimental, bundleType) {
|
|
const devOffset = dev ? 1000 : 0
|
|
const turboOffset = turbo ? 200 : 0
|
|
const experimentalOffset = experimental ? 40 : 0
|
|
let bundleTypeOffset
|
|
|
|
switch (bundleType) {
|
|
case 'app':
|
|
bundleTypeOffset = 1
|
|
break
|
|
case 'pages':
|
|
bundleTypeOffset = 2
|
|
break
|
|
default:
|
|
bundleTypeOffset = 3
|
|
}
|
|
|
|
return 8888 + devOffset + turboOffset + experimentalOffset + bundleTypeOffset
|
|
}
|