Nextcloud-vue: Enable tree shaking

Created on 14 Feb 2019  路  10Comments  路  Source: nextcloud/nextcloud-vue

The size of the vue components bundle is pretty big already, mainly caused by those three libraries:

| Library | Stat size | Parsed size |
|---|---|---
| v-tooltip | 184KB | 55KB |
| vue-multiselect | 44KB | 44KB |
| datepicker | 40KB | 40KB |

We should look into enabling webpack tree shaking to allow apps to just include the code that is actually used. So if an app doesn't use the multiselect or datepicker this could save us quite some KBs.

Bundle size treemap:
image

I tried to get this working a bit, but couldn't come up with something unforunately. @skjnldsv @ChristophWurst

Most helpful comment

All 10 comments

@juliushaertl I think it is actually enabled by default on production?

since we already support the individual import with import { xxx } from the app's webpack config should already do the trick?
Let me try

EDIT: ah no indeed, webpack is not doing it by default :/

At least for me the ncvuecomponents.js size was always the full in apps.

@juliushaertl I saw various libraries also outputting individual js files per component and allowing the import like so: import { PopoverMenu } from 'nextcloud-vue/dist/components'

https://github.com/vuematerial/vue-material

Yeah unfortuantely none of them seems to use webpack, so we cannot easily compare what they are doing :wink:

I saw various libraries also outputting individual js files per component and allowing the import like so: import { PopoverMenu } from 'nextcloud-vue/dist/components'

I looked a bit more into how those libraries are doing that, but it seems they all create individual entry points for each component, so there is one all-in-one bundle as well as one for each component.

@juliushaertl yes exactly! Would that be an issue? Nothing come to my mind :thinking:

Ok, I digged a bit more into that. In general it seems that webpack would need to provide a way to export proper es modules, which is currently not supported: https://github.com/webpack/webpack/issues/2933

The general recommendation is to use rollup for bundling libraries (https://vuejs.org/v2/cookbook/packaging-sfc-for-npm.html) but not sure if we can move that over easily.

Shall we close?

Yep should be fine now

Was this page helpful?
0 / 5 - 0 ratings