Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better* defaults #187

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
}
```


## 📦 Usage

Microbundle includes two commands - `build` (the default) and `watch`. Neither require any options, but you can tailor things to suit your needs a bit if you like.
Expand All @@ -43,6 +42,16 @@ Microbundle includes two commands - `build` (the default) and `watch`. Neither r
By default, microbundle will infer the location of your source entry file
(the root module in your program) from the `source` field in your `package.json`. It will infer the output directory and filename(s) from the `main` field. For UMD builds, microbundle will use a snake case version of the `name` field in your `package.json` for the export name; you can also specify a name via an `amdName` field or the `name` CLI option.

If you'd like to compress your library for distribution, include the `--compress` flag. You may also produce and include source maps by including the `--sourcemap` flag:

```sh
$ microbundle --compress --sourcemap
# or
$ microbundle build --compress --sourcemap
```

> **Note:** These flags can also be applied to `watch` mode!

### `microbundle watch`

Just like `microbundle build`, but watches your source files and rebuilds on any change.
Expand All @@ -66,16 +75,24 @@ Just like `microbundle build`, but watches your source files and rebuilds on any
-i, --entry Entry module(s)
-o, --output Directory to place build files into
-f, --format Only build specified formats (default es,cjs,umd)
-w, --watch Rebuilds on any change (default false)
-w, --watch Rebuilds on any change
--target Specify your target environment (default node)
--external Specify external dependencies, or 'none'
--compress Compress output using UglifyJS (default true)
--compress Compress output using UglifyJS
--strict Enforce undefined global context and add "use strict"
--name Specify name exposed in UMD builds
--cwd Use an alternative working directory (default .)
--sourcemap Generate source map (default true)
--sourcemap Generate source map
-h, --help Displays this message

Examples
$ microbundle
$ microbundle --compress
$ microbundle --external none --format cjs --strict
$ microbundle build --compress --sourcemap
$ microbundle watch --sourcemap
```

### Specifying builds in `package.json`

You can specify output builds in a `package.json` as follows:
Expand All @@ -95,7 +112,6 @@ Here's what's coming up for Microbundle:
- [x] [TypeScript support](https://github.com/developit/microbundle/issues/5)
- [x] [Flowtype support](https://github.com/developit/microbundle/issues/5#issuecomment-351075881)


## 🔨 Built with Microbundle

- [Stockroom](https://github.com/developit/stockroom) Offload your store management to a worker easily.
Expand All @@ -106,7 +122,6 @@ Here's what's coming up for Microbundle:

[MIT](https://oss.ninja/mit/developit/)


[Rollup]: https://github.com/rollup/rollup
[Bublé]: https://github.com/Rich-Harris/buble
[Nodent]: https://github.com/MatAtBread/nodent-compiler
[rollup]: https://github.com/rollup/rollup
[bublé]: https://github.com/Rich-Harris/buble
[nodent]: https://github.com/MatAtBread/nodent-compiler
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function createConfig(options, entry, format, writeMeta) {
postcss({
plugins: [
autoprefixer(),
options.compress !== false &&
options.compress &&
cssnano({
preset: 'default',
}),
Expand Down Expand Up @@ -381,7 +381,7 @@ function createConfig(options, entry, format, writeMeta) {
// [`export default ${rollupName};`]: '',
// [`var ${rollupName} =`]: 'export default'
// }),
options.compress !== false && [
options.compress && [
uglify({
sourceMap: true,
output: { comments: false },
Expand Down Expand Up @@ -437,7 +437,7 @@ function createConfig(options, entry, format, writeMeta) {
legacy: true,
freeze: false,
esModule: false,
sourcemap: options.sourcemap !== false,
sourcemap: !!options.sourcemap,
treeshake: {
propertyReadSideEffects: false,
},
Expand Down
11 changes: 8 additions & 3 deletions src/prog.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ export default handler => {

prog
.version(version)
.example('')
.example('--compress')
.example('--external none --format cjs --strict')
.example('build --compress --sourcemap')
.example('watch --sourcemap')
.option('--entry, -i', 'Entry module(s)')
.option('--output, -o', 'Directory to place build files into')
.option('--format, -f', 'Only build specified formats', 'es,cjs,umd')
.option('--watch, -w', 'Rebuilds on any change', false)
.option('--watch, -w', 'Rebuilds on any change')
.option('--target', 'Specify your target environment', 'node')
.option('--external', `Specify external dependencies, or 'none'`)
.option('--compress', 'Compress output using UglifyJS', true)
.option('--compress', 'Compress output using UglifyJS')
.option('--strict', 'Enforce undefined global context and add "use strict"')
.option('--name', 'Specify name exposed in UMD builds')
.option('--cwd', 'Use an alternative working directory', '.')
.option('--sourcemap', 'Generate source map', true);
.option('--sourcemap', 'Generate source map');

prog
.command('build [...entries]', '', { default: true })
Expand Down
Loading