DEV Community

luisdanielroviracontreras
luisdanielroviracontreras

Posted on

How to implement Vuenut in a project vue CLI with webpack

First of all, what is vuenut?

This library is created to manipulate and visualize the pattern of state management in the case of vuejs (Vuex). The main idea is to facilitate the development and maintenance of data in an application.

Start a project with the new cli 3 de vuejs

As any developer we love the latest, so we are going to implement vuenut in the latest version of the clue of vuejs.

First, if you have no idea what the cli de vue is, check the Documentacion Oficial

Vue CLI

is a full system for rapid Vue.js development, providing:

  • Interactive project scaffolding via @vue/cli.
  • Zero config rapid prototyping via @vue/cli + @vue/cli-service-global.
  • A runtime dependency (@vue/cli-service) that is:
  • Upgradeable;
  • Built on top of webpack, with sensible defaults;
  • Configurable via in-project config file;
  • Extensible via plugins
  • A rich collection of official plugins integrating the best tools in the frontend ecosystem.

Iniciar proyecto con vue CLI

Before initial a project with vue CLI we have to install it globally in our machine so that after it can do its magic, for this we execute this command (It does not matter where it is executed because it is installed globally)

 npm install -g @vue/cli
Enter fullscreen mode Exit fullscreen mode

The -g command indicates that you must install globally


Already with Vue CLI installed

Stop in the folder where you want to add the project (Not the project folder but a before vue CLI creates the folder when starting).

 vue create my-project-vuenut
Enter fullscreen mode Exit fullscreen mode

After executing this command, CLI asks us some questions.

  • Please pick a preset: (Use arrow keys)

  • Please pick a preset: default (babel, eslint)

you have to wait a while for the installed plugins and dependencies.

At the end of the installation we see a new folder with our project name that in this case is (my-project-vuenut) now if we enter the project that more or less has this structure.

 my-project-vuenut
 - node_modules
 - public
  favicon.ico
  index.html
 - src
 -- assets
 -- components
 App.vue
 main.js
 .gitignore
 package.json
 package-lock
Enter fullscreen mode Exit fullscreen mode

We will execute the command to initial the local server

npm run serve
Enter fullscreen mode Exit fullscreen mode

Install and implement Vuenut to the project

Now we have everything ready to implement Vuenut then get to work.

npm install vuenut
Enter fullscreen mode Exit fullscreen mode

When finished installing vuenut in our project we opened our main file that is (main.js) so that I use the library.

  • Add vuenut

To add vuenut we import the already installed dependency and the css styles you need to look great.

import Vuenut from 'vuenut'
import 'vuenut/dist/vuenut.css'
Enter fullscreen mode Exit fullscreen mode

And we have Vue use it to add the global level functionality to Vue

Vue.use(vuenut)
Enter fullscreen mode Exit fullscreen mode

Ready we have vuenut implemented, we just need to add the component within our App.vue file.

  • Add the component

To implement vuenut we open the App.vue archovo and within our component.

<vuenut/>
Enter fullscreen mode Exit fullscreen mode

The App.vue file would remain that way.

<template>
<div id="app">
 <vuenut/> <!-- Vuenut component -->
 <img src="./assets/logo.png">
 <HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template>
<script>
 import HelloWorld from './components/HelloWorld.vue'
 export default {
  name: 'app',
  components: {
   HelloWorld
  }
}
</script>
<style>
#app {
 font-family: 'Avenir', Helvetica, Arial, sans-serif;
 -webkit-font-smoothing: antialiased;
 -moz-osx-font-smoothing: grayscale;
 text-align: center;
 color: #2c3e50;
 margin-top: 60px;
}
</style>
Enter fullscreen mode Exit fullscreen mode

Ready and we just have to check our local server and see how vuenut is working in so few steps.

Vuenut is a library that needs Vuex to work so we can implement vuex in our project and see all the advantages vuenut offers us.

Install and deploy Vuex

we install the dependence on our project.

npm install vuex
Enter fullscreen mode Exit fullscreen mode

After finishing the installation, we import and implement.

import Vuex from 'vuex'
Vue.use(Vuex)
Enter fullscreen mode Exit fullscreen mode

we already have vuex in the project just missing add it to the vue to have our full store.

const store = new Vuex.Store({
 state: {
  myName: 'Vuenut'
 },
})
Enter fullscreen mode Exit fullscreen mode

And we add it to our instance of

new Vue({
 store,
 render: h => h(App)
}).$mount('#app')
Enter fullscreen mode Exit fullscreen mode

The App.vue file would be left this way

import Vue from 'vue'
import App from './App.vue'
import Vuenut from 'vuenut'
import 'vuenut/dist/vuenut.css'
import Vuex from 'vuex'
Vue.use(Vuex)
Vue.use(Vuenut)
const store = new Vuex.Store({
 state: {
   myName: 'Vuenut'
 },
})
Vue.config.productionTip = false
new Vue({
 store,
render: h => h(App)
}).$mount('#app')
Enter fullscreen mode Exit fullscreen mode

Ready we have our store implemented now we are going to add the vuenut.

<vuenut :store="$store.state"/>
Enter fullscreen mode Exit fullscreen mode

It is important that when adding the store to vuenut let’s put the reference to the state so that everything works perfectly

Ready we have our component with added vuex and it should look like this

Excellent we already have vuenut implemented and ready to be used in the project, some things you can do with vuenut.

  • Change store data at run time.
  • Save the store to use it later and replicate problems or bugs.
  • export store in .json to import it later or share it with a project partner.
  • Edit the entire store and change the structure of the data at run time.
  • Create functions to execute when starting the application or key combination. All the data of the library is stored in the storage so as not to have to repeat any configuration.
  • And many more features.

Vuenut is an open source library, we love to create and keep growing the community.

Links

Top comments (0)