Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between plugins and dependencies in the Vue.js UI?

Tags:

vue.js

vue-cli

When using the ui you have the option of installing dependencies and plugins.

I am confused about the difference between both of these.

For instance, I can install axios as a dependency and a plugin.

Do I need to do both? Why do one over the other?

My current understanding is that dependency is just that, it adds a package to your project while a plugin will add configuration as well.

Am I correct in thinking that?

like image 493
Taylor Avatar asked Apr 29 '19 18:04

Taylor


People also ask

What is plugins in vue JS?

A plugin is defined as either an object that exposes an install() method, or simply a function that acts as the install function itself. The install function receives the app instance along with additional options passed to app.use() , if any: const myPlugin = { install(app, options) { // configure the app } }

How do I use plugins in vue CLI?

If a plugin is already installed, you can skip the installation and only invoke its generator with the vue invoke command. The command takes the same arguments as vue add . If for some reason your plugins are listed in a package. json file other than the one located in your project, you can set the vuePlugins.

How do I remove plugins from vue ui?

Under "Dependencies" (second tab on the left of vue ui) you'll find all plugins listed. And on the right of each plugin there is a little trash icon, which removes the respective plugin.

How do I use plugins in vue 3?

To add it to our plugin, we can go to MyFirstPlugin. js and add it like this inside of our install method. import MyHeader from "./components/MyHeader. vue";export default { install: (app, options) => { /* declare global component */ app.

What is the difference between a plugin and a dependency?

A plugin is an extension to Maven, something used to produce your artifact (maven-jar-plugin for an example, is used to, you guess it, make a jar out of your compiled classes and resources). A dependency is a library that is needed by the application you are building, at compile and/or test and/or runtime time.

Should I use Vue for CSS-in-JS?

While you gain access to the dynamism of JavaScript while constructing your styles, the tradeoff is often increased bundle size and runtime cost. If you are a fan of CSS-in-JS, many of the popular CSS-in-JS libraries support Vue (e.g. styled-components-vue and vue-emotion ).

What is the difference between AngularJS and Vue JS?

AngularJS uses two-way binding between scopes, while Vue enforces a one-way data flow between components. This makes the flow of data easier to reason about in non-trivial applications. Directives vs Components. Vue has a clearer separation between directives and components.

What is the use of Vue CLI?

Vue CLI aims to be the standard tooling baseline for the Vue ecosystem. It ensures the various build tools work smoothly together with sensible defaults so you can focus on writing your app instead of spending hours wrangling with configurations.


2 Answers

A plugin is exactly what you described. It 'plugs into' another piece of software and adds functionality. A dependency on the other hand means that your software simply depends on something to function correctly - usually code.

In your axios example:

The axios plugin installs another prototype property on your Vue instance (this.$axios.. or whatever it is called) so it definitely adds a feature to Vue.

You could also only use Axios by itself and import it in the files you need import axios from 'axios'. You don't add any feature to Vue itself - you just use another software within your app. Axios here is a dependency.

like image 91
MarcRo Avatar answered May 28 '23 15:05

MarcRo


I will probably not be completely correct, but my understanding is

Plugins vs Dependencies

Command line

  • dependencies are installed via the command line as npm install <name> or npm install --save <name> to add the dependency to package.json

  • plugins are installed via the command line as vue add @scope/vue-cli-plugin-<name> or with the shorthand vue add @scope/<name>

Installation

  • dependencies are placed into your projects node_modules folder

  • plugins will invoke the generator.js script of the plugin being installed. This generator.js may add dependencies to package.json, add import statements to files in your project, add/alter existing components, or any of the various things listed under the generator api docs

Usage

  • dependencies will need to be imported into any file you use them in, or imported globally, before they are able to be used

  • plugins often will have already set up global imports, making them available in every file. Plugins will also often add additional scripts to package.json (which show up as tasks in the vue ui)

like image 40
Ace.C Avatar answered May 28 '23 14:05

Ace.C