Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Nov 2, 2021
1 parent d13d1df commit 34258bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ export default async function getBaseWebpackConfig(
productionBrowserSourceMaps: config.productionBrowserSourceMaps,
future: config.future,
experimental: config.experimental,
disableStaticImages: config.disableStaticImages,
disableStaticImages: config.images.disableStaticImages,
})

// @ts-ignore Cache exists
Expand Down
5 changes: 3 additions & 2 deletions packages/next/build/webpack/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ export async function build(
experimental,
}

let fn = pipe(base(ctx), css(ctx))
let fns = [base(ctx), css(ctx)]
if (!disableStaticImages) {
fn = pipe(fn, images(ctx))
fns.push(images(ctx))
}
const fn = pipe(...fns)
return fn(config)
}
14 changes: 11 additions & 3 deletions test/integration/invalid-document-image-import/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ describe('Invalid static image import in _document', () => {
expect(stderr).toMatch(/Location:.*pages[\\/]_document\.js/)
})

it('Should build without error when disableStaticImages in next.config.js', async () => {
it('Should fail to build when disableStaticImages in next.config.js', async () => {
nextConfig.write(`
module.exports = {
images: {
disableStaticImages: true
}
}
`)
const { code } = await nextBuild(appDir, [], {})
expect(code).toBe(0)
const { code, stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toMatch(
/You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file/
)
expect(stderr).not.toMatch(
/Images.*cannot.*be imported within.*pages[\\/]_document\.js/
)
})
})

0 comments on commit 34258bb

Please sign in to comment.