OfficialCRUGG
OfficialCRUGG

Reputation: 61

Make TS put all source files, including non-TS, into the build directory

My folder structure is the following:

src
└> index.ts
└> image.webp
└> test.html
└> something.css
build
└> index.js
tsconfig.json

As you may see, in my build folder, there is only the built index File, but not my WEBP, HTML and CSS files, which I want to be in the build folder though. Is there a way to do that?
My current tsconfig.json:

{
    "compilerOptions": {
      "module": "commonjs",
      "target": "es6",
      "removeComments": true,
      "typeRoots": ["@types"],
      "outDir": "build"
    },
    "exclude": ["node_modules"],
    "include": ["src"]
  }

Upvotes: 0

Views: 1230

Answers (2)

jason-warner
jason-warner

Reputation: 111

This has a solution by @bencergazda, he has created typescript-cp that works exactly like you would have hoped.

It works in parallel with typescript and it reads your tsconfig.

I installed it globally on my machine as it is available on npm and just ran "tsc" to do the initial copy build, then I add script with "tsc -w && tscp -w" to have typescript work in parallel with typescript-cp.

Upvotes: 0

seanplwong
seanplwong

Reputation: 1081

I believe it is not possible with tsconfig

You could try to write a build script with copyfiles

"build": "npm-run-all build:*",
"build:lib": "tsc",
"build:asset": "copyfiles image.webp test.html some.css build",

You could also achieve the same with webpack and CopyPlugin

Upvotes: 1

Related Questions