Unverified Commit c64cb60a authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Fail production build quickly (#13496)

By default, webpack will proceed to run loaders and plugins on all files, even after an error has been encountered during the build process.

This means you might need to wait minutes to see a syntax error encountered in one of your source files. This PR fixes that.
parent 6b65efb6
...@@ -26,6 +26,10 @@ export function runCompiler( ...@@ -26,6 +26,10 @@ export function runCompiler(
compiler.run( compiler.run(
(err: Error, statsOrMultiStats: { stats: Stats[] } | Stats) => { (err: Error, statsOrMultiStats: { stats: Stats[] } | Stats) => {
if (err) { if (err) {
const reason = err?.toString()
if (reason) {
return resolve({ errors: [reason], warnings: [] })
}
return reject(err) return reject(err)
} }
......
...@@ -10,6 +10,11 @@ export const base = curry(function base( ...@@ -10,6 +10,11 @@ export const base = curry(function base(
config.name = ctx.isServer ? 'server' : 'client' config.name = ctx.isServer ? 'server' : 'client'
config.target = ctx.isServer ? 'node' : 'web' config.target = ctx.isServer ? 'node' : 'web'
// Stop compilation early in a production build when an error is encountered.
// This behavior isn't desirable in development due to how the HMR system
// works, but is a good default for production.
config.bail = ctx.isProduction
// https://webpack.js.org/configuration/devtool/#development // https://webpack.js.org/configuration/devtool/#development
if (ctx.isDevelopment) { if (ctx.isDevelopment) {
if (process.platform === 'win32') { if (process.platform === 'win32') {
......
...@@ -19,7 +19,16 @@ module.exports = withCSS( ...@@ -19,7 +19,16 @@ module.exports = withCSS(
env: { env: {
customVar: 'hello', customVar: 'hello',
}, },
webpack(config, { buildId, webpack }) { webpack(config, { dev, buildId, webpack }) {
if (dev) {
if (config.bail !== false) {
throw new Error('Wrong bail value for development!')
}
} else {
if (config.bail !== true) {
throw new Error('Wrong bail value for production!')
}
}
// When next-css is `npm link`ed we have to solve loaders from the project root // When next-css is `npm link`ed we have to solve loaders from the project root
const nextLocation = path.join( const nextLocation = path.join(
require.resolve('next/package.json'), require.resolve('next/package.json'),
......
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