webpack not able to import images( using express and angular2 in typescript)

前端 未结 7 1498
难免孤独
难免孤独 2020-12-09 04:00

I am not able to import images in my headercomponent.ts. I suspect it is because of something i am doing wrong while compiling ts(using webpack ts loader) because same thin

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 04:38

    I'm using

    import * as myImage from 'path/of/my/image.png';
    

    and created a typescript definition with

    declare module "*.png" {
        const value: any;
        export = value;
    }
    

    This only works when you have a correct handler like the file-loader in webpack. Because this handler will give you a path to your file.

提交回复
热议问题