Installing Vue+Vuex+Vuetify
This short guide will hopefully clear up how node, vue, @vue-cli, and vue plugins all work together.
Background
These are the technologies needed to get a Vue single page application (SPA) going:
- Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Think about it as the Python shell, you use the Python shell to run .py files. Node is used to run .js files
- npm is the default package manager for Node.js. Packages are bits of code that are made to solve a particular problem.
- npx Executes a command (
npx <command>) either from a local node_modules/.bin, or from a central cache, installing any packages needed in order for<command>to run.<command>is typically composed of a package name and a command defined in the package, for examplevue create app. The general rule is to only usenpxto quickly try out packages. You shouldn’t use it to develop an app since it uses whatever package version is active at the moment and this can make tracking dependency errors more difficult when doing long term development. - vue is a package containing all the code needed to build user interfaces using the
vueframework. - @vue/cli is a package used to quickly scaffold
vueSPAs. It includesvueand command line programs (tooling) to build setups for a modern frontend workflow. It also includes capabilities to run a hot-reload development server, to lint-on-save, and to make production-ready builds. - vue plugins usually add global-level functionality to Vue. In our case we are focusing on
vuex(for state management) andvuetify(UI framework). - locally vs globally installed JavaScript packages are two ways to install packages. Following the general rule that it is better to install packages locally, we assume a local installation for all packages. Vue’s documentation covers the global installation alternative.
Creating your application using locally installed packages (Windows)
-
Create a folder for your application,
mkdir App. -
Move into
Appand install vue- Option 1: If you are a novice (like me) and want to start a brand new SPA, install the CLI since it includes
vueplus extra tooling to quickly scaffold most of your project,npm install @vue/cli - Option 2: If you are an advanced user and want to use vue in your existing application, use
npm install vue. But if you were, you wouldn’t be reading this since you already have an SPA and you just want to installvueand not all the included tooling in@vue/cli.
- Option 1: If you are a novice (like me) and want to start a brand new SPA, install the CLI since it includes
-
Notice that
node_moduleswas created inApp. At this point, it contains the@vue/clipackage and all its required packages. -
Inside
App, create avueapplication using the commandnode node_modules\@vue\cli\bin\vue create appvue. Note that in this step we are usingnodeto run thevue.jsfile innode_modules\@vue\cli\bin\withcreateas the command andappvueas the argument. You can actually see the code inside ofvue.jsto see how the CLI is setup. Also note that the path tovue.jsis relative since you are insideApp. Finally, when installingappvue, make sure to includevuexin the optional plugins to install. -
Notice that
appvuewas created inApp. Insideappvueare all the directories (scaffolding) needed forappvue. -
Move into
appvueand install thevuetifyplugin using the commandnode absolutepathto\App\node_modules\@vue\cli\bin\vue add vuetify. I specified the absolute path tovue.js(the samevue.jswe used to createappvue) but I guess you can also use a relative path. Notice thatvuetifywas added tonode_modulesinappvue.
You now have a working Vue+vuex+vuetify SPA ready to go!