Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve all modules through module resolver #963

Merged
merged 1 commit into from
Feb 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions server/build/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,12 @@ export default async function createCompiler (dir, { dev = false, quiet = false
if (!(/\.js$/.test(interpolatedName))) {
return { content, sourceMap }
}

const babelRuntimePath = require.resolve('babel-runtime/package')
.replace(/[\\/]package\.json$/, '')
const transpiled = babelCore.transform(content, {
presets: [require.resolve('babel-preset-es2015')],
sourceMaps: dev ? 'both' : false,
// Here we need to resolve styled-jsx/style to the absolute paths.
// Here we need to resolve all modules to the absolute paths.
// Earlier we did it with the babel-preset.
// But since we don't transpile ES2015 in the preset this is not resolving.
// That's why we need to do it here.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw It seems module-resolver works for ES2015 import too.
Why we need do it here ? I thought it was because styled-jsx/styles is something special which is dynamically added by styled-jsx/babel.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's because it's added by babel. In my tests I had no issues with other modules.

Expand All @@ -168,7 +169,16 @@ export default async function createCompiler (dir, { dev = false, quiet = false
require.resolve('babel-plugin-module-resolver'),
{
alias: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @timneutkens styled-jsx is not in the list now?
I think we'll have the styled-jsx problem again.

'styled-jsx/style': require.resolve('styled-jsx/style')
'babel-runtime': babelRuntimePath,
react: require.resolve('react'),
'react-dom': require.resolve('react-dom'),
'react-dom/server': require.resolve('react-dom/server'),
'next/link': require.resolve('../../lib/link'),
'next/prefetch': require.resolve('../../lib/prefetch'),
'next/css': require.resolve('../../lib/css'),
'next/head': require.resolve('../../lib/head'),
'next/document': require.resolve('../../server/document'),
'next/router': require.resolve('../../lib/router')
}
}
]
Expand Down