Comments (8)
Not really because I'm creating an ESM-first web component so I cannot import deflate from pako/dist/pako_deflate
since it's a CommonJS file.
If we don't want to update the code, an alternative solution would be to produce ESM files for pako_deflate.js and pako_inflate.js but it feels counter productive since ESM was designed to produce compact bundle with a static structure. In other words, import deflate from 'pako/dist/pako_deflate'
(instead of import {deflate} from 'pako'
) would be contrary to the ESM philosophy (in my opinion).
from pako.
From my understanding, classes don't tree-shake as well as ESM Modules, even static. That's because you can always reference a method by name:
class MyClass {
myMethod() { }
myMethodINeverUse() {}
}
const instance = new MyClass();
instance.myMethod();
let methodName = 'myMethodINeverUse'
instance[methodName]();
ESM Modules don't really exhibit this issue and are better for tree-shaking:
export function myMethod() {}
export function myMethodINeverUse() {};
Babel, Webpack, and Rollup will all tree-shake when you do:
import {deflate, inflate} from 'pako'
And even if you were to import inflate
and never use it, those bundlers will remove them anyway during minification.
You can even do import * as pako from 'pako'
and bundlers will remove what you don't use. But then you have to be conscious of the sideEffects: true
if you try to do something like:
import * as pako from 'pako';
const pakoFn = 'import';
pako[pakoFn]()
That's a side-effect where you don't actually support clean tree-shaking of imports.
See: https://webpack.js.org/guides/tree-shaking/
TL;DR: Drop require
and use native ESM modules, not classes, for better tree-shaking.
from pako.
This package was done to be compatible with ancient browsers, probably not actual now.
But you can import pre-build files from dist https://github.com/nodeca/pako/tree/master/dist. Will it solve your problem right now, without changes?
from pako.
Since we are already using Babel, I believe that class
will be transpiled/transformed when the target is ES5. So this change will only affect the ESM file.
from pako.
@puzrin I too only need to use deflate
and it would be very nice to have inflate
tree-shooken out.
from pako.
@ggrossetie @rlidwka is this a change that you would be interested in supporting? This library has like 10m+ users tree shaking would be a really good add especially since that is far more modern. @ggrossetie @puzrin what changes would be needed to add that support is it really just a simple as adding class
?
from pako.
what changes would be needed to add that support is it really just a simple as adding class?
Yes.
from pako.
Also, I'm pretty sure you can do
import { deflate } from 'pako/lib/deflate.js';
import { inflate } from 'pako/lib/inflate.js';
And you're basically tree-shaking yourself. Though because the files are using require
, they both might import utils/string.js
completely, instead of tree-shaking only what it needs.
from pako.
Related Issues (20)
- "Error: -3" when inflating chunks of data HOT 2
- How to decompress blob? HOT 2
- Deflate() creating broken zip file
- No way to read Deflate data in chunks. HOT 4
- CI: set minimal permissions on GitHub Workflow HOT 2
- Cannot install pako HOT 1
- library initialization slowing down app start
- TypeError: input.subarray is not a function HOT 1
- Docs update: mention what `inflate` and `deflate` actually return
- Incorrect JSDoc type information for optional parameters
- Expecting a new version release HOT 1
- Different 10th byte gzip header between zlib and pako on Mac OS 13 HOT 1
- License declaration in package.json and LICENSE are not the same
- GZIP pako compressed string results in "Not in GZIP format" in JAVA on decompressing HOT 1
- Inconsistency and `undefined` return in `inflate` method between versions v1 and v2
- Using static dictionary, inflateRaw "Uncaught invalid stored block lengths"
- how to gzip multiple files? HOT 1
- Not compatible with Angular v17
- Getting corrupted data on decompressing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pako.