import image when running compiler with `allowJS:true`

37 Views Asked by At

I want to create a React Native library using JavaScript instead of typescript, but I want to take an advantage of TSC because I use jsdoc comment, and TSC can generate a type declaration from jsdoc. But I have a problem that my local image is not included when ts compiler running.

I've tried Solution#4 but still my images not included in dist/Images when tsc run.

+ src
  + //another folder
  + Images
    - Images.js // here i add require('./error.png') 
    - error.png
  - index.js
  - declaration.d.ts
- package.json
- tsconfig.json

tsconfig.json :

{
  "include": [
    "src/**/*",
    "src/declaration.d.ts"
  ],
  "exclude": [
    "node_modules/*"
  ],
  "compilerOptions": {
    // other options
    "outDir": "dist",
    "allowJS": true
  }
}

Is there any way to included src/Images/error.png into dist folder while running tsc?

1

There are 1 best solutions below

0
Daham Akl On

For the React-based project, the better and most recommended approach is to include these images in an assets folder. for an images folder, where separately you can manage images or any other CSS, JS(3rd party files) there. This is the way most developers use for enterprise-level applications and even for small applications.