📌  相关文章
📜  adonisjs livereload - Javascript (1)

📅  最后修改于: 2023-12-03 14:39:03.054000             🧑  作者: Mango

AdonisJS Livereload

AdonisJS is a powerful Node.js web framework that makes building web applications with JavaScript an easy task. One of the great features of AdonisJS is the ability to use live reloading to quickly see your changes as you develop your application.

What is Live Reload?

Live reload is a feature that automatically refreshes a web page when changes are made to the underlying code. This allows the developer to see their changes in real-time, without having to manually refresh the page every time a change is made.

How to Use AdonisJS Livereload

To use livereload in an AdonisJS application, you will need to install the following packages:

npm install adonis-lucid
npm install adonisjs-cli
npm install adonis-livereload

After installing these packages, you will need to add the following code to your AdonisJS application:

// Start the livereload server
const livereload = require('adonis-livereload')
const Env = use('Env')

livereload.init({
  debug: Env.get('APP_DEBUG') === 'true',
  port: Env.get('LIVERELOAD_PORT', 35729),
  files: [
    'public/**/*.css',
    'public/**/*.js',
    'app/**/*.js',
    'resources/views/**/*.mustache'
  ]
})

This code will start the livereload server and configure it to watch for changes in the CSS, JavaScript, and Mustache template files in your AdonisJS application.

Conclusion

In conclusion, live reloading is a powerful feature that can help improve the workflow of developing web applications with AdonisJS. By allowing developers to see their changes in real-time, live reloading can save time and improve the quality of the final product. Use the above code snippet to get started with AdonisJS livereload today!