Tell npm to look for node_modules inside a different dir

天大地大妈咪最大 提交于 2019-12-08 13:28:56

问题


npm looks for node_modules in the current directory, and all its parent directories, then looks in the global location. My current proposed dir structure is:

  • global
    • package.json
    • node_modules/
  • project-1
    • gulpfile.coffee
  • project-2
    • gulpfile.coffee

But this isn't where npm normally looks for this. Is there an environment variable I can set to deal with this, or a way I can tell it to look in a specific directory? Thanks!


回答1:


Try the following to set NODE_PATH in gulp.

.pipe(preprocess({context: { NODE_PATH: '$NODE_PATH:/path/to/other/dir'}}))

A full example would look like the following.

var preprocess = require('gulp-preprocess');

gulp.task('html', function() {
  gulp.src('./app/*.html')
    .pipe(preprocess({context: { NODE_PATH: '$NODE_PATH:/path/to/other/dir'}})) //To set environment variables in-line 
    .pipe(gulp.dest('./dist/'))
});

The above 2 examples add to the node path if it is set. If you want to just set it do the following.

.pipe(preprocess({context: { NODE_PATH: '/path/to/other/dir'}}))



回答2:


There is a NODE_PATH environment variable you can set.



来源:https://stackoverflow.com/questions/29132387/tell-npm-to-look-for-node-modules-inside-a-different-dir

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!