-
Notifications
You must be signed in to change notification settings - Fork 532
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
Huge component size #112
Comments
Thank you for your explain. Could you make a PR with this changes? |
Yes, I will make one today with some simple changes which should reduce the size in half :) |
I used this tool: https://chrisbateman.github.io/webpack-visualizer/ |
Hi, this issue has the same goal as my other one #67 I think the generator should be on it's own and people should just pick and choose which one they want. What are your thought ? |
Agree witht that @lionel-bijaoui . What's the impact of externals ? Don't quite understand it. |
@cristijora with At the time I envisioned that you could specify by field, what dependency it have and simply add it in a script tag (some fields do that). But I'm not sure that it would work if you Doc : https://webpack.github.io/docs/library-and-externals.html Edit: Better doc (for webpack 2 but it is mainly the same process) : https://webpack.js.org/guides/author-libraries/ |
Ah got that. Don't think that's a robust option. Ideally it would be nice to get rid of the external dependencies or use strictly what's necessary which is ok in the case of lodash, but for some reasons it imports a lot of code. Moment is used only in 4 places for some basic stuff. We can get rid of it I think. |
Use moment.min to reduce build size
#112 Get rid of Vue dependency in the code.
Thanks @cristijora . Your PR merged. Now there is only lodash (75% of bundle). |
Maybe webpack 2 tree-shaking can be remove the unused lodash functions? |
Could be an option. Will give it a read. |
I would like we avoid changing webpack version for now. Also, can we make a decision about "modularizing" fields ? |
Use babel-plugin-lodash to support "tree-shaking" for lodash
@lionel-bijaoui I don't support modularizing fields, because the size of code of all fields is small. ~ 10kb. So we can decrease the size with modularizing. We need to solve the momentjs & lodash dependencies instead. |
Well, moment and lodash are priority, but since vuejs 2 compiled sit at
about 12k, 10k is actually big.
Vfg could keep some super basic field (classic html5 inputs). But all the
others (jQuery based field, others like vuemultiselect, etc.) can use the
same system as the custom fields and be use if needed.
It would allow anyone to create fields for the system with a naming
convention (vfg-***) like babel did.
At least, unused field should not be bundled in the final file. For
example, I could create some sort of "config" for vfg to tell it that I
explicitly use this and that field (maybe with `Vue.use()`) and webpack
could throw away unused fields at bundling.
Sorry to insist on that point but for my project I need a lot of custom
fields and every byte saved is welcomed. I would like to avoid to create a
fork only for performance reasons.
Thank you for your understanding.
Le 14 févr. 2017 09:31, "Icebob" <[email protected]> a écrit :
… @lionel-bijaoui <https://github.com/lionel-bijaoui> I don't support
modularizing fields, because the size of code of all fields is small. ~
10kb. So we can decrease the size with modularizing. We need to solve the
momentjs & lodash dependencies instead.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#112 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADT81IsmEDfBI9n_6DNlpewzL8akcMycks5rcWZWgaJpZM4L-rOE>
.
|
i actually partially agree with @lionel-bijaoui here. This would open some possibilities like adding some vue based components while not affecting the size of the whole thing. I don't have a good solution for it though. Maybe have something similar to the custom field implementation. Simply import the necessary external lib and declare it globally ? Ex: import fieldMultiSelect from "vue-form-generator/src/fieldVueMultiSelect.vue"
Vue.component("fieldMultiSelect", fieldMultiSelect); This would register the component as an abstract field and it will work since the component meets the requirements of the abstract field custom inputs. |
In this case we can create two bundles. A minimal version (for only html5 field, but can be import the further fields) and a full version (as current bundle, which contains every built-in fields) Opinion? |
Sorry, I didn't remember :) |
Ahah, no problem ! |
Agree. Seems like a simple approach. If the user doesn't care about size he just imports the default full version but if he does care then he imports the minimal version and declares the components himself. if(!this.$root.$options.components["multiselect"]) Example: if(!this.$root.$options.components["fieldDateTimePicker"]) |
And need to rewrite the dynamic field loader part |
Yeah. A simple option would be to place the optional fields in a separate folder 😄 |
Nice suggestion :) |
So the tasks:
|
The first 2 are in this PR |
And babel-plugin-lodash working properly? |
Great! 🎉 |
I can help with the webpack config if needed. |
@lionel-bijaoui let Fields = require.context("./fields/", false, /^\.\/field([\w-_]+)\.vue$/);
let fieldComponents = {};
each(Fields.keys(), (key) => {
let compName = key.replace(/^\.\//, "").replace(/\.vue/, "");
fieldComponents[compName] = Fields(key);
});
//some other code
components: fieldComponents, A very simple approach here would be to put the optional components which we don't want to include in a separate folder and have some webpack config at this point foldersToInclude = ["./fields/","./optional"]; and for the minimal build foldersToInclude = ["./fields"] Instead of |
And you can use DefinePlugin and declare a variable in webpack config e.g. if (FULL_BUNDLE) {
foldersToInclude = ["./fields/","./optional"];
} else {
foldersToInclude = ["./fields"]
} Maybe :) |
@cristijora thanks a lot for your help. You deserve the collaborator title more than I do 🥇 |
@lionel-bijaoui I would like to discuss that we marked some fields as "deprecated", because we have a common "input" field. Are we remove them in v2? |
Yes, that would be a good time to do it. Most of them are duplicate of the
new input based field. Let me double check the list to make sure they are
no false positive.
Le 15 févr. 2017 9:29 AM, "Icebob" <[email protected]> a écrit :
… @lionel-bijaoui <https://github.com/lionel-bijaoui> I would like to
discuss that we marked some fields as "deprecated", because we have a
common "input" field. Are we remove them in v2?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#112 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADT81Gq_DUH-ibPKNaQnK6JYDviy2FzBks5rcrdhgaJpZM4L-rOE>
.
|
OK, new issue for this: #120 |
Full bundle: 75k Great! |
Awesome. Nice to see going it down from 400+kb to 40kb. |
Just noticed that the overall component has 400+ kb in size.
I must say that's pretty huge for a component that generates fields.
After taking a look at the source code I noticed that
moment.js
is used in several places for very basic functionalities. I think you can get rid of it to save some space.Only by removing all moment js dependencies (4) the size shrinked from 400kb to 176kb.
There is also one component
fieldVueMultiSelect
which for some reason uses the wholeVue
library. I don't think there is need to bring the whole library just to instantiate that component. There should be another way of doing it. By removing the vue dep the final file further reduces to 126kb.Taking down
lodash
util function brings the file down under 100kb.To sum it up, by removing only external dependencies (
moment, vue and lodash
) I managed to bring the library down from 400+ kb to 55kb and by removing external components it goes down to 29kb.The size here is huge factor for people deciding whether to use such a component or not. I would say we could shrink this one down to 100-150kb very easily and then with some effort it can be brought under 100kb.
The text was updated successfully, but these errors were encountered: