Bower and NPM
You can install this package by using either Bower or NPM.
$ npm install –save bootstrap.native
$ bower install –save bootstrap.native
bootstrap.native is compatible with the CommonJS/RequireJS spec (exporting itself to
module.exports). It thus can fall back to adding its exports to the
You can use the scripts either using a traditional script-tag like so:
Note that you may not be able to use files directly from
/lib folder because they are missing the utilities. These files are sources for the builds located in the
It’s also possible to use any module loader that supports the
CommonJS syntax. An example is
If you are working in a virtual browser environment, the properties of the returned exports are all functions, that expect both, a global
window and a global
document variable to exist before calling. An example case is during tests, where you may use NodeJS to run front-end tests. These usually will create a virtual Window and Document object. Once these exist,
bootstrap.native will function properly.
An example of this would look like this:
var bsn = require("bootstrap.native"); var browser = require("mock-browser"); global.window = browser.createWindow(); global.document = browser.createDocument(); // Now it's safe to use bootstrap.native and expecting the properties to be the actual component classes. var Button = bsn.Button(); // Create the button class and return it. var $btn = document.createElement("button"); var myButton = new Button(... $btn and options ...); // Create a button and do a test.
Note About the Factory Methods
As mentioned above, the object properties of the exported object, when using
require(), are actual classes when
window are given - in which case we are sure to be facing an actual browser - and if absent, will be factory methods.
So when using
bootstrap.native inside of a NodeJS app, make sure you create a proper Browser-like environment first to avoid unexpected behaviour.
The scripts are developed with clean code mainly for modern browsers that nativelly support HTML5. When using polyfills IE8-IE9 will thank you.
You can make a custom build of bootstrap-native, including only the modules you need, by using the
$ node build.js --help node build.js [--minify] [--ignore=<modules>...|--only=<modules>...] Options: --minify, -m Minify output [boolean] [default: false] --ignore, -i Omit the given module(s) from the bundle [array] --only Only include the given module(s) in the bundle [array] --help Show help [boolean] Running without --ignore or --only will compile all the modules. Writes to stdout
*nix users can run
./build.js as well as
- Ingwie Phoenix: RequireJS/CommonJS compatibility and usability with common package managers. Was glad to help!
- Ryan Zimmerman: Amazing custom build script.
- Full contributors list here. Thanks so much!
The scripts are released under the MIT license.