Skip to content

Commit 6c486e5

Browse files
committed
Initial commit
0 parents  commit 6c486e5

File tree

7 files changed

+411
-0
lines changed

7 files changed

+411
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
.DS_Store
3+
*.log
4+
build
5+
dist
6+
package-lock.json

package.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "microbundle",
3+
"version": "0.1.0",
4+
"description": "Zero-configuration bundler for tiny JS libs, powered by Rollup.",
5+
"main": "dist/microbundle.js",
6+
"source": "src/index.js",
7+
"bin": {
8+
"microbundle": "dist/cli.js"
9+
},
10+
"scripts": {
11+
"build": "babel-node --presets env src/cli.js --external all --format cjs src/*.js",
12+
"prepare": "npm run -s build && npm t",
13+
"lint": "eslint src",
14+
"test:build": "node dist/cli.js --no-compress --cwd test/demo",
15+
"test": "npm run -s lint && npm run -s build && npm run -s test:build"
16+
},
17+
"eslintConfig": {
18+
"extends": "eslint-config-developit"
19+
},
20+
"keywords": [
21+
"bundle",
22+
"rollup"
23+
],
24+
"files": [
25+
"src",
26+
"dist"
27+
],
28+
"author": "Jason Miller <[email protected]> (http://jasonformat.com)",
29+
"license": "MIT",
30+
"dependencies": {
31+
"asyncro": "^2.0.1",
32+
"babel-polyfill": "^6.26.0",
33+
"chalk": "^2.3.0",
34+
"es6-promisify": "^5.0.0",
35+
"gzip-size": "^4.1.0",
36+
"pretty-bytes": "^4.0.2",
37+
"regenerator-runtime": "^0.11.1",
38+
"rollup": "^0.52.1",
39+
"rollup-plugin-buble": "^0.18.0",
40+
"rollup-plugin-bundle-size": "^1.0.1",
41+
"rollup-plugin-commonjs": "^8.2.6",
42+
"rollup-plugin-es3": "^1.1.0",
43+
"rollup-plugin-node-resolve": "^3.0.0",
44+
"rollup-plugin-nodent": "^0.1.3",
45+
"rollup-plugin-post-replace": "^1.0.0",
46+
"rollup-plugin-sizes": "^0.4.2",
47+
"rollup-plugin-uglify": "^2.0.1",
48+
"yargs": "^10.0.3"
49+
},
50+
"devDependencies": {
51+
"babel-cli": "^6.26.0",
52+
"babel-preset-env": "^1.6.1",
53+
"eslint": "^4.13.0",
54+
"eslint-config-developit": "^1.1.1"
55+
}
56+
}

src/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Microbundle
2+
3+
A zero-configuration bundler for tiny modules, powered by Rollup.
4+
5+
- Reads all the necessary information from your `package.json`
6+
- Supports multiple entry modules (`cli.js` + `index.js`, etc)
7+
- Creates multiple output formats for each entry (CommonJS, UMD & ESM).
8+
9+
## Installation
10+
11+
`npm i -D microbundle`
12+
13+
... then add it as an npm script:
14+
15+
```js
16+
{
17+
"scripts": {
18+
"build": "microbundle",
19+
"dev": "microbundle watch"
20+
}
21+
}
22+
```
23+
24+
## Usage
25+
26+
```
27+
microbundle [entries..]
28+
29+
Build once and exit
30+
31+
Commands:
32+
cli.js build [entries..] Build once and exit [default]
33+
cli.js watch [entries..] Rebuilds on any change
34+
35+
Options:
36+
--version Show version number [boolean]
37+
--entry, -i Entry module(s)
38+
[string] [default: <package.module>]
39+
--output, -o, -d Directory to place build files into
40+
[string] [default: <dirname(package.main), build/>]
41+
--cwd Use an alternative working directory
42+
[string] [default: .]
43+
--format Only build specified formats
44+
[string] [default: es,cjs,umd]
45+
--compress Compress output using UglifyJS
46+
[boolean] [default: true]
47+
--strict Enforce undefined global context and add "use
48+
strict" [default: false]
49+
```
50+
51+
## Liccense
52+
53+
MIT

src/cli.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env node
2+
3+
import yargs from 'yargs';
4+
import microbundle from '.';
5+
6+
yargs
7+
.option('entry', {
8+
type: 'string',
9+
alias: ['i', 'e', 'entries'],
10+
description: 'Entry module(s)',
11+
defaultDescription: '<package.module>'
12+
})
13+
.option('output', {
14+
type: 'string',
15+
alias: ['o', 'd'],
16+
description: 'Directory to place build files into',
17+
defaultDescription: '<dirname(package.main), build/>'
18+
})
19+
.option('cwd', {
20+
type: 'string',
21+
description: 'Use an alternative working directory',
22+
defaultDescription: '.'
23+
})
24+
.option('format', {
25+
type: 'string',
26+
description: 'Only build specified formats',
27+
defaultDescription: 'es,cjs,umd'
28+
})
29+
.option('compress', {
30+
type: 'boolean',
31+
description: 'Compress output using UglifyJS',
32+
default: true
33+
})
34+
.option('strict', {
35+
description: 'Enforce undefined global context and add "use strict"',
36+
default: false
37+
})
38+
.command(
39+
['build [entries..]', '$0 [entries..]'],
40+
'Build once and exit',
41+
() => {},
42+
argv => run(argv, false)
43+
)
44+
.command(
45+
'watch [entries..]',
46+
'Rebuilds on any change',
47+
() => {},
48+
argv => run(argv, true)
49+
)
50+
.help()
51+
.argv;
52+
53+
function run(options, watch) {
54+
options.watch = watch===true;
55+
microbundle(options)
56+
.then( output => {
57+
if (output!=null) process.stdout.write(output + '\n');
58+
if (!watch) {
59+
process.exit(0);
60+
}
61+
})
62+
.catch(err => {
63+
process.stderr.write(String(err) + '\n');
64+
process.exit(err.code || 1);
65+
});
66+
}

0 commit comments

Comments
 (0)