adding options for html minify

develop
HerrHase 2 years ago
parent 64b673e236
commit 4f76b36973

@ -3,11 +3,12 @@ const fs = require('fs')
class HappySiteWebpackPlugin {
constructor(source, views, destination = null) {
constructor(source, views, destination = null, options = {}) {
this._options = {
source: source,
views: views,
destination: destination
destination: destination,
options: options
}
if (!fs.existsSync(source)) {
@ -38,7 +39,7 @@ class HappySiteWebpackPlugin {
this._options.destination = compilation.outputOptions.path
}
const happySite = new HappySite(this._options.source, this._options.views, this._options.destination)
const happySite = new HappySite(this._options.source, this._options.views, this._options.destination, this._options.options)
happySite.run()
})
}

@ -55,6 +55,17 @@ class Engine {
data = Object.assign({}, data, this._defaults)
this.nunjucks.render(view, data, (error, response) => {
const options = configStore.get('options')
if (options.minifyHtml === true) {
response = minify(response, {
removeComments: true,
collapseWhitespace: true,
collapseInlineTagWhitespace: true
})
}
done(error, response)
})
}

@ -29,7 +29,7 @@ class HappySite {
* @param {string} destination
*
*/
constructor(source, views, destination) {
constructor(source, views, destination, options = {}) {
this._source = source
this._views = views
this._destination = destination
@ -37,6 +37,9 @@ class HappySite {
configStore.set('source', source)
configStore.set('destination', destination)
configStore.set('views', views)
configStore.set('options', Object.assign({}, {
'minifyHtml': true
}, options))
// get config for site
if (fs.existsSync(this._source + '/site.yml')) {

Loading…
Cancel
Save