告诉npm在另一个目录中寻找node_modules [英] Tell npm to look for node_modules inside a different dir
本文介绍了告诉npm在另一个目录中寻找node_modules的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
npm
在当前目录及其所有父目录中查找node_modules
,然后在全局位置中查找.我当前建议的目录结构是:
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:
- 全球
- package.json
- node_modules/
- global
- package.json
- node_modules/
- gulpfile.coffee
- gulpfile.coffee
但这不是
npm
通常在此寻找的地方.我可以设置一个环境变量来处理此问题,还是可以告诉它在特定目录中查找的一种方法?谢谢!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!推荐答案
尝试以下操作以在gulp中设置NODE_PATH.
Try the following to set NODE_PATH in gulp.
.pipe(preprocess({context: { NODE_PATH: '$NODE_PATH:/path/to/other/dir'}}))
完整的示例如下所示.
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'}}))
这篇关于告诉npm在另一个目录中寻找node_modules的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文