Skip to content

Commit

Permalink
Merge branch 'canary' into documentation-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Aug 24, 2020
2 parents 37203fa + c97e53e commit a6b90e6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
5 changes: 3 additions & 2 deletions examples/with-sentry/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const COMMIT_SHA =
VERCEL_BITBUCKET_COMMIT_SHA

process.env.SENTRY_DSN = SENTRY_DSN
const basePath = ''

module.exports = withSourceMaps({
serverRuntimeConfig: {
Expand Down Expand Up @@ -63,12 +64,12 @@ module.exports = withSourceMaps({
include: '.next',
ignore: ['node_modules'],
stripPrefix: ['webpack://_N_E/'],
urlPrefix: '~/_next',
urlPrefix: `~${basePath}/_next`,
release: COMMIT_SHA,
})
)
}

return config
},
basePath,
})
60 changes: 59 additions & 1 deletion packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1121,10 +1121,68 @@ export default async function getBaseWebpackConfig(

// Enable webpack 5 caching
if (config.experimental.unstable_webpack5cache) {
webpackConfig.cache = {
const nextPublicVariables = Object.keys(process.env).reduce(
(prev: string, key: string) => {
if (key.startsWith('NEXT_PUBLIC_')) {
return `${prev}|${key}=${process.env[key]}`
}
return prev
},
''
)
const nextEnvVariables = Object.keys(config.env).reduce(
(prev: string, key: string) => {
return `${prev}|${key}=${config.env[key]}`
},
''
)

const configVars = JSON.stringify({
crossOrigin: config.crossOrigin,
pageExtensions: config.pageExtensions,
trailingSlash: config.trailingSlash,
modern: config.experimental.modern,
buildActivity: config.devIndicators.buildActivity,
autoPrerender: config.devIndicators.autoPrerender,
plugins: config.experimental.plugins,
reactStrictMode: config.reactStrictMode,
reactMode: config.experimental.reactMode,
optimizeFonts: config.experimental.optimizeFonts,
optimizeImages: config.experimental.optimizeImages,
scrollRestoration: config.experimental.scrollRestoration,
basePath: config.basePath,
pageEnv: config.experimental.pageEnv,
excludeDefaultMomentLocales: config.future.excludeDefaultMomentLocales,
assetPrefix: config.assetPrefix,
target,
reactProductionProfiling,
})

const cache: any = {
type: 'filesystem',
// Includes:
// - Next.js version
// - NEXT_PUBLIC_ variable values (they affect caching) TODO: make this module usage only
// - next.config.js `env` key
// - next.config.js keys that affect compilation
version: `${process.env.__NEXT_VERSION}|${nextPublicVariables}|${nextEnvVariables}|${configVars}`,
buildDependencies: {
config: [],
},
cacheDirectory: path.join(dir, '.next', 'cache', 'webpack'),
}

// Adds `next.config.js` as a buildDependency when custom webpack config is provided
if (config.webpack && config.configFile) {
cache.buildDependencies = {
config: [config.configFile],
}
}

webpackConfig.cache = cache

// @ts-ignore TODO: remove ignore when webpack 5 is stable
webpackConfig.optimization.realContentHash = false
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/next/next-server/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ export default function loadConfig(
)
}

return assignDefaults({ configOrigin: CONFIG_FILE, ...userConfig })
return assignDefaults({
configOrigin: CONFIG_FILE,
configFile: path,
...userConfig,
})
} else {
const configBaseName = basename(CONFIG_FILE, extname(CONFIG_FILE))
const nonJsPath = findUp.sync(
Expand Down

0 comments on commit a6b90e6

Please sign in to comment.