Heim  >  Fragen und Antworten  >  Hauptteil

javascript - Funktioniert WebPack Resolve.alias nicht mit TypeScript?

Umgebung:

- node v6.9.2
- typescript v2.4.1
- webpack v1.15.0
- awesome-typescript-loader v3.2.1

Frage:

Fehler im tsx-Modul „Tools“ nicht gefunden...

import { toFieldValue } from '@utils/tools';

resolve : {
    alias: { 
        // 这里配置没有问题, jsx中可以正常使用
         "@utils": "./src/utils"
    }
}
import { toFieldValue } from '@utils/tools'

TSX-Konfiguration

{
  "compilerOptions": {
    "outDir": "./dist/",
    "module": "commonjs",
    "target": "es6",
    "sourceMap": true,
    "allowSyntheticDefaultImports": true,
    "jsx": "react",
    "pretty": true,
    "noImplicitAny": true,
    "traceResolution": true,
    "baseUrl": ".",
    "paths": {
      "@utils/*": ["./src/utils/*"]
    },
    "lib": [
      "dom",
      "es2015.promise",
      "es5",
      "es2015.iterable",
      "es2015.generator",
      "es2015.symbol",
      "es7"]
  },
  "include": [
    "./src/**/*"
  ],
  "exclude": [
    "node_modules"
  ],
  "awesomeTypescriptLoaderOptions": {
    "useBabel": true,
    "useCache": true
  }
}
我想大声告诉你我想大声告诉你2664 Tage vor1087

Antworte allen(2)Ich werde antworten

  • 習慣沉默

    習慣沉默2017-07-05 10:38:58

    应该是可以使用alias的,楼主可以参考我的react-typescript模版项目,https://github.com/devlee/tpl...

    楼主这不能用,分析原因是tsconfig里的paths应该是路径,而不是直接是源文件吧

    Antwort
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-07-05 10:38:58

    解决了~
    tool.js 必须要声明一个要声明一个对应的tool.d.ts文件。
    醉了醉了~~~

    Antwort
    0
  • StornierenAntwort