简体   繁体   中英

How to minify and uglify an NPM package written in Typescript?

I need to publish minified version of an NPM package written in Typescript. To compile the app I use tsc -p. command and it builds the package in lib folder. I feel that lib is somewhat similar to src folder in terms of size as it has unnecessary folder, sub-folders and files.

Is it possible to minify and uglify this lib folder into just a single index.min.js file?

PS this package is a CLI tool. Is there any need to ship type definitions in d.ts files? All they contain is just types for functions and variables used in the code.

Thanks!

在此处输入图像描述

To merge everything into one file you need to set the outFile property in your typescript property

{
  "compilerOptions": {
    "outFile": "./lib/index.js"
// more configs here
  },
  "exclude": [
    "node_modules"
  ]
}

For minification you have to use an external tool since Typescript does not have any option for that and maybe it will never have since it is an open request since 2014

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM