Skip to content

Commit 25b2b62

Browse files
authored
Add --generate-types option (#589)
1 parent fdafaf7 commit 25b2b62

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ function createConfig(options, entry, format, writeMeta) {
364364
: () => resolve(options.cwd, 'mangle.json');
365365

366366
const useTypescript = extname(entry) === '.ts' || extname(entry) === '.tsx';
367+
const emitDeclaration = !!(options.generateTypes || pkg.types || pkg.typings);
367368

368369
const escapeStringExternals = ext =>
369370
ext instanceof RegExp ? ext.source : escapeStringRegexp(ext);
@@ -476,7 +477,7 @@ function createConfig(options, entry, format, writeMeta) {
476477
map: null,
477478
}),
478479
},
479-
useTypescript &&
480+
(useTypescript || emitDeclaration) &&
480481
typescript({
481482
typescript: require(resolveFrom.silent(
482483
options.cwd,
@@ -488,6 +489,8 @@ function createConfig(options, entry, format, writeMeta) {
488489
compilerOptions: {
489490
sourceMap: options.sourcemap,
490491
declaration: true,
492+
allowJs: true,
493+
emitDeclarationOnly: options.generateTypes && !useTypescript,
491494
declarationDir: getDeclarationDir({ options, pkg }),
492495
jsx: 'preserve',
493496
jsxFactory:

0 commit comments

Comments
 (0)