Skip to content

Commit bfec1ef

Browse files
committed
Add standalone, single-scope example
1 parent df84f7d commit bfec1ef

3 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Example
2+
3+
> Generate a [browserify][browserify] standalone UMD bundle with a single scope which attaches to the global `window` object.
4+
5+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
6+
7+
<section class="intro">
8+
9+
To run the example, in your terminal, navigate to this directory
10+
11+
```bash
12+
$ cd /path/to/this/directory
13+
```
14+
15+
Once in the directory, generate the bundle
16+
17+
```bash
18+
$ node ./index.js
19+
```
20+
21+
To generate a gzipped bundle,
22+
23+
```bash
24+
$ gzip ./build/bundle.min.js -9 -c > ./build/bundle.min.js.gz
25+
```
26+
27+
Next, launch a static file server
28+
29+
```bash
30+
$ python -m SimpleHttpServer <port>
31+
```
32+
33+
where `<port>` is the server port (e.g., `7331`). Finally, to view the example in a local web browser, navigate to
34+
35+
```text
36+
http://127.0.0.1:<port>
37+
```
38+
39+
</section>
40+
41+
<!-- /.intro -->
42+
43+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
44+
45+
<section class="links">
46+
47+
[browserify]: https://github.com/substack/node-browserify
48+
49+
</section>
50+
51+
<!-- /.links -->
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="x-ua-compatible" content="ie=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7+
</head>
8+
<body>
9+
<p>
10+
Open your console.
11+
</p>
12+
<script type="text/javascript" src="/build/bundle.js"></script>
13+
<script type="text/javascript">
14+
// No module system, so bundle export should be attached to the global `window` object:
15+
console.log( stdlib );
16+
</script>
17+
</body>
18+
</html>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
var join = require( 'path' ).join;
4+
var writeFile = require( 'fs' ).writeFileSync;
5+
var mkdirp = require( 'mkdirp' ).sync;
6+
var packFlat = require( 'browser-pack-flat/plugin' );
7+
var uglify = require( 'uglify-es' );
8+
var bundle = require( './../../lib' );
9+
10+
var names = [
11+
'@stdlib/math/base/special/erf',
12+
'@stdlib/math/base/special/gamma'
13+
];
14+
15+
var bopts = {
16+
'namespace': 'flat',
17+
'standalone': 'stdlib',
18+
'plugins': [
19+
packFlat // bundle under a single scope
20+
]
21+
};
22+
23+
var dir = join( __dirname, 'build' );
24+
bundle( names, bopts, onBundle );
25+
26+
function onBundle( error, bundle ) {
27+
var fpath;
28+
if ( error ) {
29+
throw error;
30+
}
31+
mkdirp( dir );
32+
fpath = join( dir, 'bundle.js' );
33+
writeFile( fpath, bundle );
34+
35+
bundle = uglify.minify( bundle.toString() ).code;
36+
fpath = join( dir, 'bundle.min.js' );
37+
writeFile( fpath, bundle );
38+
}

0 commit comments

Comments
 (0)