1.0.7 • Published 7 years ago
@vibhus/locale_modules-poc v1.0.7
local_modules usage Proof of Concept
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.
Running the app
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.
Writing new sub modules
- Create a new folder for your module, such as
local_modules/my-module(can be anything else) - Create a
package.jsonfile 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!
Updating a local module
- Update whatever you want in your module (including dependencies)
- Bump your sub-module version in its
package.json(important) - Simply run
npm updateornpm 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"
}
}Pros
- 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.
Cons
TheFixed! And available sincenpm updateof 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 thepreinstalllifecyle and therm-local-modulesinprescripttrick doesn't work.