package.jsonnpm-live-server

how to run live-server inside project using scripts property of package.json file


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.


Solution

  • 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"
    }