Skip to content
Merged
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
For Deno users:

```js
import {minify} from 'npm:minify';

Check failure on line 34 in README.md

View workflow job for this annotation

GitHub Actions / build (24.x)

Package subpath './experimental-worker' is not defined by "exports" in /home/runner/work/minify/minify/node_modules/@babel/eslint-parser/package.json imported from /home/runner/work/minify/minify/node_modules/eslint-plugin-putout/eslint-v10/babel.js

Check failure on line 34 in README.md

View workflow job for this annotation

GitHub Actions / build (22.x)

Package subpath './experimental-worker' is not defined by "exports" in /home/runner/work/minify/minify/node_modules/@babel/eslint-parser/package.json imported from /home/runner/work/minify/minify/node_modules/eslint-plugin-putout/eslint-v10/babel.js
```

## How to use?
Expand All @@ -47,6 +47,7 @@
--css minify css
--html minify html
--auto auto detect format
--fail-on-error exit with code 1 when minification fails
```

The bash command below creates a code snippet saved as `hello.js`.
Expand Down Expand Up @@ -76,6 +77,14 @@
$ minify hello.js > hello.min.js
```

Use `--fail-on-error` to get a non-zero exit code when minification fails (useful in build scripts and CI):

```sh
$ minify broken.js --fail-on-error > broken.min.js
$ echo $?
1
```

You can pass input using `cat`:

```sh
Expand All @@ -92,7 +101,7 @@
`Minify` can be used with `async-await` and [try-to-catch](https://github.com/coderaiser/try-to-catch):

```js
import {minify} from 'minify';

Check failure on line 104 in README.md

View workflow job for this annotation

GitHub Actions / build (24.x)

Package subpath './experimental-worker' is not defined by "exports" in /home/runner/work/minify/minify/node_modules/@babel/eslint-parser/package.json imported from /home/runner/work/minify/minify/node_modules/eslint-plugin-putout/eslint-v10/babel.js

Check failure on line 104 in README.md

View workflow job for this annotation

GitHub Actions / build (22.x)

Package subpath './experimental-worker' is not defined by "exports" in /home/runner/work/minify/minify/node_modules/@babel/eslint-parser/package.json imported from /home/runner/work/minify/minify/node_modules/eslint-plugin-putout/eslint-v10/babel.js
import {tryToCatch} from 'try-to-catch';

const options = {
Expand All @@ -115,7 +124,7 @@
For cli use these options can be provided in a JSON file named `.minify.json` like so:

```json
{

Check failure on line 127 in README.md

View workflow job for this annotation

GitHub Actions / build (24.x)

Package subpath './experimental-worker' is not defined by "exports" in /home/runner/work/minify/minify/node_modules/@babel/eslint-parser/package.json imported from /home/runner/work/minify/minify/node_modules/eslint-plugin-putout/eslint-v10/babel.js

Check failure on line 127 in README.md

View workflow job for this annotation

GitHub Actions / build (22.x)

Package subpath './experimental-worker' is not defined by "exports" in /home/runner/work/minify/minify/node_modules/@babel/eslint-parser/package.json imported from /home/runner/work/minify/minify/node_modules/eslint-plugin-putout/eslint-v10/babel.js
"js": {
"type": "putout",
"putout": {
Expand Down Expand Up @@ -170,7 +179,7 @@
When you want to pass [options](https://github.com/terser/terser#minify-options) to `terser`, use section with the same name, `.minify.json` will look this way:

```json
{

Check failure on line 182 in README.md

View workflow job for this annotation

GitHub Actions / build (24.x)

Package subpath './experimental-worker' is not defined by "exports" in /home/runner/work/minify/minify/node_modules/@babel/eslint-parser/package.json imported from /home/runner/work/minify/minify/node_modules/eslint-plugin-putout/eslint-v10/babel.js

Check failure on line 182 in README.md

View workflow job for this annotation

GitHub Actions / build (22.x)

Package subpath './experimental-worker' is not defined by "exports" in /home/runner/work/minify/minify/node_modules/@babel/eslint-parser/package.json imported from /home/runner/work/minify/minify/node_modules/eslint-plugin-putout/eslint-v10/babel.js
"js": {
"type": "terser",
"terser": {
Expand Down
7 changes: 6 additions & 1 deletion bin/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ const log = function(...args) {
};

const Argv = process.argv;
const files = Argv.slice(2);
const allArgs = Argv.slice(2);
const failOnError = allArgs.includes('--fail-on-error');
const files = allArgs.filter((f) => f !== '--fail-on-error');
const [In] = files;

log.error = (e) => {
console.error(e);
process.stdin.pause();

if (failOnError)
process.exit(1);
};

process.on('uncaughtException', (error) => {
Expand Down
3 changes: 2 additions & 1 deletion help.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"--js ": "minify javascript",
"--css ": "minify css",
"--html ": "minify html",
"--auto ": "auto detect format"
"--auto ": "auto detect format",
"--fail-on-error ": "exit with code 1 when minification fails"
}
Loading