Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't emit duplicate image files #26843

Merged
merged 3 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,9 @@ export default async function getBaseWebpackConfig(
loader: 'next-image-loader',
issuer: { not: regexLikeCss },
dependency: { not: ['url'] },
options: {
isServer,
},
},
]
: []),
Expand Down
5 changes: 4 additions & 1 deletion packages/next/build/webpack/loaders/next-image-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const BLUR_QUALITY = 70
const VALID_BLUR_EXT = ['jpeg', 'png', 'webp']

async function nextImageLoader(content) {
const isServer = loaderUtils.getOptions(this).isServer
const context = this.rootContext
const opts = { context, content }
const interpolatedName = loaderUtils.interpolateName(
Expand Down Expand Up @@ -46,7 +47,9 @@ async function nextImageLoader(content) {
blurDataURL,
})

this.emitFile(interpolatedName, content, null)
if (!isServer) {
this.emitFile(interpolatedName, content, null)
}

return `${'export default '} ${stringifiedData};`
}
Expand Down
8 changes: 8 additions & 0 deletions test/integration/image-component/default/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
import { existsSync } from 'fs'

jest.setTimeout(1000 * 80)

Expand Down Expand Up @@ -555,6 +556,13 @@ function runTests(mode) {
/Image with src (.*)jpg(.*) is smaller than 40x40. Consider removing(.*)/gm
)
})
} else {
//server-only tests
it('should not create an image folder in server/chunks', async () => {
expect(
existsSync(join(appDir, '.next/server/chunks/static/image'))
).toBeFalsy()
})
}

it('should correctly ignore prose styles', async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/image-component/default/test/static.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let app
let browser
let html

const indexPage = new File(join(appDir, 'pages/static.js'))
const indexPage = new File(join(appDir, 'pages/static-img.js'))

const runTests = () => {
it('Should allow an image with a static src to omit height and width', async () => {
Expand Down Expand Up @@ -97,8 +97,8 @@ describe('Static Image Component Tests', () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
html = await renderViaHTTP(appPort, '/static')
browser = await webdriver(appPort, '/static')
html = await renderViaHTTP(appPort, '/static-img')
browser = await webdriver(appPort, '/static-img')
})
afterAll(() => {
killApp(app)
Expand Down