提醒:本文发布于 3 年前 ,文中所描述的信息可能已发生改变,请谨慎使用。

require 依赖

项目放置在 /project

模块依赖放在 /node_modules

即可保证项目内依赖可以被找到
https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders

For example, if the file at '/home/ry/projects/foo.js' called require('bar.js'), then Node.js would look in the following locations, in this order:

/home/ry/projects/node_modules/bar.js
/home/ry/node_modules/bar.js
/home/node_modules/bar.js
/node_modules/bar.js
This allows programs to localize their dependencies, so that they do not clash.

npm script

配置 export PATH=${PATH}:/node_modules/.bin 即可正常执行 npm script

https://docs.npmjs.com/misc/scripts#path

If you depend on modules that define executable scripts, like test suites, then those executables will be added to the PATH for executing the scripts. So, if your package.json has this:

{ "name" : "foo"
, "dependencies" : { "bar" : "0.1.x" }
, "scripts": { "start" : "bar ./test" } }
then you could run npm start to execute the bar script, which is exported into the node_modules/.bin directory on npm install.

http://stackoverflow.com/questions/14742553/npm-local-install-package-to-custom-location

Every configurable attribute of npm can be set in any of six different places. In order of priority:

Command-Line Flags: --prefix ./vendor/node_modules
Environment Variables: NPM_CONFIG_PREFIX=./vendor/node_modules
User Config File: $HOME/.npmrc or userconfig param
Global Config File: $PREFIX/etc/npmrc or userconfig param
Built-In Config File: path/to/npm/itself/npmrc
Default Config: node_modules/npmconf/config-defs.js

webpack 构建依赖

config.resolve.modulesDirectories = ['/node_modules']

awesome-typescript-loader missing babel-core

tsconfig.json 增加 babelCore: "/node_modules/babel-core"

https://github.com/s-panferov/awesome-typescript-loader#babelcore-string-defaultundefined

PS

本需求主要目标
虚拟机或docker下挂在windows目录是通过smb方式挂载的,无法使用符号链接,WTF!