Home > Blockchain >  esBuild not creating type files when in watch mode
esBuild not creating type files when in watch mode

Time:07-14

Have recently started using edBuild, have found it simple, fast and easy to onboard.

When i run my esBuild build command WITHOUT WATCH I can see type files are successfully created - .d.ts files.

When WATCH IS running, these files are not generate.

package.json:

"scripts": {
    "ts-types": " tsc --emitDeclarationOnly --outDir dist",
    "build": " node ./esbuild.js && npm run ts-types",
    "postbuild": "npm run ts-types"
}

esbuild.js

.build({
    entryPoints: ['/index.ts'],
    outdir: 'dist',
    format: 'cjs',
    watch: {
        onRebuild(err, result) {
            if(err) log('error')
            else log('succes')
        }
    }
})
.then(result => {
    log('succes')
})
.catch(() => process.exit(1));

How can i run watch and recreate the .d.ts files on changes?

CodePudding user response:

ESBuild doesn't support generating type declaration.

You are using tsc to actually generate the type declaration.

You should be able to start a process from inside node that runs this. Something similar to this:

const {exec} = require('child_process');

...

.build({
    entryPoints: ['/index.ts'],
    outdir: 'dist',
    format: 'cjs',
    watch: {
        onRebuild(err, result) {
            if(err) log('error')
            else {
              exec("npm run ts-types");
            }
        }
    }
})
.then(result => {
    log('succes')
})
.catch(() => process.exit(1));
  • Related