-
Notifications
You must be signed in to change notification settings - Fork 22
For Javascript Developers
The package.json
file is the top level file in the project directory.
It provides:
-
node.js
some meta-data on how to resolve the entry point into the package (main
) -
npm
the dependencies and their versions that need to be installed to get this package installed, and clues how to test the package. - various tools a lot of meta-data about the package and the package's authors.
-
browserify
some alternatives on what would run better in a webview -
kirin
some clues on how the project is structured, and how to build it.
Using package.json
for node.js and npm is well documented on the npm site, and the browserify site.
However, kirin
has its own requirements. All kirin
related requirements are contained in the kirin
field of package.json
(this is referred to as the kirin
block).
If you have generated your project using the kirin-create
template then most of this is looked after for you.
The most important thing to document then is the dependencies
entry in the kirin block is dependencies. npm
uses a set of key-value pairs to determine the dependencies and versions that the package is designed to work on.
In the absence of a kirin
block, then these dependencies are used. However, for a mobile app, this is always going to be a super-set of the dependencies that are actually needed on the device.
Thus, dependencies are listed as an array of packages in the kirin
block.
For example, to add the excellent underscore.strings
packages to your kirin
project, open up package.json
, then add the following:
"kirin": {
…
"dependencies": ["underscore.string"]
…
},
"dependencies": {
"underscore.string": ">= 2.1.0"
}
Once you've done that, you can issue the command from your project directory:
$ npm install
You can now test that kirin
can build the new package with:
~/bin/kirin-build --platform ios
At this point, we are building the javascript for iOS, however, it is very unlikely that the code for underscore.string
will be available on the device.
This is due to the way browserify works - by only including packages and modules that are require
d.
To do this, you need to include a statement somewhere in your javascript:
var strings = require("underscore.strings");
Once this statement is in place, then the kirin-build
will start packaging underscore.string
into the apps generated-javascript
directory.