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

Enable esmExternals by default (#29878)



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes
parent d1d7a951
...@@ -218,7 +218,7 @@ export const defaultConfig: NextConfig = { ...@@ -218,7 +218,7 @@ export const defaultConfig: NextConfig = {
disableOptimizedLoading: false, disableOptimizedLoading: false,
gzipSize: true, gzipSize: true,
craCompat: false, craCompat: false,
esmExternals: false, esmExternals: true,
staticPageGenerationTimeout: 60, staticPageGenerationTimeout: 60,
// default to 50MB limit // default to 50MB limit
isrMemoryCacheSize: 50 * 1024 * 1024, isrMemoryCacheSize: 50 * 1024 * 1024,
......
module.exports = {
webpack(config) {
config.resolve.alias = {
...config.resolve.alias,
'preact/compat': 'react',
}
return config
},
}
{
"name": "esm-package",
"exports": {
"./entry": {
"import": "./wrong.mjs",
"require": "./correct.js"
}
}
}
if(typeof window === "undefined")
throw new Error("This shouldn't be used on server-side")
export default "World";
{
"name": "module-package",
"exports": {
".": {
"module": "./wrong.mjs",
"import": "./wrong.mjs",
"require": "./correct.js"
}
}
}
if(typeof window === "undefined")
throw new Error("This shouldn't be used on server-side")
export default "World";
import React from 'preact/compat'
import World1 from 'esm-package/entry'
import World2 from 'module-package'
export async function getStaticProps() {
return {
props: {},
}
}
export default function Index(props) {
return (
<div>
Hello {World1}+{World2}
</div>
)
}
import React from 'preact/compat'
import World1 from 'esm-package/entry'
import World2 from 'module-package'
export function getServerSideProps() {
return {}
}
export default function Index(props) {
return (
<div>
Hello {World1}+{World2}
</div>
)
}
import React from 'preact/compat'
import World1 from 'esm-package/entry'
import World2 from 'module-package'
export default function Index(props) {
return (
<div>
Hello {World1}+{World2}
</div>
)
}
/* eslint-env jest */
import fs from 'fs-extra'
import { join } from 'path'
import {
nextBuild,
findPort,
nextStart,
killApp,
renderViaHTTP,
} from 'next-test-utils'
const appDir = join(__dirname, '../')
let appPort
let app
describe('Handle ESM externals', () => {
beforeAll(async () => {
await fs.remove(join(appDir, '.next'))
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
const expected = /Hello <!-- -->World<!-- -->\+<!-- -->World/
it('should render the static page', async () => {
const html = await renderViaHTTP(appPort, '/static')
expect(html).toMatch(expected)
})
it('should render the ssr page', async () => {
const html = await renderViaHTTP(appPort, '/ssr')
expect(html).toMatch(expected)
})
it('should render the ssg page', async () => {
const html = await renderViaHTTP(appPort, '/ssg')
expect(html).toMatch(expected)
})
})
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