Type of package installation with npm:
npm install -g packageName Install global
npm install --save -dev pacakgeName Install locally
npm install --save packageName Install locally
when run npm install --production or env variable NODE_ENV value is production, only packages in dependencies will be install, but packages in devDependencies will not.
npm install -g packageName
npm install --save-dev packageName
npm install --save packageName
Create a new folder for this project
run npm init in the work folder above mentioned
npm init
after we run npm init, we will get a new file named package.json,the file content as bellow:
{
  "name": "typescript-learn",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}
now we should insert code line "type": "module", in package.json to support ES5
After we insert the new code line ,the package.json as bellow:
{
  "name": "typescript-learn",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}
note: let the browser support ES5 ,we can insert line as bellow:
<script type="module" src="xxxxx.js"></script>
Now, we will install typescript dependency:
npm install typescript --save-dev
This demo location: code-repo/learn-test/typescript-learn
Git link: 
 

 
    
Top comments (0)