Ollie
Ollie

Reputation: 1435

How to include entire folder in TypeScript build?

I have a tsconfig.json:

{
   "compilerOptions": {
      "lib": [
         "es5",
         "es6"
      ],
      "target": "es6",
      "module": "commonjs",
      "moduleResolution": "node",
      "outDir": "./build",
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "strict": true,
      "esModuleInterop": true,
      "allowSyntheticDefaultImports": true,
      "strictPropertyInitialization": false,
      "sourceMap": true,
      "removeComments": true,
      "noImplicitAny": true,
      "strictNullChecks": true,
      "strictFunctionTypes": true,
      "noImplicitThis": true,
      "noImplicitReturns": true
   },
   "exclude": ["node_modules"],
   "include": [
     "./src/**/*.ts",
     "./src/customer-api-docs/*"
    ]
}

I have a folder called customer-api-docs that I want included in its entirety as part of the build (it contains static files for use by a library called Docsify.

I have added "./src/customer-api-docs/*" as part of the include property, and additionally I have also tried without the trailing /*. However when running tsc -b the folder is not within the build folder. All the other ts files are successfully compiled to the build folder though.

Thank you in advance for any advice you can give!

Upvotes: 0

Views: 12570

Answers (2)

Abhinandan Sharma
Abhinandan Sharma

Reputation: 61

if someone has arrived here wanting to include any folder in the typescript build folder, here is one approach.

You can just use an npm module copyfiles to copy all the folders you want in your build folder. I was deploying a heroku app built on typescript server and Reactjs. I wanted my client folder to be included in the build. So, I added this script:

"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix src/client && npm run build --prefix src/client&&copyfiles src/client/*/ build",

Upvotes: 3

itdaos
itdaos

Reputation: 69

After looking up in TypeScript Docs I found out that you actually allowed to include non-ts files into your build

If a glob pattern doesn’t include a file extension, then only files with supported extensions are included (e.g. .ts, .tsx, and .d.ts by default, with .js and .jsx if allowJs is set to true).

So probably setting something like this may help (docsify):

{
  "include": [
     "./src/**/*.ts",
     "./src/customer-api-docs/*.html",
     "./src/customer-api-docs/*.md"
  ]
}

Upvotes: 1

Related Questions