node.js - use npm with different configuration than package.json -


i have complex production environment driven package.json.

the problem: wish install locally additional packages, keep eye on list , versions of them.

solution (how there): point npm use config file, excluded git, keep private dependencies. use file add packages local node_modules npm install. need change configuration context of npm.

i have no clue how point npm use different config (something gulp -gulpfile).

update comments dev-dependencies not way go. use stuff 90% of other developers not need installed in node_modules (in fact break environment in strange way updating dev-dependencies in git-shared core project-wide package.json).

first of all, should know trying not weird, against lot of practices , patterns in nodejs.

nevertheless, it's possible , if it's done right never cause trouble you, or other developers in different platforms.

you can use little inspired on meteor build flow. let's break project conceptually 2 different parts:

  • base: handles project initialization.
  • internal original project.

project structure:

- build.js (base build script) - package.json (base package) - internal/   - package.template.json (project package template)   - app.js (your actual project files)   - [...]  (your actual project files) 

the starting point create package.json file base, in root of project. package hold dependencies build package file of internal project. advise use mozilla's convict ensure configurations done correctly using envs. goal here write package.json file @ runtime.

let's assume in environment there's environment variable use_weird_modules="true". can use fact in base project define modules going install using build.js file. can read , edit in runtime. when it's ready, save internal/package.json. then, run npm install inside internal/ directory.


build.js

let pkg = require('./package.template.json');      if(process.env.use_weird_modules) {      // install weird packages             pkg.dependencies.some_dev_package = '^v0.2.2';     pkg.dependencies.another_dev_package = '^v0.2.2';   }  // don't forget save package.json in end fs.writefilesync('./internal/package.json', json.stringify(pkg, null, 2), 'utf8'); 

don't forget put internal/package.json file in repository ignore file (ex: gitignore).

to minimize impact of brute changes in project, can define in main package.json building routine in postinstall script. allow simple npm install in root of project handle steps internally.

something this:

package.json

{   [...]   "scripts": {     "postinstall": "node build.js && cd internal/ && npm install",     "start": "node internal/app.js"   }   [...] } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -