Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript: How to include imported images in the output directory?

Tags:

typescript

typings/index.d.ts

declare module "*.svg";
declare module "*.png";
declare module "*.jpg";

tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "declaration": true,
        "outDir": "./dist"
    },
    "include": ["src/**/*", "typings/index.d.ts"]
}

When I run build, it doesn't include the imported images.

like image 921
Noah John Ucab Avatar asked Dec 12 '18 01:12

Noah John Ucab


1 Answers

The compiler won't include those files.

If you're using NPM for instance, you can copy them to your build directory by using a tool like copyfiles. Your build script would look something like that:

"scripts": {
    "build": "tsc && copyfiles *.png build/images"
}

There are multiple ways to do this though, like using webpack.

like image 98
Antoine Boisier-Michaud Avatar answered Nov 23 '22 22:11

Antoine Boisier-Michaud