Skip to content

Commit b4df2c3

Browse files
liitfrjescalan
authored andcommitted
Allow to pass options to reshape-minify package (#35)
1 parent 13930be commit b4df2c3

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Any of these plugins can be customized by passing options described below.
9393
| **locals** | Added directly to the output object, used when compiling a reshape template to html | `{}` |
9494
| **alias** | Alias option to be passed to the [include plugin](https://github.com/reshape/include#options) | |
9595
| **parserRules** | Parser rules to be passed to the [include plugin](https://github.com/reshape/include#options) | |
96-
| **minify** | Minifies the html output by removing excess spaces and line breaks | `false` |
96+
| **minify** | Minifies the html output by removing excess spaces and line breaks, comments, and by minifying inline CSS, JS, SVG and JSON. Accepts a boolean or an object of options passed to [reshape-minify](https://github.com/reshape/minify) | `false` |
9797
| **appendPlugins** | Adds a single plugin or array of plugins after all the defaults | |
9898
| **prependPlugins** | Adds a single plugin or array of plugins before all the defaults | |
9999
| **template** | Set this to `true` if you are trying to output a client-side template function. | false |

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ let evalCode = require('reshape-eval-code')
2323
* @param {Object} [options.content={}] - passed to content plugin
2424
* @param {Object} options.markdown - passed to markdown-it constructor
2525
* @param {Object} options.locals - if passed, renders as html string
26-
* @param {Boolean} options.minify - add minify plugin if true
26+
* @param {Boolean|Object} options.minify - enable minify plugin if true or
27+
* fine tune it if an object of options is passed. Beautify otherwise.
2728
* @param {String} options.filename - copied directly to output
2829
* @param {Function} [options.parser=sugarml] - undefined if false
2930
* @param {Array|String} options.appendPlugins - appended to plugins array
@@ -76,7 +77,7 @@ module.exports = function reshapeStandard (options = {}) {
7677

7778
// append the minify or beautify formatting plugin (always last)
7879
if (options.minify) {
79-
plugins.push(minify())
80+
plugins.push(minify(typeof options.minify === 'object' ? options.minify : {}))
8081
} else {
8182
plugins.push(beautify())
8283
}

test/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,16 @@ test('passed locals', (t) => {
102102
t.truthy(out.locals === 'test')
103103
})
104104

105-
test('minify option', (t) => {
105+
test('minify option as a boolean', (t) => {
106106
const out = standard({ minify: true })
107107
t.truthy(out.plugins[out.plugins.length - 1].name === 'minifyPlugin')
108108
})
109109

110+
test('minify option as an object', (t) => {
111+
const out = standard({ minify: { minifySvg: false, foo: 'bar' } })
112+
t.truthy(out.plugins[out.plugins.length - 1].name === 'minifyPlugin')
113+
})
114+
110115
test('locals option', (t) => {
111116
const undo = standardRewired.__set__('evalCode', (opts) => {
112117
t.truthy(opts === true)

0 commit comments

Comments
 (0)