Expressive Node.js + Vue.js framework with hot reload
Install current version from Node.js (not LTS): https://nodejs.org/en/download/current
- git clone https://github.com/timonSchenzel/nodue.git
- cd nodue
- npm install
- Compile assets with Laravel Mix:
npm run dev
(this will watch for changes)npm run webpack
will compile assets a single time.
You have some options here, if you want to use option 3 or 4 install nodemon globally (npm install -g nodemon
):
(when also running npm run dev
, run the following commands in another screen/tab)
npm run nodue
- This will boot Nodue (for production)npm run nodue hot
- This will boot Nodue with hot reload featurenpm run nodue:dev
- This will boot Nodue with nodemon, nodemon will watch every change (excluded controller/view files) and will reboot Nodue automaticaly when changing something. And will start Laravel Mix.npm run nodue-dev
- This will boot Nodue with nodemon, nodemon will watch every change (excluded controller/view files) and will reboot Nodue automaticaly when changing something.
For example: you want to create a welcome page.
- Visit
routes.js
in the root - Add
route.get('/', 'PagesController@home');
- url/
will be mapped toPagesController
and call his methodhome
. - Create the controller file
PagesController.js
within the folder:app/http/controllers
:
module.exports = class PagesController extends Controller
{
home()
{
return view('pages.home', {
title: 'Nodue',
text: 'This is great!',
items: [
'Nodue',
'Vue.js',
'Node.js',
],
showDiv: true,
});
}
}
- Create the view file
home.vue
withinresources/views/pages
:
<div>
<h1>{{ title }}</h1>
<p>{{ text }}</p>
<ul>
<li
v-for="item in items"
v-text="item"
></li>
</ul>
<hr>
<button @click="testConsoleLog">console.log - Hello World</button>
<button @click="toggleDivVisibility">Toggle div visibility</button>
<div v-show="showDiv">
Toggle Me.
</div>
</div>
- View behavior files
View behavior will give us the possibility interact with a view without reloading the page. Something like toggle the visibility from a div element. To create a view behavior file follow this convention: [name-from-the-view-file].js
.
- Create the view behavior file
home.js
withinresources/views/pages
:
{
created()
{
console.log('created');
},
methods: {
testConsoleLog()
{
console.log('Hello World');
},
toggleDivVisibility()
{
this.showDiv = this.showDiv ? false : true;
}
}
}
- View files and view behavior files will use Vue.js, for more information view: https://vuejs.org/v2/guide/.
The best part.
- For example: in
PagesController@home
, addHot Reloaded
to theitems
array and save it. - Our open
home.vue
and add some styling like<p style="color: red;">{{ text }}</p>
and hit save.