Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`gulp build` and dependency vs. devDependency for node

Tags:

node.js

npm

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?

like image 455
jdowdell Avatar asked May 17 '26 04:05

jdowdell


1 Answers

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.

like image 51
john_omalley Avatar answered May 18 '26 21:05

john_omalley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!