Skip to content

Commit

Permalink
Keep chunks filenames in production mode (#5029)
Browse files Browse the repository at this point in the history
* Keep chunks filenames in production mode

* Add test for new `[name]` behavior

* Rename static/dll to static/development/dll
  • Loading branch information
tusbar authored and timneutkens committed Sep 2, 2018
1 parent 3d95642 commit 2eeebac
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions build/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, i
hotUpdateChunkFilename: 'static/webpack/[id].[hash].hot-update.js',
hotUpdateMainFilename: 'static/webpack/[hash].hot-update.json',
// This saves chunks with the name given via `import()`
chunkFilename: isServer ? `${dev ? '[name]' : '[contenthash]'}.js` : `static/chunks/${dev ? '[name]' : '[contenthash]'}.js`,
chunkFilename: isServer ? `${dev ? '[name]' : '[name].[contenthash]'}.js` : `static/chunks/${dev ? '[name]' : '[name].[contenthash]'}.js`,
strictModuleExceptionHandling: true
},
performance: { hints: false },
Expand Down Expand Up @@ -213,7 +213,7 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, i
// Precompile react / react-dom for development, speeding up webpack
dev && !isServer && new AutoDllPlugin({
filename: '[name]_[hash].js',
path: './static/dll',
path: './static/development/dll',
context: dir,
entry: {
dll: [
Expand Down
2 changes: 1 addition & 1 deletion build/webpack/plugins/build-manifest-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class BuildManifestPlugin {

for (const filePath of Object.keys(compilation.assets)) {
const path = filePath.replace(/\\/g, '/')
if (/^static\/dll\//.test(path)) {
if (/^static\/development\/dll\//.test(path)) {
assetMap.devFiles.push(path)
}
}
Expand Down
1 change: 1 addition & 0 deletions test/integration/basic/components/hello-chunkfilename.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => <div>test chunkfilename</div>
5 changes: 5 additions & 0 deletions test/integration/basic/pages/dynamic/chunkfilename.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import dynamic from 'next/dynamic'

const Hello = dynamic(import(/* webpackChunkName: 'hello-world' */'../../components/hello-chunkfilename'))

export default Hello
20 changes: 20 additions & 0 deletions test/integration/basic/test/dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ export default (context, render) => {
})
})

describe('custom chunkfilename', () => {
it('should render the correct filename', async () => {
const $ = await get$('/dynamic/chunkfilename')
expect($('body').text()).toMatch(/test chunkfilename/)
expect($('html').html()).toMatch(/hello-world\.js/)
})

it('should render the component on client side', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/dynamic/chunkfilename')
await check(() => browser.elementByCss('body').text(), /test chunkfilename/)
} finally {
if (browser) {
browser.close()
}
}
})
})

describe('custom loading', () => {
it('should render custom loading on the server side when `ssr:false` and `loading` is provided', async () => {
const $ = await get$('/dynamic/no-ssr-custom-loading')
Expand Down

0 comments on commit 2eeebac

Please sign in to comment.