html-compression-webpack-plugin
Advanced tools
Comparing version 0.2.2 to 0.2.3
31
index.js
@@ -11,2 +11,3 @@ /* | ||
var path = require('path'); | ||
var del = require('del'); | ||
@@ -17,4 +18,4 @@ var RawSource = require("webpack-sources/lib/RawSource"); | ||
options = options || {}; | ||
this.asset = options.asset || "[path].gz[query]"; | ||
this.algorithm = options.algorithm || "gzip"; | ||
this.asset = options.hasOwnProperty('asset') ? options.asset : "[path].gz[query]"; | ||
this.algorithm = options.hasOwnProperty('algorithm') ? options.algorithm : "gzip"; | ||
this.compressionOptions = {}; | ||
@@ -31,6 +32,6 @@ if(typeof this.algorithm === "string") { | ||
verbose_more: options.hasOwnProperty('verbose_more') ? options.verbose_more : false, | ||
numiterations: options.numiterations ? options.numiterations : 15, | ||
numiterations: options.hasOwnProperty('numiterations') ? options.numiterations : 15, | ||
blocksplitting: options.hasOwnProperty('blocksplitting') ? options.blocksplitting : true, | ||
blocksplittinglast: options.hasOwnProperty('blocksplittinglast') ? options.blocksplittinglast : false, | ||
blocksplittingmax: options.blocksplittingmax ? options.blocksplittingmax : 15 | ||
blocksplittingmax: options.hasOwnProperty('blocksplittingmax') ? options.blocksplittingmax : 15 | ||
}; | ||
@@ -55,12 +56,14 @@ this.algorithm = function (content, options, fn) { | ||
} | ||
this.testHTML = options.testHTML || /\.html$/ | ||
this.test = options.test || /.*\.(js|css)$/i | ||
this.threshold = options.threshold || 0; | ||
this.testHTML = options.hasOwnProperty('testHTML') ? options.testHTML : /\.html$/ | ||
this.test = options.hasOwnProperty('test') ? options.test : /.*\.(js|css)$/i | ||
this.threshold = options.hasOwnProperty('threshold') ? options.threshold : 0; | ||
this.minRatio = options.hasOwnProperty('minRatio') ? options.minRatio : 0.8; | ||
this.deleteOriginals = options.hasOwnProperty('deleteOriginals') ? options.deleteOriginals : true; | ||
this.assetsRelativeOutputDirectory = options.assetsRelativeOutputDirectory | ||
this.deleteOriginals = options.hasOwnProperty('deleteOriginals') ? options.deleteOriginals : false; | ||
this.assetsRelativeOutputDirectory = options.hasOwnProperty('assetsRelativeOutputDirectory') ? options.assetsRelativeOutputDirectory : '' | ||
this.originalAssetsPaths = new Array(); | ||
if(!this.assetsRelativeOutputDirectory && this.deleteOriginals) | ||
if(this.deleteOriginals === true && this.assetsRelativeOutputDirectory === ''){ | ||
throw new Error('Set relative output directory of assets when enabling deletion of original files'); | ||
} | ||
} | ||
module.exports = HTMLCompressionPlugin; | ||
@@ -140,6 +143,8 @@ | ||
compiler.plugin('done', function(stats) { | ||
for (var i in this.originalAssetsPaths) { | ||
fs.unlink(this.originalAssetsPaths[i]); | ||
if(this.deleteOriginals === true){ | ||
for (var i in this.originalAssetsPaths) { | ||
del.sync([this.originalAssetsPaths[i]]); | ||
} | ||
} | ||
}.bind(this)); | ||
}; | ||
}; |
{ | ||
"name": "html-compression-webpack-plugin", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"author": "Tobias Koppers @sokra & Tom De Backer @TomDeBacker", | ||
"description": "Prepare compressed versions of assets to serve them with Content-Encoding.", | ||
"devDependencies": { | ||
"react": "15.0.1", | ||
"react-dom": "15.0.1", | ||
"webpack": "2.1.0-beta.27", | ||
"file-loader": "0.9.0", | ||
"mocha": "3.2.0", | ||
"html-webpack-plugin": "2.24.1", | ||
"babel-preset-es2015": "6.18.0", | ||
"babel-preset-stage-0": "6.16.0", | ||
"babel-preset-react": "6.16.0", | ||
"babel-loader": "6.2.8", | ||
"babel-core": "6.18.2", | ||
"css-loader": "0.26.1", | ||
"style-loader": "0.13.1", | ||
"extract-text-webpack-plugin": "2.0.0-beta.4" | ||
}, | ||
"dependencies": { | ||
"async": "0.2.x", | ||
"webpack-sources": "^0.1.0" | ||
"webpack-sources": "^0.1.0", | ||
"del": "2.2.2" | ||
}, | ||
@@ -23,3 +40,6 @@ "optionalDependencies": { | ||
} | ||
] | ||
], | ||
"scripts": { | ||
"test": "mocha" | ||
} | ||
} |
# HTML compression plugin for webpack | ||
## Version 0.2.* doesn't work properly for me. Use 0.2.0 instead if you experience the same. | ||
## Info | ||
@@ -36,3 +35,3 @@ | ||
* `algorithm`: Can be a `function(buf, callback)` or a string. For a string the algorithm is taken from `zlib` (or zopfli for `zopfli`). Defaults to `"gzip"`. | ||
* `deleteOriginals`: All original assets which have been compressed will be deleted in the done phase. The stats after bundling will show the files emitted but they will be deleted. Defaults to `true` | ||
* `deleteOriginals`: All original assets which have been compressed will be deleted in the done phase. The stats after bundling will show the files emitted but they will be deleted. Defaults to `false` | ||
* `test`: All assets matching this RegExp are processed. Defaults to `/.*\.(js|css)$/i` | ||
@@ -44,11 +43,19 @@ * `testHTML`: All assets matching this RegExp are processed. This will happen in the emit phase. Defaults to `/\.html$/` | ||
Option Arguments for Zopfli (see [node-zopfli](https://github.com/pierreinglebert/node-zopfli#options) doc for details): | ||
* verbose: Default: false, | ||
* verbose_more: Default: false, | ||
* numiterations: Default: 15, | ||
* blocksplitting: Default: true, | ||
* blocksplittinglast: Default: false, | ||
* blocksplittingmax: Default: 15 | ||
* `verbose`: Default: false, | ||
* `verbose_more`: Default: false, | ||
* `numiterations`: Default: 15, | ||
* `blocksplitting`: Default: true, | ||
* `blocksplittinglast`: Default: false, | ||
* `blocksplittingmax`: Default: 15 | ||
## Example | ||
To try out the example: | ||
`node example/run-to-bundle-example-project.js` | ||
The resulting files will be created `example/build` folder. | ||
## License | ||
MIT (http://www.opensource.org/licenses/mit-license.php) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11214
11
208
60
4
14
+ Addeddel@2.2.2
+ Addedarray-union@1.0.2(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddel@2.2.2(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglobby@5.0.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedis-path-cwd@1.0.0(transitive)
+ Addedis-path-in-cwd@1.0.1(transitive)
+ Addedis-path-inside@1.0.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-is-inside@1.0.2(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedrimraf@2.7.1(transitive)