From Command Line
Install dependency locally
npm install live-server
Create folder public with index.html and file called run-server.js. Here's the structure:
node_modules/
public/
index.html
run-server.js
Content of run-server.js:
var liveServer = require("live-server"); var params = { port: 8181, // Set the server port. Defaults to 8080. host: "0.0.0.0", // Set the address to bind to root: "./public", // Set root directory that's being served. Defaults to cwd. open: true, // When false, it won't load your browser by default. logLevel: 2, // 0 = errors only, 1 = some, 2 = lots }; liveServer.start(params);
in console run live-server
node run-server.jsor on Linux
node node_modules/.bin/live-server --open=public/
Using package.json
in consolenpm init npm install -D live-server npm install --save cowsay
this will generate file package.json:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "cowsay -b mooooooooo >> index.html && live-server --port=8085"
},
"author": "",
"license": "ISC",
"devDependencies": {
"live-server": "^1.2.0"
},
"dependencies": {
"cowsay": "^1.2.1"
}
}
to create index.html and run server
npm test
if you want to do clone a git repo and run in in live-server replace yellow line with:
"test": "git clone https://github.com/nikola-bodrozic/Bootstrap-Boilerplate-v3.3.7.git tb337 && live-server --watch=tb337 --open=tb337 --ignore=tb337/.git"
this will watch for file changes in tb337 folder but not in tb337/.git folder
another example
{
"scripts": {
"less-gen": "lessc -l public/css/style.less && lessc public/css/style.less public/css/style.css && exit 0",
"lint-css": "csslint --ignore=ids,order-alphabetical public/css && exit 0",
"lint-js": "eslint public/js && exit 0",
"test": "node run-w3cvalid.js && npm run less-gen && npm run lint-css && npm run lint-js && echo \"Tests finished\" && exit 0",
"start": "node run-server.js"
},
"dependencies": {
"csslint": "^1.0.5",
"html-validator": "^2.2.3",
"less": "^3.0.0-alpha.3",
"live-server": "^1.2.0"
},
"devDependencies": {
"eslint": "^4.10.0"
}
}
Inside script.test and script.start we can run js files.
No comments:
Post a Comment