Skip to content

Instantly share code, notes, and snippets.

@webgyo
Created July 16, 2019 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webgyo/b340a36d91ddeca7817300477389ee85 to your computer and use it in GitHub Desktop.
Save webgyo/b340a36d91ddeca7817300477389ee85 to your computer and use it in GitHub Desktop.
vscodeにwebpackで設定したresolve aliasを認識させる #webpack #typescript #vscode

相対パスを書く手間が省ける

const path = require('path');

module.exports = {
  ...
  resolve: {
    alias: {
      '@bar': path.resolve(__dirname, 'src/foo/bar')
    }
  }
};

ただしこのままだとコンパイルは徹がvscode上でfind moduleのメッセージが出るので

tsconfig.jsonで以下を設定する

"baseUrl": "./",
"paths": {
    "@bar/*": [
        "'src/foo/bar'/*"
    ]
}

Webpackのresolve.aliasとVSCodeのjsconfig.jsonを使ってimportを快適にする
https://qiita.com/kazuooooo/items/b0ca9bd74a093824403e

JSからTSへの移行で悩んだ点の対応メモ
https://qiita.com/kurosame/items/3c28f45c8b2e65f5c69d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment