https://www.npmjs.com/package/rootpath
//BEFORE // from $HOME_PROJECT/lib/math/ var myLib = require('../myLibrary'); var myUtils = require('../../utils/myUtils'); var myTest = require('../../test/myTest'); //AFTER // from $HOME_PROJECT/lib/math/ require('rootpath')(); var myLib = require('lib/myLibrary'); var myUtils = require('utils/myUtils'); var myTest = require('test/myTest');
在vsphere rest sdk sample看到的一個用法,這對於library更動目錄時不需要再改寫require path非常方便,但是須注意webpack使用時,應該用webpack resolve configuration來處理