Unverified Commit aa62fa7f authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add test for main.js in webpack.config.js (#15311)

This particular variable was not being read correctly. Added a test for the behavior.

Fixes #15261
parent 548ca820
...@@ -1278,7 +1278,10 @@ export default async function getBaseWebpackConfig( ...@@ -1278,7 +1278,10 @@ export default async function getBaseWebpackConfig(
const originalFile = clientEntries[ const originalFile = clientEntries[
CLIENT_STATIC_FILES_RUNTIME_MAIN CLIENT_STATIC_FILES_RUNTIME_MAIN
] as string ] as string
entry[CLIENT_STATIC_FILES_RUNTIME_MAIN] = [...['main.js'], originalFile] entry[CLIENT_STATIC_FILES_RUNTIME_MAIN] = [
...entry['main.js'],
originalFile,
]
} }
delete entry['main.js'] delete entry['main.js']
......
/* eslint no-extend-native: 0 */
// This file runs before React and Next.js core
// This file is loaded for all browsers
// Next.js includes a number of polyfills only for older browsers like IE11
// Make sure you don't duplicate these in this file
// https://github.com/vercel/next.js/blob/canary/packages/next-polyfill-nomodule/src/index.js
console.log('Load your polyfills')
module.exports = {
webpack: function (cfg) {
const originalEntry = cfg.entry
cfg.entry = async () => {
const entries = await originalEntry()
if (
entries['main.js'] &&
!entries['main.js'].includes('./client/polyfills.js')
) {
entries['main.js'].unshift('./client/polyfills.js')
}
return entries
}
return cfg
},
}
export default function StaticPage() {
return <>Hello World</>
}
/* eslint-env jest */
import { join } from 'path'
import { nextBuild } from 'next-test-utils'
jest.setTimeout(1000 * 60 * 2)
const appDir = join(__dirname, '../')
describe('Customized webpack config with main.js', () => {
it('should run correctly with main.js customized', async () => {
const { code } = await nextBuild(appDir, [], {})
expect(code).toBe(0)
})
})
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