microsoft / vscode-codicons

The icon font for Visual Studio Code
https://microsoft.github.io/vscode-codicons/dist/codicon.html
Creative Commons Attribution 4.0 International
867 stars 178 forks source link

Optimize package published to `npm` #257

Open metonym opened 2 weeks ago

metonym commented 2 weeks ago

Currently, the entire repository contents are published to NPM. The package can be optimized by excluding unnecessary files/folders/metadata when publishing to NPM.

Screenshot 2024-08-25 at 8 59 30 AM

The distributed package size can be optimized by using the package.json#files property. It's an allowlist of files or folders for publishing.

This PR proposes allowlisting dist and src folders. Note that some files are automatically included and do not need to be specified (e.g., README, LICENSE).

Running npm pack shows the following comparison.

Before

  1. On the main branch
  2. npm i; npm run build
  3. npm pack
npm notice name:          @vscode/codicons                        
npm notice version:       0.0.36                                  
npm notice filename:      vscode-codicons-0.0.36.tgz              
npm notice package size:  764.2 kB                                
npm notice unpacked size: 1.5 MB                                  
npm notice shasum:        b0d87610ffc3e3ca45c5f8e0d8e08713c16c13a8
npm notice integrity:     sha512-py9MnHtx7AjvF[...]OWu7elS+H67Nw==
npm notice total files:   502

After

  1. On this branch
  2. npm i; npm run build
  3. npm pack
npm notice name:          @vscode/codicons                        
npm notice version:       0.0.36                                  
npm notice filename:      vscode-codicons-0.0.36.tgz              
npm notice package size:  276.9 kB                                
npm notice unpacked size: 972.6 kB                                
npm notice shasum:        b6ad40e66d586dd253f3050b680fa6152d6d66f6
npm notice integrity:     sha512-i4CXMhE6/iCTk[...]wioFa7eoPksXQ==
npm notice total files:   474    

Result

Consequently, the size of the publish package (both packed/unpacked) can be dramatically reduced.

- npm notice package size:  764.2 kB                                
+ npm notice package size:  276.9 kB         

- npm notice unpacked size: 1.5 MB                           
+ npm notice unpacked size: 972.6 kB