Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a-la-carte components? Should i use it?

When starting a new project using vue-cli it asks a few questions to customize the setup. Generally the project name, description, whether to use eslint for linting, karma and mocha for testing etc. This time it asked me

? Use a-la-carte components? 

I searched for it in the vue-cli docs but didn't come across anything. So can anyone tell me what is "a-la-carte components" and if I should use it?

like image 987
Ragas Avatar asked Oct 11 '17 05:10

Ragas


People also ask

What is a la carte components?

À la carte is an English language loan phrase meaning "according to the menu." It refers to "food that can be ordered as separate items, rather than part of a set meal." So if you use a-la-carte components, it means that you only include components that you need (want) to use, instead of getting all of them.

What is tree shaking in Vuetify?

The A la carte system enables you to pick and choose which components to import, drastically lowering your build size. New projects created with the Vue CLI plugin have this enabled by default. Treeshaking will only work with Webpack 4 in production mode. This is automatic when using Vue CLI.

Does Vuetify support Vue 3?

The current version of Vuetify does not support Vue 3. Support for Vue 3 will come with the release of Vuetify v3 . When creating a new project, please ensure you selected Vue 2 from the Vue CLI prompts, or that you are installing to an existing Vue 2 project.


2 Answers

À la carte is an English language loan phrase meaning "according to the menu." It refers to "food that can be ordered as separate items, rather than part of a set meal."

So if you use a-la-carte components, it means that you only include components that you need (want) to use, instead of getting all of them

Vuetify example:

Vuetify allows you to easily import only what you need, drastically lowering its footprint.

import {  Vuetify,  VApp,  VNavigationDrawer,  VFooter,  VList,  VBtn } from 'vuetify'  Vue.use(Vuetify, {  components: {    VApp,    VNavigationDrawer,    VFooter,    VList,    VBtn  } }) 

EDIT 2018/11/14:

Since vuetify 1.3.0,
vuetify-loader (included in vuetify cli install)
automatically handles your application's a-la-carte needs, which means it will automatically import all Vuetify components as you use them.

like image 173
Traxo Avatar answered Oct 02 '22 19:10

Traxo


First of all, you didn't find that option in the docs because it's in fact a vuetify plugin option. When "a-la-carte" components are enabled, the file /plugins/vuetify.js should contain:

import Vue from 'vue' import {  Vuetify,  VApp,  //other vuetify components } from 'vuetify'  Vue.use(Vuetify, {  components: {    VApp,    //other vuetify components  } }) 

and your babel.config.js file should be changed to prevent a full vuetify import with the "transform-imports" plugin.

Second, up until vuetify v1.3.0-alpha.0, "a la carte" was useful if your wanted to minimize your webpack vendor bundle, but it's quite tedious to have to selectively import vuetify components, especially during development. Plus, Webpack has evolved a lot since the introduction of "a la carte components".

For these reasons, as of vuetify 1.3.0-alpha.0, the dev team is working on a way to completely eliminate the need for a la carte components by using Webpack 4 tree shaking features (AKA dead code elimination) through vuetify-loader. Those features are expected to be added to the vuetify official plugin in order to get automatic "a la carte components".

So, to address your second question (if you should use a-la-carte), the answer is no, not anymore. Here's how you can setup your vue-cli 3 project by yourself to use this feature:

  • Install vuetify-loader as a dev dependency: npm install -D vuetify-loader
  • Import vuetify from 'vuetify/lib' instead of 'vuetify' in your vuetify.js file.

code:

import Vue from 'vue' import Vuetify from 'vuetify/lib'  Vue.use(Vuetify) 
  • Register vuetify-loader as a webpack plugin in your vue.config.js file (if it doesn't exist, create the file in your project's root).

code:

const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin')  module.exports = {    configureWebpack: {      plugins: [         new VuetifyLoaderPlugin(),     ]    }  // ...other vue-cli plugin options... }  
  • In case you were already using a-la-carte, make sure to remove "transform-imports" from the list of your babel plugins (typically found in babel.config.js)

  • Remember that tree shaking is set to work only in production mode, so if you're using the flag --watch or --mode development with your npm run build command, you shoudln't expect your bundle size to be reduced

I hope it helps

like image 37
L.J.M BETE Avatar answered Oct 02 '22 18:10

L.J.M BETE