Reputation: 1638
Despite all that's been written on dependency
vs. devDependency
, I'm still confused how to proceed for modules that are required for a 'build time' step before npm start
will work.
In my project, one must call gulp build
before npm start
will work. Examples of activities in the build step include transpilation and bundling. The official docs say specifically not to include transpilers in the dependencies section, but instead in the devDependencies section. Other best practices suggest that autogenerated code should be kept out of git / modules. Put these together, though, and I don't understand what to do: someone can't download and run my module without transpiling and building, and those steps can't be completed without the transpiler/bundler/etc. being in the dependencies section. (Or else "running" is considered "development"?)
How are node projects properly structured for this situation?
Upvotes: 3
Views: 2620
Reputation: 1398
Anything that is not required to run your app in production mode should be a devDependency. This will include all of your build tools.
Your gulp build
should run on your automatic build server, and produce whatever is needed to run your application (transpiled JS or a webpack bundle, for example). Your build script should be something like:
npm install
gulp build
# or better make it a script in package.json
# npm run build
# remove devDependencies - no longer needed
npm prune --production
npm start
Your package.json would contain something like:
{
...
"scripts": {
"build": "gulp build",
"start": "NODE_ENV=production node lib/index"
}
...
}
In this contrived example the entry point is lib/index.
Upvotes: 5