1.2.5 • Published 10 years ago
shared-pack v1.2.5
shared-pack
Write code in node.js, and use it on node.js or angular.js platforms.
Index
Requirements
- npm
- node.js
Installation
npm install -g shared-pack
Usage
Create a javascript module
The module should satisfy the following 2 conditions:
- it should be exposed as node.js module - using
module.exports - the function to expose should be the angular.js function - with dependencies declared as parameters of the function
Example
- crete folder:
mkdir shared-module && cd $_ - initialize bower.json and package.json
bower init && npm init create module, example
shared-service.js:'use strict'; function SharedService(param1) { console.log('Ola', param1); } module.exports = SharedService;
Compile
shared-pack ./shared-service.jsResults
The results fo compilation will be a foldr ./build containing 2 files
./build/shared-service.angular.js``` function SharedService(param1) { console.log('Ola', param1); } angular.module('SharedService', ['param1']) .factory('SharedService', ['param1', SharedService]); ```./build/shared-service.node.js``` function SharedService(param1) { console.log('Ola', param1); } module.exports = SharedService(require('param1.js')); ```
Configure properly main field in bower.json and package.json
bower.json
...
"main":"./build/shared-service.angular.js",
...package.json
...
"main":"./build/shared-service.node.js",
...Roadmap
- Add support for private npm packages