mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
fa7e1a6c38
Currently we skip a persist cycle when there are no dirty tasks. This PR extends that to skip persist cycles when little compilation work has happened since the last snapshot, avoiding small writes and expensive compaction for little benefit. Compilation time is a better proxy for "how much work a snapshot would save" than a raw dirty-task count. The background snapshot loop accumulates active (non-idle) wall-clock time and skips a cycle when less than a threshold has elapsed since the last persisted snapshot. Default is 1s, overridable via `TURBO_ENGINE_SNAPSHOT_MIN_ACTIVE_TIME_MILLIS` (set to `0` in tests). Shutdown and test snapshots bypass the gate. The active-time bookkeeping is encapsulated in a small `Stopwatch` helper. <!-- NEXT_JS_LLM_PR -->
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
const enableCaching = !!process.env.ENABLE_CACHING
|
|
const enableEviction = !!process.env.ENABLE_EVICTION
|
|
|
|
/**
|
|
* @type {import('next').NextConfig}
|
|
*/
|
|
const nextConfig = {
|
|
turbopack: {
|
|
rules: {
|
|
'./app/**/page.{jsx,tsx}': {
|
|
loaders: ['./my-timestamp-loader.js'],
|
|
},
|
|
'./app/loader/page.tsx': {
|
|
loaders: ['./my-loader.js'],
|
|
},
|
|
'./pages/pages.tsx': {
|
|
loaders: ['./my-timestamp-loader.js'],
|
|
},
|
|
},
|
|
},
|
|
experimental: {
|
|
turbopackFileSystemCacheForBuild: enableCaching,
|
|
turbopackFileSystemCacheForDev: enableCaching,
|
|
turbopackMemoryEviction: enableEviction ? 'full' : false,
|
|
},
|
|
env: {
|
|
NEXT_PUBLIC_CONFIG_ENV: 'hello world',
|
|
},
|
|
webpack(config, { dev }) {
|
|
config.module.rules.push({
|
|
test: /app(?:\/.*)?\/page\.[tj]sx|pages\/pages\.tsx/,
|
|
use: ['./my-timestamp-loader.js'],
|
|
})
|
|
config.module.rules.push({
|
|
test: /app\/loader(?:\/client)?\/page\.tsx/,
|
|
use: ['./my-loader.js'],
|
|
})
|
|
if (enableCaching) {
|
|
config.cache = Object.freeze({
|
|
type: 'memory',
|
|
})
|
|
}
|
|
if (dev) {
|
|
// Make webpack consider the build as large change which makes it filesystem cache it sooner
|
|
config.plugins.push((compiler) => {
|
|
compiler.__extra_delay = true
|
|
})
|
|
}
|
|
|
|
return config
|
|
},
|
|
}
|
|
|
|
module.exports = nextConfig
|