Just a proof of concept of using local_modules
to solve the "Better local require() paths" problem.
It also helps you write true re-usable sub-modules.
Just like any node app:
npm install
npm start
_Note: if you run npm 3+, you need to remove the preinstall
script in package.json
Note: This apps does nothing useful, it'll just print a useless array.
- Create a new folder for your module, such as
local_modules/my-module
(can be anything else) - Create a
package.json
file for it, along with the usualREADME.md
- Adds its dependencies in its own
package.json
- Write the module (duh)
- Install this local package in your top level module using:
npm install --save ./local_modules/my-new-module
. - ????
- Profit!
- Update whatever you want in your module (including dependencies)
- Bump your sub-module version in its
package.json
(important) - Simply run
npm update
ornpm update my-module
Or
Use rm-local-modules
as preinstall
script and simply run npm install
:
// package.json
{
"devDependencies": {
"rm-local-modules": "0.0.0"
},
"scripts": {
"preinstall": "rm-local-modules"
}
}
- No dirty hack,
require()
wrapper,../../../
paths, but purenpm
- Proper nested 3rd party dependency declaration
- Super easy to externalize your local module and make it a 3rd party library if you feel like it: it already is an independent node module.
TheFixed! And available sincenpm update
of local module is broken at the moment. Fingers crossed we can have it soon.npm 2.9.0
/iojs 2.0.0
.- A bug in
npm 3+
broke thepreinstall
lifecyle and therm-local-modules
inprescript
trick doesn't work.