Suggestion: Add config option to use tsconfig's paths as webpack.resolve.alias
Suggestion
I frequently find myself having to add the same alias to webpack resolver and tsconfig. My ideia is to provide this as an option in @zeit/next-typescript.
// tsconfig.json
{
"paths": {
"~/components/*": ["src/components/*"],
},
}
// next.config.js
const withTypescript = require('@zeit/next-typescript')
module.exports = withTypescript({
useTsPathsAsAlias: true,
})
The code above should set config.webpack to function that loads tsconfig json, converts tsconfig.paths to webpack.resolve.alias pattern and assign it. The result should be:
// webpack config
{
...,
resolve: {
...,
alias: {
...,
'~/components': path.resolve('src/components'),
}
}
}
If it makes sense, I can write PR adding this feature.
I this it is probably not needed for this to have first class support here; the one change might be re-exporting the TS path plugin out of awesome-typescript-loader.
I have set up the following in my next config:
const TsConfigPathsPlugin = require('awesome-typescript-loader').TsConfigPathsPlugin;
..... in webpack config:
config.resolve.plugins = [
...config.resolve.plugins || [],
new TsConfigPathsPlugin(),
],
That is literally all that is needed.
This is supported by default: https://nextjs.org/docs/advanced-features/module-path-aliases