webpack无法解析外部打字稿声明文件

时间:2017-03-15 03:27:54

标签: angular typescript webpack

Angular2 + Webpack,Typescrip @ 2.1.4,Visual Studio 2015 as IDE。

我需要将外部声明文件(将其命名为extlib)添加到我的项目中,@types包中未提供。我做了以下事情:

  1. extlib.d.ts移至typings/extlib/index.d.ts;

  2. 修改tsconfig.json如下;

    {
    "compilerOptions": {
        "target": "es5",
        "module": "es2015",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": true,
        "noImplicitAny": true,
        "skipLibCheck": true,
        "lib": [
        "es2015",
        "dom"
        ],
        "typeRoots": [
        "./node_modules/@types",
        "./typings"
        ],
        "types": [
        "node",
        "howler",
        "extlib"
        ]
    },
    "files": [
        "app/app.module.ts",
        "main.ts"
    ],
    "awesomeTypescriptLoaderOptions": {
        "useWebpackText": true
    },
    "compileOnSave": false,
    "buildOnSave": false
    }
    
  3. 在ts文件中使用extlib

    import * as extlib from 'extlib'
    
  4. 这样做之后,VS的智能感知效果很好,tsc也是如此。但是当我使用webpack时,它告诉我:

        `Module not found: Error: Can't resolve 'extlib' in '...'`
    

    如何使webpack解析此外部打字稿声明文件?

0 个答案:

没有答案