1
0
Fork 0
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:
Arunoda Susiripala 2017-05-15 10:03:35 +05:30
parent 4d0147385c
commit aeaccf441b
7 changed files with 51 additions and 0 deletions

View file

@ -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)
// Get the exportPathMap from the `next.config.js`

View file

@ -0,0 +1,5 @@
export default () => (
<p>
Welcome to dynamic imports.
</p>
)

View file

@ -4,6 +4,7 @@ module.exports = {
'/': { page: '/' },
'/about': { page: '/about' },
'/counter': { page: '/counter' },
'/dynamic-imports': { page: '/dynamic-imports' },
'/dynamic': { page: '/dynamic', query: { text: 'cool dynamic text' } },
'/dynamic/one': { page: '/dynamic', query: { text: 'next export is nice' } },
'/dynamic/two': { page: '/dynamic', query: { text: 'zeit is awesome' } }

View 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>
)

View file

@ -45,6 +45,9 @@ export default () => (
<Link href='/level1/about'>
<a id='level1-about-page'>Level1 about page</a>
</Link>
<Link href='/dynamic-imports'>
<a id='dynamic-imports-page'>Dynamic imports page</a>
</Link>
</div>
<p>This is the home page</p>
<style jsx>{`

View file

@ -93,6 +93,17 @@ export default function (context) {
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', () => {
it('should render the home page', async () => {
const browser = await webdriver(context.port, '/')

View file

@ -17,5 +17,10 @@ export default function (context) {
const html = await renderViaHTTP(context.port, '/dynamic/one')
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./)
})
})
}