Typescript - Include a JSON file to create / output a directory without importing

The name may be a little strange, but I can't find anything on google.

Question I have a folder that contains only .ts and .json files. Typescript compiles .ts files and puts them in a separate directory (and not as a package, just the "as-is" directory structure).

Src /

Workers /

[ModuleA.ts, ModuleA.json],

[ModuleB.ts, ModuleB.json],

[MobuleC.ts, ModuleC.json]

In most cases, I can simply request ("*. Json"), and the JSON file will also be placed in the directory.

But now I have a situation where importing JSON does not make sense, because the JSON file is updated every few seconds, and I read the file with fs.readFile ('*. Json'), so I also don’t know if you want it swam in v8 cache (via require)

So, how do I include a JSON / None-Typescript file in the assembly that is not explicitly imported by either the request or the import?


Now I just used gulp to copy each .json file to the src folder in the corresponding dist / ** folder.

But still I find it strange. Typescript does not have something enabled for it.

+6
source share

Source: https://habr.com/ru/post/1012696/


All Articles