Unverified Commit 0fbc9d23 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add experimental webpack 5 cache option (#16307)

Don't use this yet as it's still being developed. This is a first iteration that enables the webpack cache. There's still more to do here, for example if css modules are used there's currently a bug where webpack does not save the cache for browser compilation (impacting build performance). @sokra is going to look into that issue.
parent 24f056c9
...@@ -237,7 +237,8 @@ export default async function getBaseWebpackConfig( ...@@ -237,7 +237,8 @@ export default async function getBaseWebpackConfig(
distDir, distDir,
pagesDir, pagesDir,
cwd: dir, cwd: dir,
cache: true, // Webpack 5 has a built-in loader cache
cache: !config.experimental.unstable_webpack5cache,
babelPresetPlugins, babelPresetPlugins,
hasModern: !!config.experimental.modern, hasModern: !!config.experimental.modern,
development: dev, development: dev,
...@@ -1117,6 +1118,14 @@ export default async function getBaseWebpackConfig( ...@@ -1117,6 +1118,14 @@ export default async function getBaseWebpackConfig(
} }
webpackConfig.optimization.usedExports = false webpackConfig.optimization.usedExports = false
} }
// Enable webpack 5 caching
if (config.experimental.unstable_webpack5cache) {
webpackConfig.cache = {
type: 'filesystem',
cacheDirectory: path.join(dir, '.next', 'cache', 'webpack'),
}
}
} }
webpackConfig = await buildConfiguration(webpackConfig, { webpackConfig = await buildConfiguration(webpackConfig, {
......
...@@ -54,6 +54,7 @@ const defaultConfig: { [key: string]: any } = { ...@@ -54,6 +54,7 @@ const defaultConfig: { [key: string]: any } = {
optimizeFonts: false, optimizeFonts: false,
optimizeImages: false, optimizeImages: false,
scrollRestoration: false, scrollRestoration: false,
unstable_webpack5cache: false,
}, },
future: { future: {
excludeDefaultMomentLocales: false, excludeDefaultMomentLocales: false,
......
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