html-loader
Advanced tools
Comparing version 0.3.0 to 0.4.0
46
index.js
@@ -10,2 +10,4 @@ /* | ||
var url = require("url"); | ||
var assign = require("object-assign"); | ||
var compile = require("es6-templates").compile; | ||
@@ -40,11 +42,10 @@ function randomIdent() { | ||
if(!loaderUtils.isUrlRequest(link.value, root)) return; | ||
var uri = url.parse(link.value); | ||
if (uri.hash !== null && uri.hash !== undefined) { | ||
uri.hash = null; | ||
link.value = uri.format(); | ||
link.length = link.value.length; | ||
uri.hash = null; | ||
link.value = uri.format(); | ||
link.length = link.value.length; | ||
} | ||
do { | ||
@@ -62,14 +63,29 @@ var ident = randomIdent(); | ||
if(typeof query.minimize === "boolean" ? query.minimize : this.minimize) { | ||
content = htmlMinifier.minify(content, { | ||
removeComments: query.removeComments !== false, | ||
collapseWhitespace: query.collapseWhitespace !== false, | ||
collapseBooleanAttributes: query.collapseBooleanAttributes !== false, | ||
removeAttributeQuotes: query.removeAttributeQuotes !== false, | ||
removeRedundantAttributes: query.removeRedundantAttributes !== false, | ||
useShortDoctype: query.useShortDoctype !== false, | ||
removeEmptyAttributes: query.removeEmptyAttributes !== false, | ||
removeOptionalTags: query.removeOptionalTags !== false | ||
var minimizeOptions = assign({}, query); | ||
[ | ||
"removeComments", | ||
"collapseWhitespace", | ||
"collapseBooleanAttributes", | ||
"removeAttributeQuotes", | ||
"removeRedundantAttributes", | ||
"useShortDoctype", | ||
"removeEmptyAttributes", | ||
"removeOptionalTags" | ||
].forEach(function(name) { | ||
if (typeof minimizeOptions[name] === "undefined") { | ||
minimizeOptions[name] = true; | ||
} | ||
}); | ||
content = htmlMinifier.minify(content, minimizeOptions); | ||
} | ||
return "module.exports = " + JSON.stringify(content).replace(/xxxHTMLLINKxxx[0-9\.]+xxx/g, function(match) { | ||
if (query.interpolate) { | ||
content = compile('`' + content + '`').code; | ||
} else { | ||
content = JSON.stringify(content); | ||
} | ||
return "module.exports = " + content.replace(/xxxHTMLLINKxxx[0-9\.]+xxx/g, function(match) { | ||
if(!data[match]) return match; | ||
@@ -76,0 +92,0 @@ return '" + require(' + JSON.stringify(loaderUtils.urlToRequest(data[match], root)) + ') + "'; |
@@ -30,5 +30,5 @@ /* | ||
">": "outside", // end of attributes | ||
"(([a-zA-Z\\-]+)\\s*=\\s*\")([^\"]*)\"": processMatch, | ||
"(([a-zA-Z\\-]+)\\s*=\\s*\')([^\']*)\'": processMatch, | ||
"(([a-zA-Z\\-]+)\\s*=\\s*)([^\\s>]+)": processMatch | ||
"(([a-zA-Z\\-:]+)\\s*=\\s*\")([^\"]*)\"": processMatch, | ||
"(([a-zA-Z\\-:]+)\\s*=\\s*\')([^\']*)\'": processMatch, | ||
"(([a-zA-Z\\-:]+)\\s*=\\s*)([^\\s>]+)": processMatch | ||
} | ||
@@ -35,0 +35,0 @@ }); |
{ | ||
"name": "html-loader", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"author": "Tobias Koppers @sokra", | ||
"description": "html loader module for webpack", | ||
"dependencies": { | ||
"html-minifier": "^0.7.2", | ||
"source-map": "0.1.x", | ||
"es6-templates": "^0.2.2", | ||
"fastparse": "^1.0.0", | ||
"loader-utils": "~0.2.2" | ||
"html-minifier": "^1.0.0", | ||
"loader-utils": "~0.2.2", | ||
"object-assign": "^4.0.1", | ||
"source-map": "^0.5.3" | ||
}, | ||
"devDependencies": { | ||
"mocha": "1.17.x", | ||
"should": "3.1.x" | ||
"mocha": "^2.3.4", | ||
"should": "^7.1.1" | ||
}, | ||
@@ -16,0 +18,0 @@ "scripts": { |
@@ -9,2 +9,4 @@ # html loader for webpack | ||
To completely disable tag-attribute processing (for instance, if you're handling image loading on the client side) you can pass in `attrs=false`. | ||
## Usage | ||
@@ -46,2 +48,5 @@ | ||
require("html?-attrs!./file.html"); | ||
// => '<img src="image.jpg" data-src="image2x.png" >' | ||
/// minimized by running `webpack --optimize-minimize` | ||
@@ -74,4 +79,17 @@ // => '<img src=http://cdn.example.com/49e...ba9f/a9f...92ca.jpg data-src=data:image/png;base64,...>' | ||
## Interpolation | ||
You can use `interpolate` flag to enable interpolation syntax for ES6 template strings, like so: | ||
``` | ||
require("html?interpolate!./file.html"); | ||
``` | ||
``` | ||
<img src="${require(`./images/gallery.png`)}" /> | ||
<div>${require('./partials/gallery.html')}</div> | ||
``` | ||
## License | ||
MIT (http://www.opensource.org/licenses/mit-license.php) |
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
7346
120
93
6
+ Addedes6-templates@^0.2.2
+ Addedobject-assign@^4.0.1
+ Addedalign-text@0.1.4(transitive)
+ Addedast-types@0.9.6(transitive)
+ Addedcenter-align@0.1.3(transitive)
+ Addedclean-css@3.4.28(transitive)
+ Addedcliui@2.1.0(transitive)
+ Addedcommander@2.8.12.9.0(transitive)
+ Addedconcat-stream@1.5.2(transitive)
+ Addedes6-templates@0.2.3(transitive)
+ Addedesprima@3.1.3(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)
+ Addedhe@1.0.0(transitive)
+ Addedhtml-minifier@1.5.0(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedkind-of@3.2.2(transitive)
+ Addedlazy-cache@1.0.4(transitive)
+ Addedlongest@1.0.1(transitive)
+ Addedncname@1.0.0(transitive)
+ Addedprivate@0.1.8(transitive)
+ Addedprocess-nextick-args@1.0.7(transitive)
+ Addedreadable-stream@2.0.6(transitive)
+ Addedrecast@0.11.23(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedright-align@0.1.3(transitive)
+ Addedsource-map@0.4.40.5.7(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addeduglify-js@2.6.4(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedxml-char-classes@1.0.0(transitive)
+ Addedyargs@3.10.0(transitive)
- Removedclean-css@3.1.9(transitive)
- Removedcli@0.6.6(transitive)
- Removedcommander@2.6.0(transitive)
- Removedconcat-stream@1.4.11(transitive)
- Removedexit@0.1.2(transitive)
- Removedglob@3.2.11(transitive)
- Removedhtml-minifier@0.7.2(transitive)
- Removedisarray@0.0.1(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@0.3.0(transitive)
- Removedreadable-stream@1.1.14(transitive)
- Removedsigmund@1.0.1(transitive)
- Removedsource-map@0.1.340.1.43(transitive)
- Removeduglify-js@2.4.24(transitive)
- Removedyargs@3.5.4(transitive)
Updatedhtml-minifier@^1.0.0
Updatedsource-map@^0.5.3