Álvaro González
Álvaro González

Reputation: 146390

Save gulp plug-ins in project

I'm trying out Gulp to automate the creation of a ZIP file to distribute my PHP project. I'm not very familiar yet with npm.

I've already realised that I'll need several plug-ins (gulp-asvn and gulp-zip so far). I've installed them following the instructions provided in the official site, e.g.:

npm install --save-dev gulp-asvn

My node_modules directory is already as large as the actual codebase and, being just an internal developer tool, I wouldn't like to commit it into my Subversion repository if I don't have to.

Is there a way to tell npm what packages are required and have the possibility to get them installed at once, so when others checkout the code don't have too many problems configuring their environment? In PHP's Composer you'd have a composer.json file but I'm not sure if package.json is equivalent to that, and npm install has not created it anyway.

Upvotes: 0

Views: 74

Answers (4)

Álvaro González
Álvaro González

Reputation: 146390

Project dependencies are stored in a package.json file but npm install --save-dev will not create the file if it doesn't exist, or even warn that it doesn't exist and the --save-dev switch will have no effect. (In this sense, it behaves differently than Composer, which just creates its composer.json file automatically.)

The bare minimum configuration for a project that's not a redistributable JavaScript library can be as small as this:

{
  "private": true
}

Upvotes: 1

Sumit Sahay
Sumit Sahay

Reputation: 514

Node modules are installed in the folder if that has file package.json. The package.json has many fields which tells about the author, git repository etc.

There is one important field here, which is dependencies: that basically lists the node modules that are required to run this project. When npm install somePackage --save-dev is run, It tries to find package.json and saves it as a dependency in it while also downloading the module.

You can create package.json by writing npm init and listing all the node modules in the dependencies

"dependencies": {
  "gulp-asvn": "^0.4.5",
  "....." : ".."
},

and run npm install.

You can also save dependencies by individually running npm install --save-dev gulp-asvn and other packages. It will be then added in your package.json

Upvotes: 1

Tushar Arora
Tushar Arora

Reputation: 1146

Referring from composer docs -

This idea is not new and Composer is strongly inspired by node's npm and ruby's bundler.

You can use this command to make sure that you ignore node_modules folder to be committed to svn repo.

  svn propedit svn:ignore . 

Your default text editor will pop up and you can add node_modules directory to be ignored according to your folder structure.

Now as you know that npm 'may' not be around for a long time. To be on safe side you can create another repo for node_modules.

Also you can keep your dependencies and dev-dependencies differentiated and kept separately in your package.json file.

  npm install

P.S. - Above command is more than enough for someone else to configure their environment. If not you can use environment variables for api keys and other environment dependent constants.

Upvotes: 1

MarcoL
MarcoL

Reputation: 9989

TLDR If your dependencies are named in the package.json file your fine. The user has just to say to npm to install them: npm install.

Long story

Say you have your package.json file.

Now you do

npm install --save-dev gulp-asvn

This will install the gulp-asvn package and add it to the package.json file as devDependencies.

If you're ignoring the node_modules from the checked files, the user has just to say npm to install all the dependencies and you're fine.

npm install

This command looks inside the package.json, resolves all the dependencies and the dev dependencies, pull them down from the npm registry and install them.

Upvotes: 1

Related Questions