1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Keep chunks filenames in production mode (#5029)

* Keep chunks filenames in production mode

* Add test for new `[name]` behavior

* Rename static/dll to static/development/dll
This commit is contained in:
Bertrand Marron 2018-09-03 01:40:21 +02:00 committed by Tim Neutkens
parent 3d9564215c
commit 2eeebacb4c
5 changed files with 29 additions and 3 deletions

View file

@ -181,7 +181,7 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, i
hotUpdateChunkFilename: 'static/webpack/[id].[hash].hot-update.js', hotUpdateChunkFilename: 'static/webpack/[id].[hash].hot-update.js',
hotUpdateMainFilename: 'static/webpack/[hash].hot-update.json', hotUpdateMainFilename: 'static/webpack/[hash].hot-update.json',
// This saves chunks with the name given via `import()` // 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 strictModuleExceptionHandling: true
}, },
performance: { hints: false }, performance: { hints: false },
@ -213,7 +213,7 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, i
// Precompile react / react-dom for development, speeding up webpack // Precompile react / react-dom for development, speeding up webpack
dev && !isServer && new AutoDllPlugin({ dev && !isServer && new AutoDllPlugin({
filename: '[name]_[hash].js', filename: '[name]_[hash].js',
path: './static/dll', path: './static/development/dll',
context: dir, context: dir,
entry: { entry: {
dll: [ dll: [

View file

@ -15,7 +15,7 @@ export default class BuildManifestPlugin {
for (const filePath of Object.keys(compilation.assets)) { for (const filePath of Object.keys(compilation.assets)) {
const path = filePath.replace(/\\/g, '/') const path = filePath.replace(/\\/g, '/')
if (/^static\/dll\//.test(path)) { if (/^static\/development\/dll\//.test(path)) {
assetMap.devFiles.push(path) assetMap.devFiles.push(path)
} }
} }

View file

@ -0,0 +1 @@
export default () => <div>test chunkfilename</div>

View file

@ -0,0 +1,5 @@
import dynamic from 'next/dynamic'
const Hello = dynamic(import(/* webpackChunkName: 'hello-world' */'../../components/hello-chunkfilename'))
export default Hello

View file

@ -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', () => { describe('custom loading', () => {
it('should render custom loading on the server side when `ssr:false` and `loading` is provided', async () => { 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') const $ = await get$('/dynamic/no-ssr-custom-loading')