From b2f7637d8f7a7a016c413b73136afe49a4bbf38c Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 1 Oct 2015 14:34:42 -0400 Subject: [PATCH 1/6] bump html-minifier version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7a0d4c65..21dbd162 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "author": "Tobias Koppers @sokra", "description": "html loader module for webpack", "dependencies": { - "html-minifier": "^0.7.2", + "html-minifier": "^0.8.0", "source-map": "0.1.x", "fastparse": "^1.0.0", "loader-utils": "~0.2.2" From 3656083f6dbb9d8dae3240f34745bf8b680dcedf Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 1 Oct 2015 14:38:05 -0400 Subject: [PATCH 2/6] bump dependencies and fix test --- package.json | 6 +++--- test/loaderTest.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 21dbd162..edd856fc 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "description": "html loader module for webpack", "dependencies": { "html-minifier": "^0.8.0", - "source-map": "0.1.x", - "fastparse": "^1.0.0", - "loader-utils": "~0.2.2" + "source-map": "^0.5.1", + "fastparse": "^1.1.1", + "loader-utils": "^0.2.11" }, "devDependencies": { "mocha": "1.17.x", diff --git a/test/loaderTest.js b/test/loaderTest.js index 104d11d6..74c0b166 100644 --- a/test/loaderTest.js +++ b/test/loaderTest.js @@ -38,7 +38,7 @@ describe("loader", function() { loader.call({ minimize: true }, '

#{number} {customer}

\n

{title}

\n\t ').should.be.eql( - 'module.exports = "

#{number} {customer}

{title}

";' + 'module.exports = "

#{number} {customer}

{title}

";' ); }); it("should not translate root-relative urls (without root query)", function() { From 0a3832ea3404694a3132531c378735d1098a9893 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 1 Oct 2015 14:46:58 -0400 Subject: [PATCH 3/6] parser: support full valid attr charset --- lib/attributesParser.js | 8 ++++---- test/parserTest.js | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/attributesParser.js b/lib/attributesParser.js index 507b7207..22589c63 100644 --- a/lib/attributesParser.js +++ b/lib/attributesParser.js @@ -27,9 +27,9 @@ var parser = new Parser({ inside: { "\\s+": true, // eat up whitespace ">": "outside", // end of attributes - "(([a-zA-Z\\-]+)\\s*=\\s*\")([^\"]*)\"": processMatch, - "(([a-zA-Z\\-]+)\\s*=\\s*\')([^\']*)\'": processMatch, - "(([a-zA-Z\\-]+)\\s*=\\s*)([^\\s>]+)": processMatch + "(([0-9a-zA-Z\\-:\.]+)\\s*=\\s*\")([^\"]*)\"": processMatch, + "(([0-9a-zA-Z\\-:\.]+)\\s*=\\s*\')([^\']*)\'": processMatch, + "(([0-9a-zA-Z\\-:\.]+)\\s*=\\s*)([^\\s>]+)": processMatch } }); @@ -40,4 +40,4 @@ module.exports = function parse(html, isRelevantTagAttr) { results: [], isRelevantTagAttr: isRelevantTagAttr }).results; -}; \ No newline at end of file +}; diff --git a/test/parserTest.js b/test/parserTest.js index 6ba940e7..96ffa7b1 100644 --- a/test/parserTest.js +++ b/test/parserTest.js @@ -7,6 +7,7 @@ function test(name, html, result) { attrParse(html, function(tag, attr) { if(tag === "img" && attr === "src") return true; if(tag === "link" && attr === "href") return true; + if(tag === "div" && /data-/.test(attr)) return true; return false; }).map(function(match) { return match.value }).should.be.eql(result); }); @@ -28,6 +29,8 @@ describe("parser", function() { test("tags", '', ["image.png", "style.css"]); test("cdata", ']]>', ["image2.png"]); test("doctype", '', ["image.png"]); + test("alphanumeric", '
', ["video.mp4"]); + test("vue shorthands", '', []); }); describe("locations", function() { @@ -38,4 +41,4 @@ describe("locations", function() { value: "image.png" }]); }); -}); \ No newline at end of file +}); From 41632ef7c54b5166ad273cbe962f6a2ef5f23e24 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 1 Oct 2015 14:51:52 -0400 Subject: [PATCH 4/6] add support for minifying vue 1.0 templates --- index.js | 5 +++-- test/loaderTest.js | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 928ee2ab..238311d0 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,6 @@ function randomIdent() { return "xxxHTMLLINKxxx" + Math.random() + Math.random() + "xxx"; }; - module.exports = function(content) { this.cacheable && this.cacheable(); var query = loaderUtils.parseQuery(this.query); @@ -65,7 +64,9 @@ module.exports = function(content) { removeRedundantAttributes: query.removeRedundantAttributes !== false, useShortDoctype: query.useShortDoctype !== false, removeEmptyAttributes: query.removeEmptyAttributes !== false, - removeOptionalTags: query.removeOptionalTags !== false + removeOptionalTags: query.removeOptionalTags !== false, + // required for Vue 1.0 shorthand syntax + customAttrSurround: [[/@/, new RegExp('')], [/:/, new RegExp('')]] }); } return "module.exports = " + JSON.stringify(content).replace(/xxxHTMLLINKxxx[0-9\.]+xxx/g, function(match) { diff --git a/test/loaderTest.js b/test/loaderTest.js index 74c0b166..692fc6af 100644 --- a/test/loaderTest.js +++ b/test/loaderTest.js @@ -41,6 +41,13 @@ describe("loader", function() { 'module.exports = "

#{number} {customer}

{title}

";' ); }); + it('should minimize vue template', function () { + loader.call({ + minimize: true + }, '
\n hihihi {{what}} \n
').should.be.eql( + 'module.exports = "
hihihi {{what}}
";' + ); + }) it("should not translate root-relative urls (without root query)", function() { loader.call({}, 'Text ').should.be.eql( 'module.exports = "Text ";' From a42a48aa9f21350edbc8a1d9bb5978b776353991 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 1 Oct 2015 14:52:16 -0400 Subject: [PATCH 5/6] change package name-version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index edd856fc..23ff07e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "html-loader", - "version": "0.3.0", + "name": "vue-html-loader", + "version": "1.0.0", "author": "Tobias Koppers @sokra", "description": "html loader module for webpack", "dependencies": { From 253b71db9232a540dca8a27e77b3ddd457a9494a Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 1 Oct 2015 14:54:10 -0400 Subject: [PATCH 6/6] update readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 084f1c62..54d820f9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# html loader for webpack +# vue-html-loader + +> This is a fork of the webpack html-loader with some parser improvements and some Vue.js specific fixes. Used by vue-loader as a peer dependency. Usage is exactly the same with the original html-loader. Exports HTML as string. HTML is minimized when the compiler demands.