create-react-appのtypescript版において、import時のindex.tsxの表記を省略する方法

2019-01-14

tsconfig.json に"lib": ["es6", "dom"]を追記してあげると、index.tsは省略できるようになります。

が、index.tsxは省略できず、数日悩んでいました。

で、結論から書くと、webpack.config.jsに以下を追記してあげると動きました。

...

// ADD
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

module.exports = function (webpackEnv) {
  ...
  return {
    resolve: {
      ...,
      plugins: [
        ...,
        // ADD
        new TsconfigPathsPlugin({ configFile: paths.appTsConfig })
      ]
    },
  }
  ...
}

動く理由はよくわかっていません、誰か教えて!