Comments (10)
Just because they do doesn’t mean that this wouldn’t be a good change. This does nothing for browserify users or people using older versions of webpack.
This solution is both relatively easy to switch to and the support is guaranteed.
from tslib.
I am also finding this to be a problem when publishing many small typescript modules. Ideally each utility would have it's own namespace require('tslib/$NAME')
.
Inlining the code directly means (when publishing a bunch of small modules) a bunch of code is duplicated, however when you use importHelpers
it means you are incurring at least 2kb gzipped, which is a lot to ask for a module that is say 1kb gzipped.
I would personally advocate the approach taken by just however everything doesn't necessarily need to be in it's own published package.
It would be even cooler if these utilities could be used (without risk and with official support) in non typescript files to even further decrease duplication. For example in many of modules I require something like just-extend when I could easily use tslib.__extends
if it were supported.
from tslib.
So you are importing the whole tslib
there.
Again, why not put each helper in its own module and do something like this:
var _extends = require("tslib/lib/extends");
from tslib.
Honestly, there is not a lot of code in this library. While the output does not lend itself to tree-shaking, your loader will only include it once so it doesn't seem like a code size issue.
@aluanhaddad "a lot of code" is relative, if I write a 10 line script for the web that uses only _extends
, why would I incur a penalty of 200-line tslib
.
from tslib.
First, install tslib
:
npm install tslib
Then add importHelpers: true
in your tsconfig.json
:
{
"compilerOptions": {
"moduleResolution": "node",
"module": "commonjs",
"target": "es5",
// ...
"importHelpers": true // <-------
}
}
Now when you compiler *.ts
file, it may looks like this:
var tslib_1 = require("tslib")
tslib_1.__awaiter(...)
tslib_1.__extends(...)
from tslib.
Honestly, there is not a lot of code in this library. While the output does not lend itself to tree-shaking, your loader will only include it once so it doesn't seem like a code size issue.
Also, some of the functions reference each other, meaning that if the package were split, they would need cross referencing imports which would result in a more complex multi-module format export strategy than what is already in place.
from tslib.
@streamich if you don't use importHelpers
then typescript will inline only the methods which you actually use. importHelpers
is to reduce helper methods being inlined across multiple modules.
from tslib.
@frankwallis I know that, but it will inline those in each file though.
from tslib.
Is there a reason that existing bundlers can't just do a good job here with tree-shaking? We provide both ES2015 and UMD outputs. Both Webpack and Rollup should be able to do a decent job here.
from tslib.
Yeah, I'm against the idea of splitting this into sub-modules too. Module bundlers can handle tree shaking tslib just fine nowadays (we have tests for in in #126).
I'm going to close 👍🏻
from tslib.
Related Issues (20)
- Use standard `exports` in `package.json` HOT 3
- __importDefault method may return an object with undefined default property HOT 2
- __assign is not a function
- Type 'boolean' is not assignable to parameter of type '(false | Observable<false>) & (true | Observable<true>) HOT 1
- CI: set minimal permissions for GitHub Workflows HOT 1
- TypeError: (0 , tslib__WEBPACK_IMPORTED_MODULE_0__.__rest) is not a function HOT 1
- Should tslib be in peerDependencies or just dependencies when building a library? HOT 3
- [2.5.1][Regression] imported helper named '__decorate' does not exist in 'tslib' HOT 6
- ERROR in bundle from UglifyJs Unexpected token: punc (,) HOT 8
- Regression in [email protected] when using private fields i.c.m. with ESM HOT 3
- Cannot find module '...node_modules/tslib/modules/index.js' imported from chunks/app/server.mjs HOT 2
- Generate SLSA Build L3 provenance HOT 4
- tslib >=2.5.1 regression - increases bundle size caused by noop `Object.create;` statements
- calls to tslib __setFunctionName fail on Cobalt 9 HOT 5
- Suggest an dependabot to keep GitHub Actions updated HOT 1
- Regression failure upgrading from 2.5.0 to 2.5.1+, webpack fails to transpile new export statement for ES5. HOT 1
- Performance improvement HOT 2
- The spread (...) syntax allows an string,but __spreadArray does not support string. HOT 2
- Why do I get compilation results of tslib imports containing native absolute path? HOT 2
- this appears to be a dev-dependency, but the instructions point it to be a dependency 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 tslib.