This website requires JavaScript.

Tooling with NPM Scripts

Using the exercises

mkdir npmtooling
cd npmtooling
git clone --bare https://github.com/planetoftheweb/npmtooling.git .git
git config --bool core.bare false
git reset --hard
npm install # install all of the project dependencies.
git branch # to see all the branches available
git checkout 03_01b
git stash && git checkout 03_01e # go ahead and ignore any of your changes

Getting Started

Creating a live server

npm install xxx
# If the application needs the package in order to run as part of the final product, then you can use dash dash save.
npm install <package>@<version> # install specified version
# You can also save it as a development dependency, which means that it's something that you only need to run during the development phase.
npm install --save-dev live-server

Managing script types

Create a command in package.json

{
  "name": "npmTooling",
  "version": "0.0.1",
  "description": "Assets for my Tooling with NPM Scripts course at Lynda.com",
  "repository": {
    "type": "git",
    "url": "https://github.com/planetoftheweb/npmtooling.git"
  },
  "author": "Ray Villalobos",
  // create a command called serve dash dev and in here
  "scripts":{
    "serve-dev":"live-server builds/development",
    "prod-setup":"mkdirp builds/production/js",
    // using start is that when I run my command I don't need to add the word run.
    "start":"npm run serve-dev",
    // you can also run a script before one of these scripts with the special name. 
    "prestart": "npm run prod-setup"
  },
  "devDependencies": {
    "live-server": "^1.2.0"
  }
}

execute the command with npm run

npm run serve-dev

using start is that when I run my command I don't need to add the word run.

npm start

Tips

change port

If you will look at package.json file.

you will see something like this

 "start": "http-server -a localhost -p 8000"

This tells start a http-server at address of localhost on port 8000,ideally it should be present in your package.json but if it's not present you can include it in scripts section.

0条评论
avatar