vue-quick-chat icon indicating copy to clipboard operation
vue-quick-chat copied to clipboard

Proposal: Replace moment.js with date-fns or Luxon.js

Open martinandersen3d opened this issue 5 years ago • 12 comments

This thread purpose, is to discuss if it should be done.

Why? -> Bundle size, thats why :-)

When looking at the package size of moment.js, its "medium-huge"... https://bundlephobia.com/[email protected]

Luxon is supposed to replace moment.js, with better webpack support (include what you need). Also made by the team of moment. They created Luxon, because it support new techologies, and they did not want to break moment.js

date-fns, same as luxon..

https://moment.github.io/luxon/ https://date-fns.org/

This is maybe a "nice" to have and not a "need" to have. But would be best practice.

Now.. it all comes down to browser compatibility and opinions. What is the general opinion on this?

:-)

martinandersen3d avatar Jan 06 '20 20:01 martinandersen3d

The bundle size is a problem. I don't know if the unique reason is moment.js, and I do not have much experience at reducing bundle size of packages. However, if the bundle size can be reduced just changing from moment.js to Luxon, there's no problem in my point of view.

Luxon has a guide for moment users https://moment.github.io/luxon/docs/manual/moment.html.

Maybe we could also discuss here other ways to reduce the bundle size.

MatheusrdSantos avatar Jan 06 '20 23:01 MatheusrdSantos

Also.. in vue-quick-chat/package.json, everything in Core-js is included.

https://bundlephobia.com/[email protected]

We can choose to include only the things that we need. Example from Core-js docs: image

https://github.com/zloirock/core-js

martinandersen3d avatar Jan 07 '20 12:01 martinandersen3d

The send icon:

Replace: vue-icon https://bundlephobia.com/[email protected]

With this: We can include only ONE icon here: image


This is just a Proposal, to optimize bundlesize. Hehe.. I dont know if it is nice or worse :D

martinandersen3d avatar Jan 07 '20 12:01 martinandersen3d

Icon alternative: https://codepen.io/martinandersen3d/pen/vYEdERg

just include the icon as raw html.. its 300 bytes :D

martinandersen3d avatar Jan 07 '20 12:01 martinandersen3d

Thanks, @martinandersen3d. I will apply these changes as soon as possible.

MatheusrdSantos avatar Jan 07 '20 23:01 MatheusrdSantos

Today I changed the icon package from vue-icon to vue-material-design-icons (the same suggested before), and I got a small improvement on the bundle size. Initial size image after changes image

MatheusrdSantos avatar Jan 13 '20 23:01 MatheusrdSantos

The icon is the smallest of the changes I guess.

Try checkout this extension for vscode

https://marketplace.visualstudio.com/items?itemName=wix.vscode-import-cost

martinandersen3d avatar Jan 13 '20 23:01 martinandersen3d

The bundle size still large. I guess the problem is with some js lib since the dist/vue-quick-chat.commom.js has 709.27 KiB, and the recommended limit size is 244 KiB.

The next change I'll apply is migrating from moment.js to Luxon.js

MatheusrdSantos avatar Jan 13 '20 23:01 MatheusrdSantos

I have not tried this yet, but looks usefull

https://www.npmjs.com/package/webpack-bundle-analyzer

martinandersen3d avatar Jan 13 '20 23:01 martinandersen3d

Thanks, I'll use these tools.

MatheusrdSantos avatar Jan 13 '20 23:01 MatheusrdSantos

Hi, @martinandersen3d. Today I migrated from momentjs to Luxonjs, and I got a significant improvement in the bundle size. image However, it still warning about the bundle size. I'll try to fix core-js.

MatheusrdSantos avatar Jan 15 '20 01:01 MatheusrdSantos

on "Dev branch":

image

image

I fumbled a little to get it to work.. but it was something like this:

Cmd (run as admin)

npm install -g @vue/cli

npm i webpack-cli @webpack-cli/init

I used this one instead https://www.npmjs.com/package/vue-cli-plugin-webpack-bundle-analyzer

npm i vue-cli-plugin-webpack-bundle-analyzer --save-dev

this guy does not provide an exact guide, but gives some clue to how it work. https://www.youtube.com/watch?v=ltlxjq4YEKU

  • Sorry for misspells.. i'm in a rush :D

martinandersen3d avatar Jan 24 '20 16:01 martinandersen3d