mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Add dynamic-import support for next-export.
This commit is contained in:
parent
4d0147385c
commit
aeaccf441b
|
@ -44,6 +44,17 @@ export default async function (dir, options) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy dynamic import chunks
|
||||||
|
if (existsSync(join(nextDir, 'chunks'))) {
|
||||||
|
log(' copying dynamic import chunks')
|
||||||
|
|
||||||
|
await mkdirp(join(outDir, '_next', 'webpack'))
|
||||||
|
await cp(
|
||||||
|
join(nextDir, 'chunks'),
|
||||||
|
join(outDir, '_next', 'webpack', 'chunks')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
await copyPages(nextDir, outDir, buildId)
|
await copyPages(nextDir, outDir, buildId)
|
||||||
|
|
||||||
// Get the exportPathMap from the `next.config.js`
|
// Get the exportPathMap from the `next.config.js`
|
||||||
|
|
5
test/integration/static/components/hello.js
Normal file
5
test/integration/static/components/hello.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
export default () => (
|
||||||
|
<p>
|
||||||
|
Welcome to dynamic imports.
|
||||||
|
</p>
|
||||||
|
)
|
|
@ -4,6 +4,7 @@ module.exports = {
|
||||||
'/': { page: '/' },
|
'/': { page: '/' },
|
||||||
'/about': { page: '/about' },
|
'/about': { page: '/about' },
|
||||||
'/counter': { page: '/counter' },
|
'/counter': { page: '/counter' },
|
||||||
|
'/dynamic-imports': { page: '/dynamic-imports' },
|
||||||
'/dynamic': { page: '/dynamic', query: { text: 'cool dynamic text' } },
|
'/dynamic': { page: '/dynamic', query: { text: 'cool dynamic text' } },
|
||||||
'/dynamic/one': { page: '/dynamic', query: { text: 'next export is nice' } },
|
'/dynamic/one': { page: '/dynamic', query: { text: 'next export is nice' } },
|
||||||
'/dynamic/two': { page: '/dynamic', query: { text: 'zeit is awesome' } }
|
'/dynamic/two': { page: '/dynamic', query: { text: 'zeit is awesome' } }
|
||||||
|
|
15
test/integration/static/pages/dynamic-imports.js
Normal file
15
test/integration/static/pages/dynamic-imports.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import Link from 'next/link'
|
||||||
|
import dynamic from 'next/dynamic'
|
||||||
|
|
||||||
|
const DynamicComponent = dynamic(import('../components/hello'))
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div id='dynamic-imports-page'>
|
||||||
|
<div>
|
||||||
|
<Link href='/'>
|
||||||
|
<a>Go Back</a>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<DynamicComponent />
|
||||||
|
</div>
|
||||||
|
)
|
|
@ -45,6 +45,9 @@ export default () => (
|
||||||
<Link href='/level1/about'>
|
<Link href='/level1/about'>
|
||||||
<a id='level1-about-page'>Level1 about page</a>
|
<a id='level1-about-page'>Level1 about page</a>
|
||||||
</Link>
|
</Link>
|
||||||
|
<Link href='/dynamic-imports'>
|
||||||
|
<a id='dynamic-imports-page'>Dynamic imports page</a>
|
||||||
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<p>This is the home page</p>
|
<p>This is the home page</p>
|
||||||
<style jsx>{`
|
<style jsx>{`
|
||||||
|
|
|
@ -93,6 +93,17 @@ export default function (context) {
|
||||||
browser.close()
|
browser.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should render dynamic import components in the client', async () => {
|
||||||
|
const browser = await webdriver(context.port, '/')
|
||||||
|
const text = await browser
|
||||||
|
.elementByCss('#dynamic-imports-page').click()
|
||||||
|
.waitForElementByCss('#dynamic-imports-page')
|
||||||
|
.elementByCss('#dynamic-imports-page p').text()
|
||||||
|
|
||||||
|
expect(text).toBe('Welcome to dynamic imports.')
|
||||||
|
browser.close()
|
||||||
|
})
|
||||||
|
|
||||||
describe('pages in the nested level: level1', () => {
|
describe('pages in the nested level: level1', () => {
|
||||||
it('should render the home page', async () => {
|
it('should render the home page', async () => {
|
||||||
const browser = await webdriver(context.port, '/')
|
const browser = await webdriver(context.port, '/')
|
||||||
|
|
|
@ -17,5 +17,10 @@ export default function (context) {
|
||||||
const html = await renderViaHTTP(context.port, '/dynamic/one')
|
const html = await renderViaHTTP(context.port, '/dynamic/one')
|
||||||
expect(html).toMatch(/next export is nice/)
|
expect(html).toMatch(/next export is nice/)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should render pages with dynamic imports', async() => {
|
||||||
|
const html = await renderViaHTTP(context.port, '/dynamic-imports')
|
||||||
|
expect(html).toMatch(/Welcome to dynamic imports./)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue