{"id":13526520,"url":"https://github.com/WebReflection/ucompress","last_synced_at":"2025-04-01T07:32:50.911Z","repository":{"id":47292065,"uuid":"249436783","full_name":"WebReflection/ucompress","owner":"WebReflection","description":"A micro, all-in-one, compressor for common Web files.","archived":false,"fork":false,"pushed_at":"2021-09-04T07:14:15.000Z","size":1620,"stargazers_count":91,"open_issues_count":1,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-11T02:19:26.540Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebReflection.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-23T13:21:47.000Z","updated_at":"2023-06-19T01:08:10.000Z","dependencies_parsed_at":"2022-09-13T23:51:03.006Z","dependency_job_id":null,"html_url":"https://github.com/WebReflection/ucompress","commit_stats":null,"previous_names":[],"tags_count":73,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fucompress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fucompress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fucompress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fucompress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebReflection","download_url":"https://codeload.github.com/WebReflection/ucompress/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222709794,"owners_count":17026764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:01:30.959Z","updated_at":"2024-11-02T11:31:17.503Z","avatar_url":"https://github.com/WebReflection.png","language":"JavaScript","readme":"# \u003cem\u003eµ\u003c/em\u003ecompress\n\n[![Build Status](https://travis-ci.com/WebReflection/ucompress.svg?branch=master)](https://travis-ci.com/WebReflection/ucompress) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/ucompress/badge.svg?branch=master)](https://coveralls.io/github/WebReflection/ucompress?branch=master)\n\n\n![compressed umbrellas](./test/ucompress.jpg)\n\n\u003csup\u003e**Social Media Photo by [Kevin Borrill](https://unsplash.com/@kev2480) on [Unsplash](https://unsplash.com/)**\u003c/sup\u003e\n\nA \u003cem\u003emicro\u003c/em\u003e, all-in-one, compressor for common Web files, resolving automatically _JavaScript_ imports, when these are static.\n\n\n### 📣 Community Announcement\n\nPlease ask questions in the [dedicated forum](https://webreflection.boards.net/) to help the community around this project grow ♥\n\n---\n\n## As CLI\n\nDue amount of dependencies, it's recommended to install this module via `npm i -g ucompress`. However you can try it via `npx` too.\n\n```sh\n# either npm i -g ucompress once, or ...\nnpx ucompress --help\n```\n\nIf `--source` and `--dest` parameter are passed, it will do everything automatically.\n\n```sh\nucompress --source ./src --dest ./public\n```\n\nCheck other flags for extra optimizations, such as `.json` headers files and/or `.br`, `.gzip`, and `.deflate` versions, which you can serve via NodeJS or Express, using [µcdn-utils](https://github.com/WebReflection/ucdn-utils#readme).\n\n\n\n## As module\n\n```js\nimport ucompress from 'ucompress';\n// const ucompress = require('ucompress');\n\n// define or retrieve `source` and `dest as you like\n\n// automatic extension =\u003e compression\nucompress(source, dest).then(dest =\u003e console.log(dest));\n\n// explicit compression\nucompress.html(source, dest).then(dest =\u003e console.log(dest));\n\n// handy fallback\nucompress.copy(source, dest).then(dest =\u003e console.log(dest));\n```\n\n\n### Options\n\nThe optional third `options` _object_ parameter can contain any of the following properties:\n\n  * `createFile`, a _boolean_ property, `false` by default, that will automatically pre-compress via _brotli_, _gzip_, and _deflate_, compatible files, plus it will create a `.json` file with pre-processed _headers_ details per each file\n  * `maxWidth`, an _integer_ property, that if provided, it will reduce, if necessary, the destination image _width_ when it comes to _JPG_ or _PNG_ files\n  * `maxHeight`, an _integer_ property, that if provided, it will reduce, if necessary, the destination image _height_ when it comes to _JPG_ or _PNG_ files\n  * `preview`, a _boolean_ parameter, false by default, that creates _JPG_ counter `.preview.jpg` files to be served instead of originals, enabling bandwidth saving, especially for very big pictures (example: [with-preview](https://github.com/WebReflection/with-preview/#readme))\n  * `noImport`, a _boolean_ parameter, false by default, that skips automatic _ESM_ `import` resolution, in case the site provides imports maps by itself\n  * `noMinify`, a _boolean_ parameter, false by default, that keeps the `.js`, `.css`, and `.html` source intact, still performing other changes, such as `.js` imports\n\n\n\n## As Micro CDN\n\nIf you'd like to use this module to serve files _CDN_ like, check **[µcdn](https://github.com/WebReflection/ucdn#readme)** out, it includes ucompress already, as [explained in this post](https://medium.com/@WebReflection/%C2%B5compress-goodbye-bundlers-bb66a854fc3c).\n\n\n### Compressions\n\nFollowing the list of tools ued to optimized various files:\n\n  * **css** files via [csso](https://www.npmjs.com/package/csso)\n  * **gif** files via [gifsicle](https://www.npmjs.com/package/gifsicle) as *optional dependency*\n  * **html** files via [html-minifier](https://www.npmjs.com/package/html-minifier)\n  * **jpg** or **jpeg** files via [sharp](https://github.com/lovell/sharp)\n  * **js** or **mjs** files via [terser](https://github.com/terser/terser) and [html-minifier](https://github.com/kangax/html-minifier)\n  * **json** files are simply parsed and stringified so that white spaces get removed\n  * **md** files are transformed into their `.md.preview.html` version, if the _preview_ is enabled, through [marked](https://github.com/markedjs/marked)\n  * **png** files via [pngquant-bin](https://www.npmjs.com/package/pngquant-bin)\n  * **svg** files via [svgo](https://www.npmjs.com/package/svgo)\n  * **xml** files via [html-minifier](https://www.npmjs.com/package/html-minifier)\n\n\n### About Automatic Modules Resolution\n\nIf your modules are published as [dual-module](https://medium.com/@WebReflection/a-nodejs-dual-module-deep-dive-8f94ff56210e), or if you have a `module` field in your `package.json`, and it points at an _ESM_ compatible file, as it should, or if you have a `type` field equal to `module` and a `main` that points at an _ESM_ compatible, or if you have an `exports` field which `import` resolves to an _ESM_ compatible module, _µcompress_ will resolve that entry point automatically.\n\nIn every other case, the _import_ will be left untouched, eventually warning in console when such _import_ failed.\n\n**Dynamic imports** are resolved in a very similar way, but composed imports will likely fail:\n\n```js\n// these work if the module is found in the source path\n// as example, inside source/node_modules\nimport 'module-a';\nimport('module-b').then(...);\n\n// these work *only* if the file is in the source path\n// but not within a module, as resolved modules are not\n// copied over, only known imports, eventually, are\nimport(`/js/${strategy}.js`);\n\n// these will *not* work\nimport(condition ? 'condition-thing' : 'another-thing');\nimport('a' + thing + '.js');\n```\n\n\n### About `ucompress.createHeaders(path[, headers])`\n\nThis method creates headers for a specific file, or all files within a folder, excluding files that starts with a `.` dot, an `_` underscore, or files within a `node_modules` folder (_you know, that hole that should never fully land in production_).\n\n```js\nucompress.createHeaders(\n  // a folder with already optimized files\n  '/path/static',\n  // optional headers to set per folder\n  {'Access-Control-Allow-Origin': '*'}\n);\n```\n\n\n### Brotli, Deflate, GZip, and Headers\n\nIf the third, optional object, contains a `{createFile: true}` flag, each file will automatically generate its own related `.json` file which includes a [RFC-7232](https://tools.ietf.org/html/rfc7232#section-2.3.3) compliant _ETag_, among other details such as `last-modified`, `content-type`, and `content-length`.\n\nThe following file extensions, available via the `ucompress.encoded` _Set_, will also create their `.br`, `.deflate`, and `.gzip` version in the destination folder, plus their own `.json` file, per each different compression, but **only** when `{createFile: true}` is passed.\n\n  * **.css**\n  * **.html**\n  * **.js**\n  * **.mjs**\n  * **.map**\n  * **.json**\n  * **.md**\n  * **.svg**\n  * **.txt**\n  * **.woff2**\n  * **.xml**\n  * **.yml**\n\nIncompatible files will fallback as regular copy `source` into `dest` when the module is used as callback, without creating any optimized version, still providing headers when the flag is used.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWebReflection%2Fucompress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FWebReflection%2Fucompress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWebReflection%2Fucompress/lists"}