This plugin is designed to shake tree (remove code unused) mainly with the lib tsyringe. Attention: Currently only works with ES Module (.mjs)
What this plugin does:
- Replaces tsyringe library decorators and functions for native code; (check what is being supported so far);
- Remove unused functions that are in classes with created objects, that is, remove only what we feel is safe;
- We use the RollupJS library to shake the tree and eliminate other code.
- We rerun the steps to ensure the code is cleaner
- We replace the file generated by the esbuild
- Only with ES Module files;
- EcmaVersion: 'latest' (no option to change)
- Works with multiple files;
- Works with serverless;
Decorators:
@injectable()
@inject(string)
Functions:
container.register(string, className)
container.registerSingleton(string, className)
PS: Some unmapped item may break the tree shake
Install via npm:
npm install esbuild-shake-tsyringe-tree --save-dev
- Add the plugin to the
plugins
array in your Serverlessesbuild.config.js
:
const esbuildShakeTsyringeTree = require('esbuild-shake-tsyringe-tree');
build({
/* ... */
format: 'esm',
outputFileExtension: '.mjs',
plugins: [esbuildShakeTsyringeTree],
});
All done! When building your project with esbuild it will automatically shake the tree. No extra configuration is needed.
Help us making this plugin better and future proof.
- Clone the code
- Install the dependencies with
npm install
- Create a feature branch
git checkout -b new_feature
- Lint with standard
npm run lint