From cce10b8e92b162386373d80d2f0c373c0af87ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?h=CE=B1rsh=20v=CE=B1ir=CE=B1gi?= Date: Thu, 24 Oct 2024 01:18:52 +0530 Subject: [PATCH] switched to minimal live reload server. --- README.md | 2 +- docs/readme.md | 2 +- tailwind/app.js | 18 ++++++++++++++++-- tailwind/package.json | 3 ++- template/app.js | 18 ++++++++++++++++-- template/package.json | 5 +++-- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ce641ca..fe0615d 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ To know about the project structure read about files included in this code block - Excellent terminal user interface ✅ - Post this project to npmjs website. ✅ - Add Tailwind CSS support. ✅ -- Use a lightweight server for EJS live reloading. ⏩ +- Use a lightweight server for EJS live reloading. ✅ - Prompt `package.json` file's details from user. ⏩ - Custom local template feature ⏩ diff --git a/docs/readme.md b/docs/readme.md index 8b55b96..f2aad79 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -95,7 +95,7 @@ To know about the project structure read about files included in this code block - Excellent terminal user interface ✅ - Post this project to npmjs website. ✅ - Add Tailwind CSS support. ✅ -- Use a lightweight server for EJS live reloading. ⏩ +- Use a lightweight server for EJS live reloading. ✅ - Prompt `package.json` file's details from user. ⏩ - Custom local template feature ⏩ diff --git a/tailwind/app.js b/tailwind/app.js index 5c89b98..023c626 100644 --- a/tailwind/app.js +++ b/tailwind/app.js @@ -4,6 +4,20 @@ const express = require('express') const app = express() const port = 3000 +/** + * Code snippet for hot reloadings. + * You can wipe this at production. + */ +const livereload = require("livereload") +const connectlivereload = require("connect-livereload") +app.use(connectlivereload()) +const livereloadserver = livereload.createServer() +livereloadserver.watch(path.join(__dirname, "views")) +livereloadserver.watch(path.join(__dirname, "public")) +livereloadserver.server.once("connection", () => { + setTimeout(() => livereloadserver.refresh("/"), 100) +}) + app.set('view engine', 'ejs') app.set('views', path.join(__dirname, 'views')) app.use(express.static('public')) @@ -20,8 +34,8 @@ app.get('/', (req, res) => res.render('home')) app.listen(port, () => { /** - * The above code is exclusivly for dev purpose. - * You can replace this function. + * Code snippet for dev purpose. + * You can wipe this at production. */ const netface = require('./utils/netface') const linkfaces = netface.ipv4s() diff --git a/tailwind/package.json b/tailwind/package.json index 1d0475c..becabd2 100644 --- a/tailwind/package.json +++ b/tailwind/package.json @@ -15,8 +15,9 @@ }, "devDependencies": { "nodemon": "^3.1.7", + "livereload": "^0.9.3", + "connect-livereload": "^0.6.1", "npm-run-all2": "^7.0.0", - "browser-sync": "^3.0.3", "tailwindcss": "^3.4.13" } } diff --git a/template/app.js b/template/app.js index 27e1ac9..a55b893 100644 --- a/template/app.js +++ b/template/app.js @@ -4,6 +4,20 @@ const express = require('express') const app = express() const port = 3000 +/** + * Code snippet for hot reloadings. + * You can wipe this at production. + */ +const livereload = require("livereload") +const connectlivereload = require("connect-livereload") +app.use(connectlivereload()) +const livereloadserver = livereload.createServer() +livereloadserver.watch(path.join(__dirname, "views")) +livereloadserver.watch(path.join(__dirname, "public")) +livereloadserver.server.once("connection", () => { + setTimeout(() => livereloadserver.refresh("/"), 100) +}) + app.set('view engine', 'ejs') app.use(express.static('public')) app.use('/colors', express.static( @@ -19,8 +33,8 @@ app.get('/', (req, res) => res.render('home')) app.listen(port, () => { /** - * The above code is exclusivly for dev purpose. - * You can replace this function. + * Code snippet for dev purpose. + * You can wipe this at production. */ const netface = require('./utils/netface') const linkfaces = netface.ipv4s() diff --git a/template/package.json b/template/package.json index bb4e727..b2880a1 100644 --- a/template/package.json +++ b/template/package.json @@ -14,7 +14,8 @@ }, "devDependencies": { "nodemon": "^3.1.7", - "npm-run-all2": "^7.0.0", - "browser-sync": "^3.0.3" + "livereload": "^0.9.3", + "connect-livereload": "^0.6.1", + "npm-run-all2": "^7.0.0" } }