If you want to specify which modules to use, you need to setup package.json
first. Modules inside package.json can be with or without a slash in their name. Without slash
, they will be loaded from npm, without, they will be loaded straight ahead from GitHub.
We decided not to push our modules on npm, because the itsa namespace on GitHub quarantees the right identity of our modules. All ITSA modules can be refered to with "itsa/modulename"
.
After settting up the right package.json, you need to run npm install
, which will install all the modules and their dependencies inside the folder node_modules
.
Now you can write your application. Be aware that some modules needs to be required as a function
with the window
-object passed through, something "itsa"
does under the hood. When requiring io yourself, you need to use "itsa/node-win"
like this:
Once everything is setup right, you can start build your scriptfile.
Because the browser doesn't support "require()
", you need to bundled loader-file (bundled with Browerify). Browserify inspects your code and creates a single bundle-file that holds all the requirements (and its dependencies) and will define the require()-method in the browser.
Creating your own loader-file takes 4-steps:
The package.json file is just alike the nodejs example above. You can require any "itsa/modulename"
-module you want, any subfile, other CommonJS GitHub-modules or npm-modules. You probably be only interested in modules that are build for usage on browser.
The main-property doesn't need to be specified.
This will install all packages and their requirements into the folder node_modules
.
The builder-file can have any name, as from now, we suppose its name as being index.js. Inside the builder-file, you can use "require()
" just the same as within nodejs. You should define only one global namespace (f.e. ITSA
) and bind any methods and variables to that one namespace. This namespace should be exported with module.exports
.
Notice that the exported ITSA
can be required both as reference
as well as a function
were you pass through any config-parameters.
The last step is to create the loaderfile using Browerify. Because you need a minified file, you need to minify as well. We use uglifyjs to minify, but you are free to use any minifier you want.
If you don't have them yet, install browserify, cssify and uglifyjs on your system globally: By installing it globally, you have the command-line commands available. `cssify` is also automaticly installed locally, for it needs to be there as well.
Final step is to create two build files. One just browserified with all comments and not minified, the second will be minified. You can choose any name you want for these files. Notice that you have to use browserify with the option `-g cssify` to build with css-files. Also notice that we have set specific options to uglify so that the compressed file works with ITSA
's code.
<script src="/build-min.js"></script>