From 25b2b62d24ea172dba698c22045b8fe5e607ebf5 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Fri, 18 Dec 2020 14:17:23 -0500 Subject: [PATCH] Add --generate-types option (#589) --- src/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 29988ab..938aa44 100644 --- a/src/index.js +++ b/src/index.js @@ -364,6 +364,7 @@ function createConfig(options, entry, format, writeMeta) { : () => resolve(options.cwd, 'mangle.json'); const useTypescript = extname(entry) === '.ts' || extname(entry) === '.tsx'; + const emitDeclaration = !!(options.generateTypes || pkg.types || pkg.typings); const escapeStringExternals = ext => ext instanceof RegExp ? ext.source : escapeStringRegexp(ext); @@ -476,7 +477,7 @@ function createConfig(options, entry, format, writeMeta) { map: null, }), }, - useTypescript && + (useTypescript || emitDeclaration) && typescript({ typescript: require(resolveFrom.silent( options.cwd, @@ -488,6 +489,8 @@ function createConfig(options, entry, format, writeMeta) { compilerOptions: { sourceMap: options.sourcemap, declaration: true, + allowJs: true, + emitDeclarationOnly: options.generateTypes && !useTypescript, declarationDir: getDeclarationDir({ options, pkg }), jsx: 'preserve', jsxFactory: