mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Add module
as server fallback main field (#6256)
* Add `module` as server fallback main field * Test that a module only package can be imported
This commit is contained in:
parent
23c9c0d624
commit
33b9ebc783
|
@ -189,7 +189,7 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer
|
||||||
[PAGES_DIR_ALIAS]: path.join(dir, 'pages'),
|
[PAGES_DIR_ALIAS]: path.join(dir, 'pages'),
|
||||||
[DOT_NEXT_ALIAS]: distDir
|
[DOT_NEXT_ALIAS]: distDir
|
||||||
},
|
},
|
||||||
mainFields: isServer ? ['main'] : ['browser', 'module', 'main']
|
mainFields: isServer ? ['main', 'module'] : ['browser', 'module', 'main']
|
||||||
}
|
}
|
||||||
|
|
||||||
const webpackMode = dev ? 'development' : 'production'
|
const webpackMode = dev ? 'development' : 'production'
|
||||||
|
|
1
test/integration/config/node_modules/module-only-package/index.js
generated
vendored
Normal file
1
test/integration/config/node_modules/module-only-package/index.js
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
module.exports = "I am sometimes found by tooling. I shouldn't be."
|
1
test/integration/config/node_modules/module-only-package/modern.js
generated
vendored
Normal file
1
test/integration/config/node_modules/module-only-package/modern.js
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export default 'OK'
|
5
test/integration/config/node_modules/module-only-package/package.json
generated
vendored
Normal file
5
test/integration/config/node_modules/module-only-package/package.json
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"name": "module-only-package",
|
||||||
|
"description": "I'm a hipster package that only ships a module entrypoint.",
|
||||||
|
"module": "./modern.js"
|
||||||
|
}
|
3
test/integration/config/pages/module-only-content.js
Normal file
3
test/integration/config/pages/module-only-content.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import messageInAPackage from 'module-only-package'
|
||||||
|
|
||||||
|
export default () => <p id='messageInAPackage'>{messageInAPackage}</p>
|
|
@ -35,7 +35,8 @@ describe('Configuration', () => {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
renderViaHTTP(context.appPort, '/next-config'),
|
renderViaHTTP(context.appPort, '/next-config'),
|
||||||
renderViaHTTP(context.appPort, '/build-id'),
|
renderViaHTTP(context.appPort, '/build-id'),
|
||||||
renderViaHTTP(context.appPort, '/webpack-css')
|
renderViaHTTP(context.appPort, '/webpack-css'),
|
||||||
|
renderViaHTTP(context.appPort, '/module-only-component')
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
|
|
|
@ -33,5 +33,10 @@ export default function ({ app }, suiteName, render, fetch) {
|
||||||
const $ = await get$('/build-id')
|
const $ = await get$('/build-id')
|
||||||
expect($('#buildId').text() === '-')
|
expect($('#buildId').text() === '-')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('correctly imports a package that defines `module` but no `main` in package.json', async () => {
|
||||||
|
const $ = await get$('/module-only-content')
|
||||||
|
expect($('#messageInAPackage').text() === 'OK')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue