-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save 8kb by replaceing error messages with error codes #653
Comments
Plan of actionAfter a quick research, the best way forward seems to be a custom babel plugin. That way we can easily generate different bundles by changing either There is no way around parsing the code anyway, and babel's ast-parser is the most advanced and best documented at the time of this proposal. Typescript itself doesn't have an api for plugins (yet?). Behind the scenes react parses the source code and searches the ast tree for a specific function call expression and replaces the call with a different error function. In our case we have to simply look for a {
"My error message": "0",
"Another error message": "1"
// ...
} We replace the message parameters (like component name) with simple placeholders, so that we can effectively prevent duplicate messages. RequirementsThe proposed approach has a few hard requirements, that should be kept in mind:
I'll post an update once I'll have some code ready to comment on. |
For urls: best create a github issue, there is one that follows this mechanism already :) https://github.com/mobxjs/mobx/issues?q=label%3Abuilt-in-error-explanation+is%3Aclosed Personally I think using the same approach as React will be the most convenient, as it makes it the responsibility of the uglifier to strip out the additional code. A simple table with issue numbers, and two different implementations should suffice here I think |
@mweststrate, I assume, we won't create issue for every error key, I'd better create simple page on gh-pages, thats loads @marvinhagemeister, you know there is typescript ast parser, right? May be using it like a simple browserify plugin (example) would work? |
@andykog Awesome, thanks for sharing, I didn't know about that one! I'm not sold on linking to github issues. A page on |
We use goo.gl links at bluebird that direct to pages with a lot of info - it was useful in Angular, I recommend those. |
|
I've opened a PR as part one of the issue. I've transferred String messages to a separate file. |
Closed since there is a follow up issue #813 |
I'm currently looking into ways to make the bundle size smaller and noticed that we'd save a lot by swapping out the error messages with error codes similar to what the react guys did. This would save about
~8KB
(53 vs 45 kb) for the non-gzipped minified bundle.We could print something like this:
The text was updated successfully, but these errors were encountered: