Commit 7e1d54cc authored by Lukáš Huvar's avatar Lukáš Huvar Committed by Joe Haddad

Add warning for disabled minification during build (#8337)

* Add warning for disabled minification

* Adding err.sh

* Apply suggestions from code review
Co-Authored-By: 's avatarJoe Haddad <timer150@gmail.com>

* Remove example

* Update packages/next/build/index.ts
Co-Authored-By: 's avatarJoe Haddad <timer150@gmail.com>

* Update index.test.js
parent 3b31f957
# Minification Disabled in Production
#### Why This Error Occurred
Code optimization has been disabled for your **production build**.
The `optimization.minimize` or `optimization.minimizer` was incorrectly overridden in `next.config.js`.
This severely degrades your application's performance at runtime. It can also result in server-side-only code being downloaded by your users.
#### Possible Ways to Fix It
Be sure your `next.config.js` has not modified `optimization.minimize` or `optimization.minimizer`.
You can file an issue on our GitHub if you do not understand why minification is being disabled by your `next.config.js`.
...@@ -208,10 +208,26 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -208,10 +208,26 @@ export default async function build(dir: string, conf = null): Promise<void> {
}), }),
]) ])
const clientConfig = configs[0]
if (
clientConfig.optimization &&
(clientConfig.optimization.minimize !== true ||
(clientConfig.optimization.minimizer &&
clientConfig.optimization.minimizer.length === 0))
) {
console.warn(
chalk.bold.yellow(`Warning: `) +
chalk.bold(
`Production code optimization has been disabled in your project. Read more: https://err.sh/zeit/next.js/minification-disabled`
)
)
}
let result: CompilerResult = { warnings: [], errors: [] } let result: CompilerResult = { warnings: [], errors: [] }
// TODO: why do we need this?? https://github.com/zeit/next.js/issues/8253 // TODO: why do we need this?? https://github.com/zeit/next.js/issues/8253
if (isLikeServerless) { if (isLikeServerless) {
const clientResult = await runCompiler(configs[0]) const clientResult = await runCompiler(clientConfig)
// Fail build if clientResult contains errors // Fail build if clientResult contains errors
if (clientResult.errors.length > 0) { if (clientResult.errors.length > 0) {
result = { result = {
......
module.exports = {
webpack: config => {
config.optimization.minimize = true
return config
}
}
export default () => <div>Build</div>
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import { nextBuild, File, waitFor } from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
const appDir = join(__dirname, '../')
describe('Build warnings', () => {
it('should not shown warning about minification withou any modification', async () => {
const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
expect(stderr).not.toContain('optimization has been disabled')
})
it('should shown warning about minification for minimize', async () => {
const nextConfig = new File(join(appDir, 'next.config.js'))
await waitFor(500)
nextConfig.replace('true', 'false')
const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
expect(stderr).toContain('optimization has been disabled')
nextConfig.restore()
})
it('should shown warning about minification for minimizer', async () => {
const nextConfig = new File(join(appDir, 'next.config.js'))
await waitFor(500)
nextConfig.replace(
'config.optimization.minimize = true',
'config.optimization.minimizer = []'
)
const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
expect(stderr).toContain('optimization has been disabled')
nextConfig.restore()
})
})
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