1

I have project and i have installed live-server using npm install --save-dev live-server I want to now run live-server using scripts property in package.json file. I know we can run it globally but i want to run live-server within the project folder.

Smith
  • 1,266
  • 13
  • 31

2 Answers2

1

i dont know why you want to do that, but you can add this on package.json

 "scripts": {
    "live": "live-server"
  }

and then run with npm like this:

npm run live

here's an example of package.json:

{
  "name": "tailwindcss",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "tailwindcss": "^1.4.6"
  },
  "devDependencies": {},
  "scripts": {
    "build:css": "tailwind build src/style.css -o style.css",
    "live": "live-server"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
0

1- if you want to hot reload a file like index.html with live-reload try to add in the script section of package.json

package.json

{
 "name": "frontend",
 "version": "1.0.0",
 "description": "",
 "scripts": {
   "serve": "live-server src/index.html --verbose",
   "test": "echo \"Error: no test specified\" && exit 1"
  },
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"live-server": "^1.2.2"
}
}

2- if you want hot reload for all files on a folder add in script section of package.json instead of src/index.html just leave src folder

"scripts": {
   "serve": "live-server src --verbose",
   "test": "echo \"Error: no test specified\" && exit 1"
  },

This will hot reload any changes on all files inside of src folder include js,html and etc files type...

hope it will help....