angular - webpack kan inte lösa externa TypeScript-deklarationsfiler


Angular2+Webpack, [email , Visual Studio 2015 som IDE.

Jag behöver lägga till en extern deklarationsfil (namnge den extlib) i mitt projekt, som inte tillhandahålls i @types-paket. Jag har gjort följande saker:

  1. flytta extlib.d.ts till typings/extlib/index.d.ts;

  2. ändra tsconfig.json enligt följande;

    {
    "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. använd extlib i ts-filer som:

    import * as extlib from 'extlib'
    

Efter att ha gjort detta fungerar Intellisense i VS bra, det gör även tsc. Men när jag använder webpack, berättade det för mig:

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

Vad ska jag göra för att få webpack att lösa dessa externa TypeScript-deklarationsfiler?