-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A extension to add support for imagemin images compression
- Loading branch information
1 parent
67b305a
commit 6232467
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# RollupJS Extension | ||
|
||
**Task Definitions**: _None_<br /> | ||
**Template Definitions**: _['imagemin'](#imagemin-template)_<br /> | ||
**Batcher Definitions**: _None_ | ||
|
||
Performs compression on images with the default settings from `imagemin-cli` | ||
|
||
### Template Options | ||
|
||
* `auto-install` (_Boolean_, default: `true`): Whether to automatically install `rollup` if not present (using the [npm extension](npm.md)). The global npm extension `auto-install` option will take precedence here if not otherwise set. | ||
* `entry` (_String_): List of application entry points. | ||
* `outdir` (_String_): The build output directory. | ||
* `plugins` (_String_): Any valid imagemin plugins (eg: `mozjpeg`) | ||
|
||
### Example | ||
|
||
_chompfile.toml_ | ||
```toml | ||
version = 0.1 | ||
|
||
extensions = ['[email protected]:rollup'] | ||
|
||
[[task]] | ||
name = 'build:assets' | ||
deps = ["public/assets"] | ||
template = 'imagemin' | ||
[task.template-options] | ||
plugins = ['mozjpeg'] | ||
entry = 'public/assets' | ||
``` | ||
|
||
## Roadmap | ||
|
||
This plugin is very simple currently and needs to be extended to support comprehensive Imagemin pipelines and customization options. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
Chomp.addExtension("[email protected]:npm"); | ||
|
||
Chomp.registerTemplate("imagemin", function (task) { | ||
const { | ||
outdir = "dist", | ||
entry, | ||
autoInstall, | ||
plugins = [], | ||
} = task.templateOptions; | ||
if (!entry) { | ||
throw new Error(`Images entry is mandatory`); | ||
} | ||
|
||
const imageminPlugins = plugins.map((plugin) => `imagemin-${plugin}`); | ||
const statement = `imagemin ${entry}/* --out-dir=${outdir}/${entry} ${ | ||
plugins.length > 0 | ||
? plugins.reduce((acc, plugin) => { | ||
acc = acc + `--plugin=${plugin}`; | ||
return acc; | ||
}, "") | ||
: "" | ||
}`; | ||
|
||
return [ | ||
{ | ||
name: task.name, | ||
deps: [ | ||
...task.deps, | ||
...(ENV.CHOMP_EJECT | ||
? ["npm:install"] | ||
: [ | ||
"node_modules/imagemin-cli", | ||
/* | ||
While reading through cli imagemin don't need prefix | ||
https://github.com/imagemin/imagemin-cli/blob/main/cli.js#L55 | ||
*/ | ||
...imageminPlugins.map((plugin) => `node_modules/${plugin}`), | ||
]), | ||
], | ||
targets: [...new Set([...task.targets])], | ||
run: statement, | ||
}, | ||
...(ENV.CHOMP_EJECT | ||
? [] | ||
: [ | ||
{ | ||
template: "npm", | ||
templateOptions: { | ||
autoInstall, | ||
packages: ["imagemin-cli", ...imageminPlugins], | ||
dev: true, | ||
}, | ||
}, | ||
]), | ||
]; | ||
}); |