esbuild-shake-tsyringe-tree
v0.1.3
Published
This plugin is designed to shake tree (remove code unused) mainly with the lib tsyringe. Attention: Currently only works with ES Module (.mjs)
Downloads
397
Maintainers
Readme
Esbuild plugin to shake tree with tsyringe
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
Requirements:
- Only with ES Module files;
- EcmaVersion: 'latest' (no option to change)
- Works with multiple files;
- Works with serverless;
What we support in tsyringe
Decorators:
@injectable()
@inject(string)
Functions:
container.register(string, className)
container.registerSingleton(string, className)
PS: Some unmapped item may break the tree shake
Setup
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.
Contribute
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