diff --git a/README.md b/README.md index 262372ca..97ca5480 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,31 @@ -# html loader for webpack +# DEPRECATED + +This is only used by the now outdated 8.x version of vue-loader. + +--- + +# vue-html-loader + +> This is a fork of [html-loader](https://github.com/webpack/html-loader) with some modifications for handling Vue templates. + +## Config + +You can config the loader's behavior by adding an `html` field under `vue` in your webpack config: + +``` js +// webpack.config.js +module.exports = { + // ... + vue: { + html: { + // all loader queries can be specified here + // also, you can specify options for htmlMinifier here. + } + } +} +``` + +## Original README below Exports HTML as string. HTML is minimized when the compiler demands. @@ -87,46 +114,6 @@ require("html?interpolate!./file.html");
${require('./partials/gallery.html')}
``` -## Advanced options - -If you need to pass [more advanced options](https://github.com/webpack/html-loader/pull/46), especially those which cannot be stringified, you can also define an `htmlLoader`-property on your `webpack.config.js`: - -``` javascript -module.exports = { - ... - module: { - loaders: [ - { - test: /\.html$/, - loader: "html" - } - ] - } - htmlLoader: { - ignoreCustomFragments: [/\{\{.*?}}/] - } -}; -``` - -If you need to define two different loader configs, you can also change the config's property name via `html?config=otherHtmlLoaderConfig`: - -```javascript -module.exports = { - ... - module: { - loaders: [ - { - test: /\.html$/, - loader: "html?config=otherHtmlLoaderConfig" - } - ] - } - otherHtmlLoaderConfig: { - ... - } -}; -``` - ## License MIT (http://www.opensource.org/licenses/mit-license.php) diff --git a/index.js b/index.js index d751899d..c111f499 100644 --- a/index.js +++ b/index.js @@ -14,12 +14,9 @@ function randomIdent() { } function getLoaderConfig(context) { - var query = loaderUtils.parseQuery(context.query); - var configKey = query.config || 'htmlLoader'; - var config = context.options && context.options.hasOwnProperty(configKey) ? context.options[configKey] : {}; - + var query = loaderUtils.getOptions(context) || {}; + var config = (context.options && context.options.vue && context.options.vue.html) || {}; delete query.config; - return assign(query, config); } @@ -77,10 +74,8 @@ module.exports = function(content) { "removeAttributeQuotes", "useShortDoctype", "keepClosingSlash", - "minifyJS", - "minifyCSS", "removeScriptTypeAttributes", - "removeStyleTypeAttributes", + "removeStyleLinkTypeAttributes" ].forEach(function(name) { if(typeof minimizeOptions[name] === "undefined") { minimizeOptions[name] = true; diff --git a/lib/attributesParser.js b/lib/attributesParser.js index ff49026f..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 - "(([0-9a-zA-Z\\-:]+)\\s*=\\s*\")([^\"]*)\"": processMatch, - "(([0-9a-zA-Z\\-:]+)\\s*=\\s*\')([^\']*)\'": processMatch, - "(([0-9a-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 } }); diff --git a/package.json b/package.json index 0389d29e..3c0199a6 100644 --- a/package.json +++ b/package.json @@ -1,30 +1,25 @@ { - "name": "html-loader", - "version": "0.4.3", - "author": "Tobias Koppers @sokra", - "description": "html loader module for webpack", + "name": "vue-html-loader", + "version": "1.2.4", + "author": "Evan You", + "description": "vue template loader for webpack", "dependencies": { "es6-templates": "^0.2.2", "fastparse": "^1.0.0", - "html-minifier": "^1.0.0", - "loader-utils": "~0.2.2", - "object-assign": "^4.0.1" + "html-minifier": "^2.1.5", + "loader-utils": "^1.0.2", + "object-assign": "^4.1.0" }, "devDependencies": { "mocha": "^2.3.4", - "should": "^7.1.1" + "should": "^9.0.2" }, "scripts": { "test": "mocha --reporter spec" }, "repository": { "type": "git", - "url": "git@github.com:webpack/html-loader.git" + "url": "git@github.com:vuejs/vue-html-loader.git" }, - "licenses": [ - { - "type": "MIT", - "url": "http://www.opensource.org/licenses/mit-license.php" - } - ] + "license": "MIT" } diff --git a/test/loaderTest.js b/test/loaderTest.js index cb024368..faf5f6fd 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}

";' ); }); // https://github.com/webpack/webpack/issues/752 @@ -46,7 +46,7 @@ describe("loader", function() { loader.call({ minimize: true }, '').should.be.eql( - 'module.exports = "";' + 'module.exports = "";' ); }); it("should preserve comments", function() { @@ -54,7 +54,7 @@ describe("loader", function() { minimize: true, query: "?-removeComments" }, '

#{number} {customer}

{title}

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

#{number} {customer}

{title}

";' + 'module.exports = "

#{number} {customer}

{title}

";' ); }); it("should treat attributes as case sensitive", function() { @@ -62,34 +62,30 @@ describe("loader", function() { minimize: true, query: "?caseSensitive" }, '

#{number} {customer}

{title}

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

#{number} {customer}

{title}

";' + 'module.exports = "

#{number} {customer}

{title}

";' ); }); it("should accept complex options via a webpack config property", function() { loader.call({ minimize: true, options: { - htmlLoader: { - ignoreCustomFragments: [/\{\{.*?}}/] + vue: { + html: { + ignoreCustomFragments: [/\{\{.*?}}/] + } } } }, '

{{ count <= 1 ? "foo" : "bar" }}

').should.be.eql( 'module.exports = "

{{ count <= 1 ? \\"foo\\" : \\"bar\\" }}

";' ); }); - it("should allow the webpack config property name to be configured", function() { - loader.call({ - minimize: true, - options: { - htmlLoaderSuperSpecialConfig: { - ignoreCustomFragments: [/\{\{.*?}}/] - } - }, - query: '?config=htmlLoaderSuperSpecialConfig' - }, '

{{ count <= 1 ? "foo" : "bar" }}

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

{{ count <= 1 ? \\"foo\\" : \\"bar\\" }}

";' + 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 ";' diff --git a/test/parserTest.js b/test/parserTest.js index aa05c64a..a49c4bd8 100644 --- a/test/parserTest.js +++ b/test/parserTest.js @@ -9,6 +9,7 @@ function test(name, html, result) { if(tag === "link" && attr === "href") return true; if(tag === "div" && attr === "data-videomp4") return true; if(tag === "use" && attr === "xlink:href") return true; + if(tag === "div" && /data-/.test(attr)) return true; return false; }).map(function(match) { return match.value }).should.be.eql(result); }); @@ -32,6 +33,7 @@ describe("parser", function() { test("doctype", '', ["image.png"]); test("alphanumeric", '
', ["video.mp4"]); test("use", '', ["vector.svg"]); + test("vue shorthands", '', []); }); describe("locations", function() { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy