How do I install bower using package.json and npm install? - npm

How do I install bower using package.json and npm?
I have my package.json file setup like so..
{
"name": "myprogramname",
"version": "0.0.1",
"devDependencies": {
"bower": "1.2.6"
//other dependencies are listed as well
}
}
from the command line I run
npm install
It installs all of my dependencies in devDependencies except bower. Any reason for this?
Also,
which bower
returns nothing

Npm did actually install Bower but not globally. If you check your node_modules/ directory, it should be there.
Therefore, it IS accessible for other developers at this path:
node_modules/bower/bin/bower

A neater way to use a local install of bower is shown here.
Basically you need to use "npm run bower install" instead of "bower install" if you install bower through NPM locally and don't have it installed globally on your computer.

Related

package.json disable "npm install"

Is there any way to disable the command npm install or npm i on a project through the package.json config?
I'm using yarn to add and install npm dependencies, and I want to force to not use npm install

Ensure only dependencies are in node modules and not dev dependencies

I have a script in my package.json like so:
"build": "npm install && npm prune --production"
This command will install all dependencies and then remove the devDependencies.
Is there a command to do this in one hit? For example, a command that ensures that production-level dependencies are the only ones existing in node_modules?
The solution is npm install --only=prod.

npm install - how to trigger npm task as a post-install hook?

After npm install is run I would like to run
npm run jspm install
I have package.json
"scripts": {
"postinstall" : "npm run jspm install",
"jspm": "jspm"
},
This throws an error since npm run jspm install gets passed to node rather than npm. What's the correct way to do this?
There doesn't seem to be a reason to reference the jspm script. You can refer to jspm directly in the postinstall script:
"postinstall" : "jspm install",

Babel doesn't run from npm script

I have the babel cli installed on my machine using:
npm install -g babel-cli
When I run this command I get the desired output. i.e out.js is created
babel script.js --out-file out.js
but when I try to run that command via npm I get an error saying
The CLI has been moved into the package `babel-cli`.
$ npm install -g babel-cli
Here's the package.json:
{
"name": "youtubeapiloader",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"compile": "babel -g src/youtube-api-loader.js --out-file youtube-api.js",
"prepublish": "npm run compile"
},
"devDependencies": {
"babel": "^6.1.18"
}
}
Have you tried installing babel-cli as a devDependency already?
I managed to get it working like this. Just do
npm install babel-cli --save-dev
Perhaps you might also need babel-core, but I can not remember correctly.
Note that if you want to run this using Travis CI you might still need to globally install babel-cli using a custom installation step within your .travis.yml. e.g.
language: node_js
sudo: false
node_js:
- "5.0"
install:
- npm install -g babel-cli
- npm install

How to install bower dependencies using npm install?

I want npm install to install the bower dependencies as well. I have a bower.json file containing frontend packages and there is package.json file which contains the backend packages. After i run npm install, node_modules are installed whereas the dependencies mentioned in bower.json file are not installed.
I don't want to use bower install rather I want to do all this with npm install command.
It's quite simple. If you have bower listed in package.json as dependency you may add postinstall script to your package.json as follows:
"scripts": {
"postinstall": "bower install"
}
and running npm install will launch also bower install automatically