🐶
blog.terrier.dev

posted: 2018/07/25

next.jsとTypeScriptでpathsを指定しても解決されないときの対処


https://github.com/zeit/next-plugins/issues/207
にissueがあった。
awesome-typescript-pluginのやつはうまく行かなかったので、下記記事を参考にwebpack設定追加した
tsconfig.json
    "baseUrl": ".",
    "paths": {
      "~/*": ["packages/*"]
    },
next.config.js
const path = require("path")
const withTypescript = require("@zeit/next-typescript")

module.exports = withTypescript({
  webpack(config, options) {
    config.resolve.alias = {
      ...config.resolve.alias,
      "~": path.resolve("packages")
    }
    return config
  }
})

Edit on Github
@terrierscript