From 725aeb20d497a4130c921a674beb69fd43433035 Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Thu, 7 May 2015 14:02:59 +0200
Subject: [PATCH 001/281] Initial commit
---
LICENSE | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 LICENSE
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 000000000..2c8fd9923
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Q42
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
From 8bac681379828e6de7a2117ff80009b0ad748493 Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Thu, 7 May 2015 14:08:53 +0200
Subject: [PATCH 002/281] Create README.md
---
README.md | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
create mode 100644 README.md
diff --git a/README.md b/README.md
new file mode 100644
index 000000000..a55de700b
--- /dev/null
+++ b/README.md
@@ -0,0 +1,83 @@
+# vue-multi-loader
+
+> Vue.js component loader for [Webpack](http://webpack.github.io), using Webpack loaders for the parts.
+
+It allows you to write your components in this format:
+
+``` html
+// app.vue
+
+
+
+
{{msg}}
+
+
+
+```
+
+You can also mix preprocessor languages in the component file:
+
+``` html
+// app.vue
+
+
+
+h1(class="red") {{msg}}
+
+
+
+```
+
+And you can import using the `src` attribute (note that there's no need for a `lang` attribute here, as Webpack will
+be used to determine which loader applies):
+
+``` html
+
+```
+
+## Usage
+
+Config Webpack:
+
+``` js
+// webpack.config.js
+module.exports = {
+ entry: "./main.js",
+ output: {
+ filename: "build.js"
+ },
+ module: {
+ loaders: [
+ { test: /\.vue$/, loader: "vue-multi-loader" },
+ ]
+ }
+}
+```
+
+And this is all you need to do in your main entry file:
+
+``` js
+// main.js
+var Vue = require('vue')
+var appOptions = require('./app.vue')
+var app = new Vue(appOptions).$mount('#app')
+```
From f90373017aa1930e173e2d2150924464d12adfdb Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Thu, 7 May 2015 14:30:39 +0200
Subject: [PATCH 003/281] First version
---
.gitignore | 1 +
index.js | 46 +++++++++++++++++++++++++++++++++
package.json | 24 ++++++++++++++++++
parser.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
selector.js | 13 ++++++++++
5 files changed, 156 insertions(+)
create mode 100644 .gitignore
create mode 100644 index.js
create mode 100644 package.json
create mode 100644 parser.js
create mode 100644 selector.js
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..07e6e472c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/node_modules
diff --git a/index.js b/index.js
new file mode 100644
index 000000000..bd7d15e51
--- /dev/null
+++ b/index.js
@@ -0,0 +1,46 @@
+module.exports = function (content) {
+ this.cacheable();
+ var cb = this.async();
+ var languages = {}
+ var output = ''
+ var vueUrl = this.resource;
+ var loaders = {}
+ var loaderPrefix = {
+ template: 'html!',
+ style: 'style!css!',
+ script: ''
+ }
+
+ function loader(part, lang) {
+ var loader = loaders[lang] || loaderPrefix[part] + lang;
+ return loader ? loader + '!' : ''
+ }
+
+ function getRequire(part, lang) {
+ return 'require(' + JSON.stringify('-!' + loader(part, lang) + require.resolve('./selector.js') + '?' + part + '/' + lang + '!' + vueUrl) + ')';
+ }
+
+ var me = this;
+ var url = "!!" + require.resolve("./parser.js") + "!" + vueUrl;
+ this.loadModule(url, function(err, source, map, module) {
+ if (err) return cb(err);
+
+ var parts = me.exec(source, url);
+
+ for (var lang in parts.style)
+ output += getRequire('style', lang) + '\n'
+
+ for (var lang in parts.script)
+ output += 'module.exports = ' + getRequire('script', lang) + '\n'
+
+ var hasTemplate = false;
+ for (var lang in parts.template) {
+ if (hasTemplate)
+ return cb(new Error('Only one template element allowed per vue component!'))
+ output += 'module.exports.template = ' + getRequire('template', lang);
+ hasTemplate = true;
+ }
+
+ cb(null, output);
+ })
+}
diff --git a/package.json b/package.json
new file mode 100644
index 000000000..36a60bac3
--- /dev/null
+++ b/package.json
@@ -0,0 +1,24 @@
+{
+ "name": "vue-multi-loader",
+ "version": "0.0.1",
+ "description": "Vue.js component loader for Webpack, using Webpack loaders for the parts",
+ "main": "index.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/Q42/vue-multi-loader.git"
+ },
+ "keywords": [
+ "vue",
+ "webpack",
+ "loader"
+ ],
+ "author": "Sjoerd Visscher",
+ "license": "ISC",
+ "bugs": {
+ "url": "https://github.com/Q42/vue-multi-loader/issues"
+ },
+ "homepage": "https://github.com/Q42/vue-multi-loader",
+ "dependencies": {
+ "parse5": "^1.1.4"
+ }
+}
diff --git a/parser.js b/parser.js
new file mode 100644
index 000000000..8586e9d6a
--- /dev/null
+++ b/parser.js
@@ -0,0 +1,72 @@
+var parse5 = require('parse5')
+var parser = new parse5.Parser()
+var serializer = new parse5.TreeSerializer()
+
+module.exports = function (content) {
+ this.cacheable()
+ var cb = this.async()
+
+ // only 1 template tag is allowed, while styles and
+ // scripts are concatenated.
+ var languages = {}
+ var output = {
+ template: {},
+ style: {},
+ script: {},
+ includes: []
+ }
+
+ // parse the file into an HTML tree
+ var fragment = parser.parseFragment(content)
+
+ // Walk through the top level nodes and check for their
+ // types & languages. If there are pre-processing needed,
+ // push it into a jobs list.
+ fragment.childNodes.forEach(function (node) {
+ var type = node.nodeName;
+ if (type == '#text')
+ return
+ if (checkSrc(node, output.includes))
+ return
+
+ var lang = checkLang(node) || ''
+ output[type][lang] = (output[type][lang] || '') + serialize(node) + '\n'
+ })
+
+ cb(null, 'module.exports = ' + JSON.stringify(output))
+}
+
+function checkLang (node) {
+ if (node.attrs) {
+ var i = node.attrs.length
+ while (i--) {
+ var attr = node.attrs[i]
+ if (attr.name === 'lang') {
+ return attr.value
+ }
+ }
+ }
+}
+
+function checkSrc (node, arr) {
+ if (node.attrs) {
+ var i = node.attrs.length
+ while (i--) {
+ var attr = node.attrs[i]
+ if (attr.name === 'src') {
+ arr.push(attr.value)
+ return true
+ }
+ }
+ }
+ return false
+}
+
+// Work around changes in parse5 >= 1.2.0
+function serialize (node) {
+ var childNode = node.childNodes[0]
+ if (childNode && childNode.nodeName === '#document-fragment') {
+ return serializer.serialize(childNode)
+ }
+ return serializer.serialize(node)
+}
diff --git a/selector.js b/selector.js
new file mode 100644
index 000000000..3d0ce4bc1
--- /dev/null
+++ b/selector.js
@@ -0,0 +1,13 @@
+module.exports = function () {
+ this.cacheable()
+ var cb = this.async()
+ var path = this.query.substr(1).split('/')
+
+ var me = this
+ var url = "!!" + require.resolve("./parser.js") + "!" + this.resource
+ this.loadModule(url, function(err, source) {
+ if (err) return cb(err)
+ var parts = me.exec(source, url)
+ cb(null, parts[path[0]][path[1]])
+ })
+}
From 60eefdcbb247588876f7c5393272da861d24b301 Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Thu, 7 May 2015 16:13:54 +0200
Subject: [PATCH 004/281] Support src attributes
---
.gitignore | 1 +
index.js | 3 +++
package.json | 2 +-
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 07e6e472c..7a3a95d56 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
/node_modules
+/npm-debug.log
diff --git a/index.js b/index.js
index bd7d15e51..5db83c984 100644
--- a/index.js
+++ b/index.js
@@ -26,6 +26,9 @@ module.exports = function (content) {
if (err) return cb(err);
var parts = me.exec(source, url);
+
+ for (var i = 0; i < parts.includes.length; i++)
+ output += 'require(' + JSON.stringify('./' + parts.includes[i]) + ')\n'
for (var lang in parts.style)
output += getRequire('style', lang) + '\n'
diff --git a/package.json b/package.json
index 36a60bac3..ab4f232f9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-multi-loader",
- "version": "0.0.1",
+ "version": "0.0.2",
"description": "Vue.js component loader for Webpack, using Webpack loaders for the parts",
"main": "index.js",
"repository": {
From 9bc441f4bf8cfdab4f8f7ca1b7cdb7a372967dbe Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Sun, 10 May 2015 20:16:11 +0200
Subject: [PATCH 005/281] v0.0.3 support html languages that generate a
function
---
index.js | 35 +++++++++++++++++++++------------
package.json | 2 +-
parser.js | 55 +++++++++++++++++++++++-----------------------------
selector.js | 16 +++++++--------
4 files changed, 56 insertions(+), 52 deletions(-)
diff --git a/index.js b/index.js
index 5db83c984..7b4377847 100644
--- a/index.js
+++ b/index.js
@@ -1,19 +1,29 @@
module.exports = function (content) {
this.cacheable();
var cb = this.async();
- var languages = {}
- var output = ''
+ var languages = {};
+ var output = '';
var vueUrl = this.resource;
- var loaders = {}
+ var loaders = {
+ html: 'html',
+ css: 'style!css',
+ js: ''
+ };
var loaderPrefix = {
- template: 'html!',
+ template: '',
style: 'style!css!',
script: ''
- }
+ };
+ var defaultLang = {
+ template: 'html',
+ style: 'css',
+ script: 'js'
+ };
function loader(part, lang) {
- var loader = loaders[lang] || loaderPrefix[part] + lang;
- return loader ? loader + '!' : ''
+ lang = lang || defaultLang[part];
+ var loader = loaders[lang] !== undefined ? loaders[lang] : loaderPrefix[part] + lang;
+ return loader ? loader + '!' : '';
}
function getRequire(part, lang) {
@@ -26,21 +36,22 @@ module.exports = function (content) {
if (err) return cb(err);
var parts = me.exec(source, url);
-
+
for (var i = 0; i < parts.includes.length; i++)
- output += 'require(' + JSON.stringify('./' + parts.includes[i]) + ')\n'
+ output += 'require(' + JSON.stringify('./' + parts.includes[i]) + ')\n';
for (var lang in parts.style)
- output += getRequire('style', lang) + '\n'
+ output += getRequire('style', lang) + '\n';
for (var lang in parts.script)
- output += 'module.exports = ' + getRequire('script', lang) + '\n'
+ output += 'module.exports = ' + getRequire('script', lang) + '\n';
var hasTemplate = false;
for (var lang in parts.template) {
if (hasTemplate)
- return cb(new Error('Only one template element allowed per vue component!'))
+ return cb(new Error('Only one template element allowed per vue component!'));
output += 'module.exports.template = ' + getRequire('template', lang);
+ output += '\nif (module.exports.template instanceof Function) module.exports.template = module.exports.template({})';
hasTemplate = true;
}
diff --git a/package.json b/package.json
index ab4f232f9..52cfa24ed 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-multi-loader",
- "version": "0.0.2",
+ "version": "0.0.3",
"description": "Vue.js component loader for Webpack, using Webpack loaders for the parts",
"main": "index.js",
"repository": {
diff --git a/parser.js b/parser.js
index 8586e9d6a..39c83313f 100644
--- a/parser.js
+++ b/parser.js
@@ -1,48 +1,41 @@
-var parse5 = require('parse5')
-var parser = new parse5.Parser()
-var serializer = new parse5.TreeSerializer()
+var parse5 = require('parse5');
+var parser = new parse5.Parser();
+var serializer = new parse5.TreeSerializer();
module.exports = function (content) {
- this.cacheable()
- var cb = this.async()
+ this.cacheable();
+ var cb = this.async();
- // only 1 template tag is allowed, while styles and
- // scripts are concatenated.
- var languages = {}
+ var languages = {};
var output = {
template: {},
style: {},
script: {},
includes: []
- }
-
- // parse the file into an HTML tree
- var fragment = parser.parseFragment(content)
+ };
- // Walk through the top level nodes and check for their
- // types & languages. If there are pre-processing needed,
- // push it into a jobs list.
+ var fragment = parser.parseFragment(content);
fragment.childNodes.forEach(function (node) {
var type = node.nodeName;
if (type == '#text')
- return
+ return;
if (checkSrc(node, output.includes))
- return
+ return;
- var lang = checkLang(node) || ''
- output[type][lang] = (output[type][lang] || '') + serialize(node) + '\n'
- })
+ var lang = checkLang(node) || '';
+ output[type][lang] = (output[type][lang] || '') + serialize(node) + '\n';
+ });
- cb(null, 'module.exports = ' + JSON.stringify(output))
+ cb(null, 'module.exports = ' + JSON.stringify(output));
}
function checkLang (node) {
if (node.attrs) {
- var i = node.attrs.length
+ var i = node.attrs.length;
while (i--) {
- var attr = node.attrs[i]
+ var attr = node.attrs[i];
if (attr.name === 'lang') {
- return attr.value
+ return attr.value;
}
}
}
@@ -50,12 +43,12 @@ function checkLang (node) {
function checkSrc (node, arr) {
if (node.attrs) {
- var i = node.attrs.length
+ var i = node.attrs.length;
while (i--) {
- var attr = node.attrs[i]
+ var attr = node.attrs[i];
if (attr.name === 'src') {
- arr.push(attr.value)
- return true
+ arr.push(attr.value);
+ return true;
}
}
}
@@ -64,9 +57,9 @@ function checkSrc (node, arr) {
// Work around changes in parse5 >= 1.2.0
function serialize (node) {
- var childNode = node.childNodes[0]
+ var childNode = node.childNodes[0];
if (childNode && childNode.nodeName === '#document-fragment') {
- return serializer.serialize(childNode)
+ return serializer.serialize(childNode);
}
- return serializer.serialize(node)
+ return serializer.serialize(node);
}
diff --git a/selector.js b/selector.js
index 3d0ce4bc1..c4d85bed6 100644
--- a/selector.js
+++ b/selector.js
@@ -1,13 +1,13 @@
module.exports = function () {
- this.cacheable()
- var cb = this.async()
- var path = this.query.substr(1).split('/')
+ this.cacheable();
+ var cb = this.async();
+ var path = this.query.substr(1).split('/');
- var me = this
- var url = "!!" + require.resolve("./parser.js") + "!" + this.resource
+ var me = this;
+ var url = "!!" + require.resolve("./parser.js") + "!" + this.resource;
this.loadModule(url, function(err, source) {
- if (err) return cb(err)
- var parts = me.exec(source, url)
- cb(null, parts[path[0]][path[1]])
+ if (err) return cb(err);
+ var parts = me.exec(source, url);
+ cb(null, parts[path[0]][path[1]]);
})
}
From 511329371e764b0ef85e1d072292ab68d8aae5d6 Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Wed, 13 May 2015 15:56:25 +0200
Subject: [PATCH 006/281] Apply tips by @sokra
https://github.com/webpack/webpack/issues/860#issuecomment-100227750
---
index.js | 8 +++++---
package.json | 1 +
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/index.js b/index.js
index 7b4377847..be8abb981 100644
--- a/index.js
+++ b/index.js
@@ -1,9 +1,11 @@
+var loaderUtils = require("loader-utils");
+
module.exports = function (content) {
this.cacheable();
var cb = this.async();
var languages = {};
var output = '';
- var vueUrl = this.resource;
+ var vueUrl = loaderUtils.getRemainingRequest(this);
var loaders = {
html: 'html',
css: 'style!css',
@@ -27,7 +29,7 @@ module.exports = function (content) {
}
function getRequire(part, lang) {
- return 'require(' + JSON.stringify('-!' + loader(part, lang) + require.resolve('./selector.js') + '?' + part + '/' + lang + '!' + vueUrl) + ')';
+ return 'require(' + loaderUtils.stringifyRequest(this, '-!' + loader(part, lang) + require.resolve('./selector.js') + '?' + part + '/' + lang + '!' + vueUrl) + ')';
}
var me = this;
@@ -38,7 +40,7 @@ module.exports = function (content) {
var parts = me.exec(source, url);
for (var i = 0; i < parts.includes.length; i++)
- output += 'require(' + JSON.stringify('./' + parts.includes[i]) + ')\n';
+ output += 'require(' + loaderUtils.stringifyRequest(this, loaderUtils.urlToRequest(parts.includes[i])) + ')\n';
for (var lang in parts.style)
output += getRequire('style', lang) + '\n';
diff --git a/package.json b/package.json
index 52cfa24ed..d4f13b578 100644
--- a/package.json
+++ b/package.json
@@ -19,6 +19,7 @@
},
"homepage": "https://github.com/Q42/vue-multi-loader",
"dependencies": {
+ "loader-utils": "^0.2.7",
"parse5": "^1.1.4"
}
}
From e1987d95b6469c4c7c169fb42ce61cf11862d040 Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Thu, 14 May 2015 17:06:00 +0200
Subject: [PATCH 007/281] stringifyRequest strips trailing slashes even in
querystrings
---
selector.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/selector.js b/selector.js
index c4d85bed6..ffed1b3f9 100644
--- a/selector.js
+++ b/selector.js
@@ -8,6 +8,6 @@ module.exports = function () {
this.loadModule(url, function(err, source) {
if (err) return cb(err);
var parts = me.exec(source, url);
- cb(null, parts[path[0]][path[1]]);
+ cb(null, parts[path[0]][path[1]||'']);
})
}
From 19ea5d10ffcb3d26824ff559738511dd2505ff8f Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Thu, 14 May 2015 17:06:29 +0200
Subject: [PATCH 008/281] Fix bug
---
index.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/index.js b/index.js
index be8abb981..7f09ce574 100644
--- a/index.js
+++ b/index.js
@@ -28,8 +28,9 @@ module.exports = function (content) {
return loader ? loader + '!' : '';
}
+ var me = this;
function getRequire(part, lang) {
- return 'require(' + loaderUtils.stringifyRequest(this, '-!' + loader(part, lang) + require.resolve('./selector.js') + '?' + part + '/' + lang + '!' + vueUrl) + ')';
+ return 'require(' + loaderUtils.stringifyRequest(me, '-!' + loader(part, lang) + require.resolve('./selector.js') + '?' + part + '/' + lang + '!' + vueUrl) + ')';
}
var me = this;
From 2dabd6620f3dbeeba2e709f449be70868c9a1faf Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Thu, 14 May 2015 17:07:18 +0200
Subject: [PATCH 009/281] Use template-html-loader by default
instead of trying to execute template functions
---
index.js | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/index.js b/index.js
index 7f09ce574..67fcc3016 100644
--- a/index.js
+++ b/index.js
@@ -12,7 +12,7 @@ module.exports = function (content) {
js: ''
};
var loaderPrefix = {
- template: '',
+ template: 'html!template-html-loader?raw&engine=',
style: 'style!css!',
script: ''
};
@@ -54,7 +54,6 @@ module.exports = function (content) {
if (hasTemplate)
return cb(new Error('Only one template element allowed per vue component!'));
output += 'module.exports.template = ' + getRequire('template', lang);
- output += '\nif (module.exports.template instanceof Function) module.exports.template = module.exports.template({})';
hasTemplate = true;
}
From 2f7d5df45fe481d4ca2de4ffab3211a7f4019ae9 Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Thu, 14 May 2015 17:33:58 +0200
Subject: [PATCH 010/281] Loader configuration via query arguments
---
index.js | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/index.js b/index.js
index 67fcc3016..4e4a1b38f 100644
--- a/index.js
+++ b/index.js
@@ -6,11 +6,10 @@ module.exports = function (content) {
var languages = {};
var output = '';
var vueUrl = loaderUtils.getRemainingRequest(this);
- var loaders = {
- html: 'html',
- css: 'style!css',
- js: ''
- };
+ var loaders = loaderUtils.parseQuery(this.query);
+ loaders.html = loaders.html || 'html';
+ loaders.css = loaders.css || 'style!css';
+ loaders.js = loaders.js || '';
var loaderPrefix = {
template: 'html!template-html-loader?raw&engine=',
style: 'style!css!',
From e83905548f563f06ea3ecff2cbee5057f28453cb Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Fri, 15 May 2015 00:31:47 +0200
Subject: [PATCH 011/281] Helper function for loader configuration
---
index.js | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/index.js b/index.js
index 4e4a1b38f..4b013ca29 100644
--- a/index.js
+++ b/index.js
@@ -59,3 +59,7 @@ module.exports = function (content) {
cb(null, output);
})
}
+
+module.exports.withLoaders = function (opts) {
+ return 'vue-multi-loader?' + JSON.stringify(opts).replace(/!/g, '\\u0021')
+}
From e42864d490526a9a59626eec662aae3bcb799cdd Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Fri, 15 May 2015 00:42:03 +0200
Subject: [PATCH 012/281] source map support
---
package.json | 3 ++-
parser.js | 50 +++++++++++++++++++++++++++++++++++++++-----------
selector.js | 3 ++-
3 files changed, 43 insertions(+), 13 deletions(-)
diff --git a/package.json b/package.json
index d4f13b578..987d7dda4 100644
--- a/package.json
+++ b/package.json
@@ -20,6 +20,7 @@
"homepage": "https://github.com/Q42/vue-multi-loader",
"dependencies": {
"loader-utils": "^0.2.7",
- "parse5": "^1.1.4"
+ "parse5": "^1.1.4",
+ "source-map": "^0.4.2"
}
}
diff --git a/parser.js b/parser.js
index 39c83313f..9b9990f6a 100644
--- a/parser.js
+++ b/parser.js
@@ -1,10 +1,14 @@
var parse5 = require('parse5');
-var parser = new parse5.Parser();
+var parser = new parse5.Parser(null, { locationInfo: true });
var serializer = new parse5.TreeSerializer();
+var SourceNode = require("source-map").SourceNode;
+var loaderUtils = require("loader-utils");
module.exports = function (content) {
this.cacheable();
var cb = this.async();
+ var vueRequest = loaderUtils.getRemainingRequest(this);
+ var request = loaderUtils.getCurrentRequest(this);
var languages = {};
var output = {
@@ -14,6 +18,13 @@ module.exports = function (content) {
includes: []
};
+ function pos(offset) {
+ return {
+ line: content.substr(0, offset).split('\n').length,
+ col: offset - content.lastIndexOf('\n', offset - 1)
+ }
+ }
+
var fragment = parser.parseFragment(content);
fragment.childNodes.forEach(function (node) {
var type = node.nodeName;
@@ -23,9 +34,35 @@ module.exports = function (content) {
return;
var lang = checkLang(node) || '';
- output[type][lang] = (output[type][lang] || '') + serialize(node) + '\n';
+
+ // Work around changes in parse5 >= 1.2.0
+ var childNode = node.childNodes[0];
+ if (childNode && childNode.nodeName === '#document-fragment') {
+ node = childNode;
+ }
+
+ if (!node.childNodes.length)
+ return;
+
+ var start = node.childNodes[0].__location.start;
+ var end = node.childNodes[node.childNodes.length - 1].__location.end;
+ var lines = content.substring(start, end).split('\n');
+ var startPos = pos(start);
+ var sourceNodes = lines.map(function (line, i) {
+ return new SourceNode(startPos.line + i, i ? 0 : startPos.col, vueRequest, line + '\n');
+ });
+ output[type][lang] = (output[type][lang] || []).concat(sourceNodes)
});
+ for (var type in output) {
+ for (var lang in output[type]) {
+ var sourceNodes = output[type][lang];
+ output[type][lang] = new SourceNode(1, 1, vueRequest, sourceNodes).toStringWithSourceMap({
+ file: request
+ })
+ }
+ }
+
cb(null, 'module.exports = ' + JSON.stringify(output));
}
@@ -54,12 +91,3 @@ function checkSrc (node, arr) {
}
return false
}
-
-// Work around changes in parse5 >= 1.2.0
-function serialize (node) {
- var childNode = node.childNodes[0];
- if (childNode && childNode.nodeName === '#document-fragment') {
- return serializer.serialize(childNode);
- }
- return serializer.serialize(node);
-}
diff --git a/selector.js b/selector.js
index ffed1b3f9..956f2ea74 100644
--- a/selector.js
+++ b/selector.js
@@ -8,6 +8,7 @@ module.exports = function () {
this.loadModule(url, function(err, source) {
if (err) return cb(err);
var parts = me.exec(source, url);
- cb(null, parts[path[0]][path[1]||'']);
+ var part = parts[path[0]][path[1]||''];
+ cb(null, part.code, part.map);
})
}
From f9945eeee6692d2d19fb03ac193ff47095b52416 Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Fri, 15 May 2015 00:54:47 +0200
Subject: [PATCH 013/281] v0.0.4
---
README.md | 34 ++++++++++++++++++++++++++++++++++
package.json | 2 +-
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index a55de700b..aca832ae5 100644
--- a/README.md
+++ b/README.md
@@ -81,3 +81,37 @@ var Vue = require('vue')
var appOptions = require('./app.vue')
var app = new Vue(appOptions).$mount('#app')
```
+
+## Loader configuration
+
+By default, `vue-multi-loader` will try to use the loader with the same name as
+the `lang` attribute, but you can configure which loader should be used.
+
+For example, to extract out the generated css into a separate file,
+use this configuration:
+
+``` js
+// webpack.config.js
+var ExtractTextPlugin = require("extract-text-webpack-plugin");
+var vue = require("vue-multi-loader");
+
+module.exports = {
+ entry: "./main.js",
+ output: {
+ filename: "build.js"
+ },
+ module: {
+ loaders: [
+ {
+ test: /\.vue$/, loader: vue.withLoaders({
+ css: ExtractTextPlugin.extract("css"),
+ stylus: ExtractTextPlugin.extract("css!stylus")
+ })
+ },
+ ]
+ },
+ plugins: [
+ new ExtractTextPlugin("[name].css")
+ ]
+}
+```
diff --git a/package.json b/package.json
index 987d7dda4..c3f18bc47 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-multi-loader",
- "version": "0.0.3",
+ "version": "0.0.4",
"description": "Vue.js component loader for Webpack, using Webpack loaders for the parts",
"main": "index.js",
"repository": {
From 89d7d515025a8dd5d72285796f39dfafd91a86c0 Mon Sep 17 00:00:00 2001
From: Sjoerd Visscher
Date: Mon, 8 Jun 2015 13:39:55 +0200
Subject: [PATCH 014/281] v0.0.5 Parse with htmlparser2
Fixes #1
---
package.json | 2 +-
parser.js | 56 ++++++++++++++--------------------------------------
2 files changed, 16 insertions(+), 42 deletions(-)
diff --git a/package.json b/package.json
index c3f18bc47..92c06dc1a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-multi-loader",
- "version": "0.0.4",
+ "version": "0.0.5",
"description": "Vue.js component loader for Webpack, using Webpack loaders for the parts",
"main": "index.js",
"repository": {
diff --git a/parser.js b/parser.js
index 9b9990f6a..b6db5493e 100644
--- a/parser.js
+++ b/parser.js
@@ -1,5 +1,5 @@
var parse5 = require('parse5');
-var parser = new parse5.Parser(null, { locationInfo: true });
+var parser = new parse5.Parser(parse5.TreeAdapters.htmlparser2, { locationInfo: true });
var serializer = new parse5.TreeSerializer();
var SourceNode = require("source-map").SourceNode;
var loaderUtils = require("loader-utils");
@@ -26,26 +26,26 @@ module.exports = function (content) {
}
var fragment = parser.parseFragment(content);
- fragment.childNodes.forEach(function (node) {
- var type = node.nodeName;
- if (type == '#text')
+ fragment.children.forEach(function (node) {
+ if (node.attribs && node.attribs.src) {
+ output.includes.push(node.attribs.src)
return;
- if (checkSrc(node, output.includes))
+ }
+
+ if (!node.children || !node.children.length)
return;
- var lang = checkLang(node) || '';
+ var lang = (node.attribs && node.attribs.lang) || '';
+ var type = node.name;
+ if (!output[type])
+ return;
// Work around changes in parse5 >= 1.2.0
- var childNode = node.childNodes[0];
- if (childNode && childNode.nodeName === '#document-fragment') {
- node = childNode;
- }
+ if (node.children[0].type === 'root')
+ node = node.children[0];
- if (!node.childNodes.length)
- return;
-
- var start = node.childNodes[0].__location.start;
- var end = node.childNodes[node.childNodes.length - 1].__location.end;
+ var start = node.children[0].__location.start;
+ var end = node.children[node.children.length - 1].__location.end;
var lines = content.substring(start, end).split('\n');
var startPos = pos(start);
var sourceNodes = lines.map(function (line, i) {
@@ -65,29 +65,3 @@ module.exports = function (content) {
cb(null, 'module.exports = ' + JSON.stringify(output));
}
-
-function checkLang (node) {
- if (node.attrs) {
- var i = node.attrs.length;
- while (i--) {
- var attr = node.attrs[i];
- if (attr.name === 'lang') {
- return attr.value;
- }
- }
- }
-}
-
-function checkSrc (node, arr) {
- if (node.attrs) {
- var i = node.attrs.length;
- while (i--) {
- var attr = node.attrs[i];
- if (attr.name === 'src') {
- arr.push(attr.value);
- return true;
- }
- }
- }
- return false
-}
From ff72520043253e2ed15c0bcf7bd2edc18ec6f987 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 8 Jun 2015 17:48:30 -0400
Subject: [PATCH 015/281] add peer dependencies
---
package.json | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/package.json b/package.json
index 92c06dc1a..1b0e58afd 100644
--- a/package.json
+++ b/package.json
@@ -22,5 +22,10 @@
"loader-utils": "^0.2.7",
"parse5": "^1.1.4",
"source-map": "^0.4.2"
+ },
+ "peerDependencies": {
+ "css-loader": "^0.14.4",
+ "html-loader": "^0.3.0",
+ "style-loader": "^0.12.3"
}
}
From 32d388f9223a81f162b2193c86b27f2eda1ee96d Mon Sep 17 00:00:00 2001
From: Evan You
Date: Fri, 12 Jun 2015 00:13:38 -0400
Subject: [PATCH 016/281] renaming
---
README.md | 8 ++++----
index.js | 2 +-
package.json | 12 ++++++------
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index aca832ae5..80a838c37 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# vue-multi-loader
+# vue-loader
> Vue.js component loader for [Webpack](http://webpack.github.io), using Webpack loaders for the parts.
@@ -67,7 +67,7 @@ module.exports = {
},
module: {
loaders: [
- { test: /\.vue$/, loader: "vue-multi-loader" },
+ { test: /\.vue$/, loader: "vue-loader" },
]
}
}
@@ -84,7 +84,7 @@ var app = new Vue(appOptions).$mount('#app')
## Loader configuration
-By default, `vue-multi-loader` will try to use the loader with the same name as
+By default, `vue-loader` will try to use the loader with the same name as
the `lang` attribute, but you can configure which loader should be used.
For example, to extract out the generated css into a separate file,
@@ -93,7 +93,7 @@ use this configuration:
``` js
// webpack.config.js
var ExtractTextPlugin = require("extract-text-webpack-plugin");
-var vue = require("vue-multi-loader");
+var vue = require("vue-loader");
module.exports = {
entry: "./main.js",
diff --git a/index.js b/index.js
index 4b013ca29..96622382d 100644
--- a/index.js
+++ b/index.js
@@ -61,5 +61,5 @@ module.exports = function (content) {
}
module.exports.withLoaders = function (opts) {
- return 'vue-multi-loader?' + JSON.stringify(opts).replace(/!/g, '\\u0021')
+ return 'vue-loader?' + JSON.stringify(opts).replace(/!/g, '\\u0021')
}
diff --git a/package.json b/package.json
index 1b0e58afd..a57636c6f 100644
--- a/package.json
+++ b/package.json
@@ -1,11 +1,11 @@
{
- "name": "vue-multi-loader",
- "version": "0.0.5",
- "description": "Vue.js component loader for Webpack, using Webpack loaders for the parts",
+ "name": "vue-loader",
+ "version": "1.1.7",
+ "description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
"type": "git",
- "url": "https://github.com/Q42/vue-multi-loader.git"
+ "url": "https://github.com/vuejs/vue-loader.git"
},
"keywords": [
"vue",
@@ -15,9 +15,9 @@
"author": "Sjoerd Visscher",
"license": "ISC",
"bugs": {
- "url": "https://github.com/Q42/vue-multi-loader/issues"
+ "url": "https://github.com/vuejs/vue-loader/issues"
},
- "homepage": "https://github.com/Q42/vue-multi-loader",
+ "homepage": "https://github.com/vuejs/vue-loader",
"dependencies": {
"loader-utils": "^0.2.7",
"parse5": "^1.1.4",
From 8fd05e41eabf464b1b3f0e731a3027eebe1a4588 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Fri, 12 Jun 2015 19:37:21 -0400
Subject: [PATCH 017/281] add a note for template loader
---
README.md | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/README.md b/README.md
index 80a838c37..736b3d699 100644
--- a/README.md
+++ b/README.md
@@ -82,6 +82,12 @@ var appOptions = require('./app.vue')
var app = new Vue(appOptions).$mount('#app')
```
+## Pre-Processors
+
+By default `vue-loader` needs `html-loader`, `css-loader` and `style-loader` as peer dependencies. In order to use pre-processors, you need to install the corresponding Webpack loader for that language.
+
+**Note** For template pre-processors, use `template-html-loader` plus the raw templating engine. For example to use `jade`, you will need to install both `template-html-loader` and `jade` instead of `jade-loader`.
+
## Loader configuration
By default, `vue-loader` will try to use the loader with the same name as
From fc534b24b1f6dd04dfce9a2a1ff2b0135b44c4ed Mon Sep 17 00:00:00 2001
From: Evan You
Date: Fri, 12 Jun 2015 19:43:57 -0400
Subject: [PATCH 018/281] bump
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index a57636c6f..338d6bd3f 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
- "version": "1.1.7",
+ "version": "2.0.0",
"description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
From 95dd6262c06a824ebec36307fd2aa7666318574d Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sun, 14 Jun 2015 18:41:36 -0400
Subject: [PATCH 019/281] some formatting and comments
---
index.js | 107 ++++++++++++++++++++++++++++++++++++----------------
parser.js | 54 +++++++++++++-------------
selector.js | 18 ++++-----
3 files changed, 111 insertions(+), 68 deletions(-)
diff --git a/index.js b/index.js
index 96622382d..6d7b492a2 100644
--- a/index.js
+++ b/index.js
@@ -1,65 +1,108 @@
-var loaderUtils = require("loader-utils");
+var loaderUtils = require("loader-utils")
module.exports = function (content) {
- this.cacheable();
- var cb = this.async();
- var languages = {};
- var output = '';
- var vueUrl = loaderUtils.getRemainingRequest(this);
- var loaders = loaderUtils.parseQuery(this.query);
- loaders.html = loaders.html || 'html';
- loaders.css = loaders.css || 'style!css';
- loaders.js = loaders.js || '';
+ this.cacheable()
+ var cb = this.async()
+ var languages = {}
+ var output = ''
+ var vueUrl = loaderUtils.getRemainingRequest(this)
+
+ // check if there are custom loaders specified with
+ // vueLoader.withLoaders(), otherwise use defaults
+ var loaders = loaderUtils.parseQuery(this.query)
+ loaders.html = loaders.html || 'html'
+ loaders.css = loaders.css || 'style!css'
+ loaders.js = loaders.js || ''
+
var loaderPrefix = {
template: 'html!template-html-loader?raw&engine=',
style: 'style!css!',
script: ''
- };
+ }
+
var defaultLang = {
template: 'html',
style: 'css',
script: 'js'
- };
+ }
+ /**
+ * Determine the loaders to use for an extracted part.
+ *
+ * @param {String} part - style|script|template
+ * @param {String} lang
+ * @return {String}
+ */
function loader(part, lang) {
- lang = lang || defaultLang[part];
- var loader = loaders[lang] !== undefined ? loaders[lang] : loaderPrefix[part] + lang;
- return loader ? loader + '!' : '';
+ lang = lang || defaultLang[part]
+ var loader = loaders[lang] !== undefined
+ ? loaders[lang]
+ : loaderPrefix[part] + lang
+ return loader ? loader + '!' : ''
}
- var me = this;
+ /**
+ * Generate a require call for an extracted part.
+ *
+ * @param {String} part - style|script|template
+ * @param {String} lang
+ * @return {String}
+ */
+ var self = this
function getRequire(part, lang) {
- return 'require(' + loaderUtils.stringifyRequest(me, '-!' + loader(part, lang) + require.resolve('./selector.js') + '?' + part + '/' + lang + '!' + vueUrl) + ')';
+ return 'require(' +
+ loaderUtils.stringifyRequest(self,
+ '-!' + loader(part, lang) +
+ require.resolve('./selector.js') + '?' + part + '/' + lang + '!' +
+ vueUrl
+ ) +
+ ')'
}
- var me = this;
- var url = "!!" + require.resolve("./parser.js") + "!" + vueUrl;
+ var self = this
+ var url = "!!" + require.resolve("./parser.js") + "!" + vueUrl
this.loadModule(url, function(err, source, map, module) {
- if (err) return cb(err);
+ if (err) return cb(err)
- var parts = me.exec(source, url);
+ // up to this part, what we have done is basically executing
+ // parser.js on the raw vue file and get the parsing result
+ // which is an object that contains info about the vue file.
+ var parts = self.exec(source, url)
- for (var i = 0; i < parts.includes.length; i++)
- output += 'require(' + loaderUtils.stringifyRequest(this, loaderUtils.urlToRequest(parts.includes[i])) + ')\n';
+ // add require for all the src imports
+ for (var i = 0; i < parts.includes.length; i++) {
+ var importReqeust = loaderUtils.urlToRequest(parts.includes[i])
+ output += 'require(' + loaderUtils.stringifyRequest(this, importReqeust) + ')\n'
+ }
- for (var lang in parts.style)
- output += getRequire('style', lang) + '\n';
+ // add require for styles
+ for (var lang in parts.style) {
+ output += getRequire('style', lang) + '\n'
+ }
- for (var lang in parts.script)
- output += 'module.exports = ' + getRequire('script', lang) + '\n';
+ // add require for script
+ for (var lang in parts.script) {
+ output += 'module.exports = ' + getRequire('script', lang) + '\n'
+ }
- var hasTemplate = false;
+ // add require for template
+ var hasTemplate = false
for (var lang in parts.template) {
if (hasTemplate)
- return cb(new Error('Only one template element allowed per vue component!'));
- output += 'module.exports.template = ' + getRequire('template', lang);
- hasTemplate = true;
+ return cb(new Error('Only one template element allowed per vue component!'))
+ output += 'module.exports.template = ' + getRequire('template', lang)
+ hasTemplate = true
}
- cb(null, output);
+ // done
+ cb(null, output)
})
}
+/**
+ * Expose a way to specify custom loaders to be used at the
+ * end for the extracted parts of a component.
+ */
module.exports.withLoaders = function (opts) {
return 'vue-loader?' + JSON.stringify(opts).replace(/!/g, '\\u0021')
}
diff --git a/parser.js b/parser.js
index b6db5493e..d9e8f59b3 100644
--- a/parser.js
+++ b/parser.js
@@ -1,22 +1,22 @@
-var parse5 = require('parse5');
-var parser = new parse5.Parser(parse5.TreeAdapters.htmlparser2, { locationInfo: true });
-var serializer = new parse5.TreeSerializer();
-var SourceNode = require("source-map").SourceNode;
-var loaderUtils = require("loader-utils");
+var parse5 = require('parse5')
+var parser = new parse5.Parser(parse5.TreeAdapters.htmlparser2, { locationInfo: true })
+var serializer = new parse5.TreeSerializer()
+var SourceNode = require("source-map").SourceNode
+var loaderUtils = require("loader-utils")
module.exports = function (content) {
- this.cacheable();
- var cb = this.async();
- var vueRequest = loaderUtils.getRemainingRequest(this);
- var request = loaderUtils.getCurrentRequest(this);
+ this.cacheable()
+ var cb = this.async()
+ var vueRequest = loaderUtils.getRemainingRequest(this)
+ var request = loaderUtils.getCurrentRequest(this)
- var languages = {};
+ var languages = {}
var output = {
template: {},
style: {},
script: {},
includes: []
- };
+ }
function pos(offset) {
return {
@@ -25,43 +25,43 @@ module.exports = function (content) {
}
}
- var fragment = parser.parseFragment(content);
+ var fragment = parser.parseFragment(content)
fragment.children.forEach(function (node) {
if (node.attribs && node.attribs.src) {
output.includes.push(node.attribs.src)
- return;
+ return
}
if (!node.children || !node.children.length)
- return;
+ return
- var lang = (node.attribs && node.attribs.lang) || '';
- var type = node.name;
+ var lang = (node.attribs && node.attribs.lang) || ''
+ var type = node.name
if (!output[type])
- return;
+ return
// Work around changes in parse5 >= 1.2.0
if (node.children[0].type === 'root')
- node = node.children[0];
+ node = node.children[0]
- var start = node.children[0].__location.start;
- var end = node.children[node.children.length - 1].__location.end;
- var lines = content.substring(start, end).split('\n');
- var startPos = pos(start);
+ var start = node.children[0].__location.start
+ var end = node.children[node.children.length - 1].__location.end
+ var lines = content.substring(start, end).split('\n')
+ var startPos = pos(start)
var sourceNodes = lines.map(function (line, i) {
- return new SourceNode(startPos.line + i, i ? 0 : startPos.col, vueRequest, line + '\n');
- });
+ return new SourceNode(startPos.line + i, i ? 0 : startPos.col, vueRequest, line + '\n')
+ })
output[type][lang] = (output[type][lang] || []).concat(sourceNodes)
- });
+ })
for (var type in output) {
for (var lang in output[type]) {
- var sourceNodes = output[type][lang];
+ var sourceNodes = output[type][lang]
output[type][lang] = new SourceNode(1, 1, vueRequest, sourceNodes).toStringWithSourceMap({
file: request
})
}
}
- cb(null, 'module.exports = ' + JSON.stringify(output));
+ cb(null, 'module.exports = ' + JSON.stringify(output))
}
diff --git a/selector.js b/selector.js
index 956f2ea74..73062fd2e 100644
--- a/selector.js
+++ b/selector.js
@@ -1,14 +1,14 @@
module.exports = function () {
- this.cacheable();
- var cb = this.async();
- var path = this.query.substr(1).split('/');
+ this.cacheable()
+ var cb = this.async()
+ var path = this.query.substr(1).split('/')
- var me = this;
- var url = "!!" + require.resolve("./parser.js") + "!" + this.resource;
+ var self = this
+ var url = "!!" + require.resolve("./parser.js") + "!" + this.resource
this.loadModule(url, function(err, source) {
- if (err) return cb(err);
- var parts = me.exec(source, url);
- var part = parts[path[0]][path[1]||''];
- cb(null, part.code, part.map);
+ if (err) return cb(err)
+ var parts = self.exec(source, url)
+ var part = parts[path[0]][path[1]||'']
+ cb(null, part.code, part.map)
})
}
From 02eaf0cd02caf15e76c6fcd6babeae94d392a40b Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 15 Jun 2015 15:12:09 -0400
Subject: [PATCH 020/281] fix source map
---
index.js | 2 +-
package.json | 3 +--
parser.js | 25 +------------------------
selector.js | 5 +++--
4 files changed, 6 insertions(+), 29 deletions(-)
diff --git a/index.js b/index.js
index 6d7b492a2..1965481bb 100644
--- a/index.js
+++ b/index.js
@@ -61,7 +61,7 @@ module.exports = function (content) {
var self = this
var url = "!!" + require.resolve("./parser.js") + "!" + vueUrl
- this.loadModule(url, function(err, source, map, module) {
+ this.loadModule(url, function(err, source) {
if (err) return cb(err)
// up to this part, what we have done is basically executing
diff --git a/package.json b/package.json
index 338d6bd3f..59521c024 100644
--- a/package.json
+++ b/package.json
@@ -20,8 +20,7 @@
"homepage": "https://github.com/vuejs/vue-loader",
"dependencies": {
"loader-utils": "^0.2.7",
- "parse5": "^1.1.4",
- "source-map": "^0.4.2"
+ "parse5": "^1.1.4"
},
"peerDependencies": {
"css-loader": "^0.14.4",
diff --git a/parser.js b/parser.js
index d9e8f59b3..203251486 100644
--- a/parser.js
+++ b/parser.js
@@ -1,7 +1,5 @@
var parse5 = require('parse5')
var parser = new parse5.Parser(parse5.TreeAdapters.htmlparser2, { locationInfo: true })
-var serializer = new parse5.TreeSerializer()
-var SourceNode = require("source-map").SourceNode
var loaderUtils = require("loader-utils")
module.exports = function (content) {
@@ -18,13 +16,6 @@ module.exports = function (content) {
includes: []
}
- function pos(offset) {
- return {
- line: content.substr(0, offset).split('\n').length,
- col: offset - content.lastIndexOf('\n', offset - 1)
- }
- }
-
var fragment = parser.parseFragment(content)
fragment.children.forEach(function (node) {
if (node.attribs && node.attribs.src) {
@@ -46,22 +37,8 @@ module.exports = function (content) {
var start = node.children[0].__location.start
var end = node.children[node.children.length - 1].__location.end
- var lines = content.substring(start, end).split('\n')
- var startPos = pos(start)
- var sourceNodes = lines.map(function (line, i) {
- return new SourceNode(startPos.line + i, i ? 0 : startPos.col, vueRequest, line + '\n')
- })
- output[type][lang] = (output[type][lang] || []).concat(sourceNodes)
+ output[type][lang] = content.substring(start, end).trim()
})
- for (var type in output) {
- for (var lang in output[type]) {
- var sourceNodes = output[type][lang]
- output[type][lang] = new SourceNode(1, 1, vueRequest, sourceNodes).toStringWithSourceMap({
- file: request
- })
- }
- }
-
cb(null, 'module.exports = ' + JSON.stringify(output))
}
diff --git a/selector.js b/selector.js
index 73062fd2e..c98db663c 100644
--- a/selector.js
+++ b/selector.js
@@ -8,7 +8,8 @@ module.exports = function () {
this.loadModule(url, function(err, source) {
if (err) return cb(err)
var parts = self.exec(source, url)
- var part = parts[path[0]][path[1]||'']
- cb(null, part.code, part.map)
+ var type = path[0]
+ var lang = path[1] || ''
+ cb(null, parts[type][lang])
})
}
From 95b486f51b44c5fc233ef85fc56a764d627eb0a5 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 15 Jun 2015 18:49:37 -0400
Subject: [PATCH 021/281] tests
---
.gitignore | 1 +
package.json | 22 ++++++++
test/fixtures/basic.js | 1 +
test/fixtures/basic.vue | 19 +++++++
test/fixtures/pre.js | 1 +
test/fixtures/pre.vue | 23 ++++++++
test/test.js | 120 ++++++++++++++++++++++++++++++++++++++++
7 files changed, 187 insertions(+)
create mode 100644 test/fixtures/basic.js
create mode 100644 test/fixtures/basic.vue
create mode 100644 test/fixtures/pre.js
create mode 100644 test/fixtures/pre.vue
create mode 100644 test/test.js
diff --git a/.gitignore b/.gitignore
index 7a3a95d56..e698d7971 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
/node_modules
/npm-debug.log
+test/output
diff --git a/package.json b/package.json
index 59521c024..c8157b571 100644
--- a/package.json
+++ b/package.json
@@ -18,6 +18,9 @@
"url": "https://github.com/vuejs/vue-loader/issues"
},
"homepage": "https://github.com/vuejs/vue-loader",
+ "scripts": {
+ "test": "mocha test/test.js --slow 2000"
+ },
"dependencies": {
"loader-utils": "^0.2.7",
"parse5": "^1.1.4"
@@ -26,5 +29,24 @@
"css-loader": "^0.14.4",
"html-loader": "^0.3.0",
"style-loader": "^0.12.3"
+ },
+ "devDependencies": {
+ "babel-core": "^5.5.8",
+ "babel-loader": "^5.1.4",
+ "chai": "^3.0.0",
+ "css-loader": "^0.14.4",
+ "html-loader": "^0.3.0",
+ "jade": "^1.11.0",
+ "jsdom": "^5.4.3",
+ "mkdirp": "^0.5.1",
+ "mocha": "^2.2.5",
+ "node-libs-browser": "^0.5.2",
+ "object-assign": "^3.0.0",
+ "rimraf": "^2.4.0",
+ "source-map": "^0.4.2",
+ "style-loader": "^0.12.3",
+ "stylus-loader": "^1.2.0",
+ "template-html-loader": "0.0.3",
+ "webpack": "^1.9.11"
}
}
diff --git a/test/fixtures/basic.js b/test/fixtures/basic.js
new file mode 100644
index 000000000..b5a46fc5f
--- /dev/null
+++ b/test/fixtures/basic.js
@@ -0,0 +1 @@
+window.testModule = require('./basic.vue')
diff --git a/test/fixtures/basic.vue b/test/fixtures/basic.vue
new file mode 100644
index 000000000..5cf4c68ac
--- /dev/null
+++ b/test/fixtures/basic.vue
@@ -0,0 +1,19 @@
+
+
+
+
'
)
var style = window.document.querySelector('style').textContent
- var cls = '.v-' + hash(require.resolve('./fixtures/local-css.vue'))
expect(style).to.contain('div' + cls + '.test {\n color: blue;\n}')
expect(style).to.contain(cls + ' {\n color: red;\n}')
expect(style).to.contain(cls + ' h1 {\n color: green;\n}')
From 8bbc858742e28e72862d9e2dfb9cb69c0987a7f5 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Thu, 16 Jul 2015 07:12:49 -0700
Subject: [PATCH 042/281] lift rules that start with body
---
lib/style-rewriter.js | 15 +++++++++++----
test/fixtures/local-css.vue | 3 +++
test/test.js | 12 +++++++++---
3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js
index 3a13625b8..14f1eaf6f 100644
--- a/lib/style-rewriter.js
+++ b/lib/style-rewriter.js
@@ -4,15 +4,22 @@ var hash = require('hash-sum')
var currentClass
var rootRE = /:root\b/g
+var liftRE = /^(html|head|body)\b/
var processRoot = postcss.plugin('process-root', function () {
return function (root) {
+ var lifted = 0
+ function lift (node) {
+ node.moveBefore(root.nodes[lifted++])
+ }
root.each(function (node) {
node.each(function (node) {
- if (rootRE.test(node.selector)) {
+ var sel = node.selector
+ if (liftRE.test(sel)) {
+ lift(node)
+ } else if (rootRE.test(sel)) {
// replace :root selector
- node.selector = node.selector.replace(rootRE, currentClass)
- // move the node to the outer scope to avoid nesting
- node.moveBefore(root.nodes[0])
+ node.selector = sel.replace(rootRE, currentClass)
+ lift(node)
}
})
})
diff --git a/test/fixtures/local-css.vue b/test/fixtures/local-css.vue
index 529b5f05f..7a2f2328b 100644
--- a/test/fixtures/local-css.vue
+++ b/test/fixtures/local-css.vue
@@ -1,4 +1,7 @@
-
+
diff --git a/test/fixtures/local-css.js b/test/fixtures/local-css.js
deleted file mode 100644
index 519ba68d9..000000000
--- a/test/fixtures/local-css.js
+++ /dev/null
@@ -1 +0,0 @@
-window.testModule = require('./local-css.vue')
diff --git a/test/fixtures/scoped-css.js b/test/fixtures/scoped-css.js
new file mode 100644
index 000000000..607e0d58f
--- /dev/null
+++ b/test/fixtures/scoped-css.js
@@ -0,0 +1 @@
+window.testModule = require('./scoped-css.vue')
diff --git a/test/fixtures/local-css.vue b/test/fixtures/scoped-css.vue
similarity index 92%
rename from test/fixtures/local-css.vue
rename to test/fixtures/scoped-css.vue
index 7a2f2328b..0a335d6e6 100644
--- a/test/fixtures/local-css.vue
+++ b/test/fixtures/scoped-css.vue
@@ -1,4 +1,4 @@
-
-
-
-h1(class="red") {{msg}}
-
-
-
-```
-
-And you can import using the `src` attribute:
-
-``` html
-
-```
-
-**NOTE**: Starting from version 2.1.0, `src` imports follow similar rules to `require()` calls, which means for relative paths you need to start with `./`, and you can import resources from node modules: `
+```
+
+The `lang` attribute will be used to automatically locate the loader to use, and you can pass Webpack loader queries in it as well:
+
+``` html
+
+```
+
+#### A Note on Dependencies
+
+By default, `vue-loader` requires `html-loader`, `css-loader` and `style-loader` as peer dependencies. In order to use pre-processors, you also need to install the corresponding Webpack loader for that language.
+
+Also, for template pre-processors, you should install `template-html-loader` plus the raw templating engine. For example to use `jade`, you will need to install both `template-html-loader` and `jade` instead of `jade-loader`.
+
+## Style Imports
+
+If you want, you can separate your styles into a separate file and import it using the `src` attribute:
-**Note** For template pre-processors, use `template-html-loader` plus the raw templating engine. For example to use `jade`, you will need to install both `template-html-loader` and `jade` instead of `jade-loader`.
+``` html
+
+```
+
+Beware that `src` imports follow similar rules to `require()` calls, which means for relative paths you need to start with `./`, and you can import resources from node modules: `
```
-#### A Note on Dependencies
+#### A Note on Loader Dependencies
-By default, `vue-loader` requires `html-loader`, `css-loader` and `style-loader` as peer dependencies. In order to use pre-processors, you also need to install the corresponding Webpack loader for that language.
+By default, `vue-loader` requires `vue-html-loader`, `css-loader` and `style-loader` as peer dependencies. In order to use pre-processors, you also need to install the corresponding Webpack loader for that language.
-Also, for template pre-processors, you should install `template-html-loader` plus the raw templating engine. For example to use `jade`, you will need to install both `template-html-loader` and `jade` instead of `jade-loader`.
+#### Template Pre-Processors
+
+For template pre-processors, you should install `template-html-loader` plus the raw templating engine. For example to use `jade`, you will need to install both `template-html-loader` and `jade` instead of `jade-loader`.
## Style Imports
@@ -103,7 +105,7 @@ Beware that `src` imports follow similar rules to `require()` calls, which means
## Asset URL Handling
-By default, `vue-loader` automatically processes your style and template files with `css-loader` and `html-loader` - this means that all asset URLs such as ``, `background: url(...)` and CSS `@import` are **resolved as module dependencies**.
+By default, `vue-loader` automatically processes your style and template files with `css-loader` and `vue-html-loader` - this means that all asset URLs such as ``, `background: url(...)` and CSS `@import` are **resolved as module dependencies**.
For example, `url(image.png)` will be translated into `require('./image.png')`. Because `.png` is not JavaScript, you will need to configure Webpack to use [file-loader](https://github.com/webpack/file-loader) or [url-loader](https://github.com/webpack/url-loader) to handle them. This may feel cumbersome, but it gives you some very powerful benefits in managing your static assets this way:
@@ -111,7 +113,7 @@ For example, `url(image.png)` will be translated into `require('./image.png')`.
2. `url-loader` allows you to conditionally load a file as a inline Data URL if they are smaller than a given threshold.
-For more details, see the respective documentations for [html-loader](https://github.com/webpack/html-loader) and [css-loader](https://github.com/webpack/css-loader).
+For more details, see the respective documentations for [vue-html-loader](https://github.com/vuejs/vue-html-loader) and [css-loader](https://github.com/webpack/css-loader).
## Advanced Loader configuration
From 5282f7e86e0e40c080bfbb09be6b7e3278faa398 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Thu, 1 Oct 2015 15:12:20 -0400
Subject: [PATCH 058/281] bump 3.0.4
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 62a378c75..eaf019091 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
- "version": "3.0.3",
+ "version": "3.0.4",
"description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
From a977487148c7bcbbbf353347679c48c4832cebdd Mon Sep 17 00:00:00 2001
From: Evan You
Date: Tue, 13 Oct 2015 17:34:16 -0400
Subject: [PATCH 059/281] new scoped css implementation
---
lib/id-generator.js | 12 ++++++++++
lib/style-rewriter.js | 44 ++++++++++--------------------------
lib/template-rewriter.js | 34 +++++++++++++---------------
package.json | 2 --
test/fixtures/scoped-css.vue | 8 +------
test/test.js | 20 ++++------------
6 files changed, 46 insertions(+), 74 deletions(-)
create mode 100644 lib/id-generator.js
diff --git a/lib/id-generator.js b/lib/id-generator.js
new file mode 100644
index 000000000..e1c242d95
--- /dev/null
+++ b/lib/id-generator.js
@@ -0,0 +1,12 @@
+// keep track of unique ids for component modules.
+
+var ids = Object.create(null)
+var count = 0
+
+exports.get = function (path) {
+ var id = ids[path]
+ if (!id) {
+ id = ids[path] = ++count
+ }
+ return '_v-' + id
+}
diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js
index 8837e65ea..4088e9a4e 100644
--- a/lib/style-rewriter.js
+++ b/lib/style-rewriter.js
@@ -1,37 +1,18 @@
var postcss = require('postcss')
-var nested = require('postcss-nested')
var selectorParser = require('postcss-selector-parser')
-var hash = require('hash-sum')
+var idGen = require('./id-generator')
-var liftRE = /^(html|head|body)\b/
-var scopeRE = /:scope\b/
-var processRoot = postcss.plugin('process-root', function () {
+var currentId
+var addId = postcss.plugin('add-id', function () {
return function (root) {
- var lifted = 0
- function lift (node) {
- node.moveBefore(root.nodes[lifted++])
- }
root.each(function (node) {
- node.each(function (node) {
- var kept = []
- selectorParser(function (selectors) {
- selectors.each(function (selector) {
- var sel = selector.toString()
- if (liftRE.test(sel)) {
- lift(node.clone({
- selector: sel
- }))
- } else {
- kept.push(sel)
- }
- })
- }).process(node.selector)
- if (!kept.length) {
- node.removeSelf()
- } else {
- node.selector = kept.join(',').replace(scopeRE, '&')
- }
- })
+ node.selector = selectorParser(function (selectors) {
+ selectors.each(function (selector) {
+ selector.append(selectorParser.attribute({
+ attribute: currentId
+ }))
+ })
+ }).process(node.selector).result
})
}
})
@@ -39,9 +20,8 @@ var processRoot = postcss.plugin('process-root', function () {
module.exports = function (css) {
this.cacheable()
var cb = this.async()
- var cls = '.v-' + hash(this.resourcePath)
- css = cls + '{' + css + '}'
- postcss([processRoot, nested])
+ currentId = idGen.get(this.resourcePath)
+ postcss([addId])
.process(css)
.then(function (result) {
cb(null, result)
diff --git a/lib/template-rewriter.js b/lib/template-rewriter.js
index 7ec2bf725..f91ade954 100644
--- a/lib/template-rewriter.js
+++ b/lib/template-rewriter.js
@@ -1,30 +1,28 @@
var parse5 = require('parse5')
var parser = new parse5.Parser()
var serializer = new parse5.Serializer()
-var hash = require('hash-sum')
+var idGen = require('./id-generator')
module.exports = function (html) {
this.cacheable()
- var cls = 'v-' + hash(this.resourcePath)
+ var id = idGen.get(this.resourcePath)
var tree = parser.parseFragment(html)
- tree.childNodes.forEach(function (node) {
+ walk(tree, function (node) {
if (node.attrs) {
- var hasClass = false
- for (var i = 0, l = node.attrs.length; i < l; i++) {
- var attr = node.attrs[i]
- if (attr.name === 'class') {
- attr.value += ' ' + cls
- hasClass = true
- break
- }
- }
- if (!hasClass) {
- node.attrs.push({
- name: 'class',
- value: cls
- })
- }
+ node.attrs.push({
+ name: id,
+ value: ''
+ })
}
})
return serializer.serialize(tree)
}
+
+function walk (tree, fn) {
+ if (tree.childNodes) {
+ tree.childNodes.forEach(function (node) {
+ fn(node)
+ walk(node, fn)
+ })
+ }
+}
diff --git a/package.json b/package.json
index eaf019091..c6f915162 100644
--- a/package.json
+++ b/package.json
@@ -23,11 +23,9 @@
"test": "eslint lib && mocha test/test.js --slow 5000"
},
"dependencies": {
- "hash-sum": "^1.0.2",
"loader-utils": "^0.2.10",
"parse5": "^1.5.0",
"postcss": "^4.1.16",
- "postcss-nested": "^0.3.2",
"postcss-selector-parser": "^1.1.2"
},
"peerDependencies": {
diff --git a/test/fixtures/scoped-css.vue b/test/fixtures/scoped-css.vue
index ee925ca5d..515ee88f1 100644
--- a/test/fixtures/scoped-css.vue
+++ b/test/fixtures/scoped-css.vue
@@ -1,13 +1,7 @@
```
-The `lang` attribute will be used to automatically locate the loader to use, and you can pass Webpack loader queries in it as well:
+You can also include Webpack loader queries in the `lang` attribute:
``` html
```
-#### A Note on Loader Dependencies
+## Template Pre-Processors
-By default, `vue-loader` requires `vue-html-loader`, `css-loader` and `style-loader` as peer dependencies. In order to use pre-processors, you also need to install the corresponding Webpack loader for that language.
+For template pre-processors, you should install `template-html-loader` plus the raw templating engine. For example to use `jade`, you will need to install both `template-html-loader` and `jade` instead of `jade-loader`.
-#### Template Pre-Processors
+## Scoped Styles
-For template pre-processors, you should install `template-html-loader` plus the raw templating engine. For example to use `jade`, you will need to install both `template-html-loader` and `jade` instead of `jade-loader`.
+When a `
+
+
hi
+
+```
+
+Into the following:
+
+``` html
+
+
+
hi
+
+```
+
+#### Notes
+
+1. You can include both scoped and non-scoped styles in the same component.
+
+2. A child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS.
+
+3. Partials are not affected by scoped styles.
+
+## Hot Reload
+
+When using `webpack-dev-server` in hot mode, `vue-loader` enables hot component reloading for Vue.js 1.0.0+. An example config:
+
+``` js
+module.exports = {
+ entry: ['webpack/hot/dev-server', './src/main.js'],
+ output: {
+ publicPath: '/static/',
+ filename: 'build.js'
+ },
+ module: {
+ loaders: [
+ { test: /\.vue$/, loader: 'vue' },
+ ]
+ },
+ devtool: '#source-map'
+}
+```
+
+In `index.html`, include the bundle:
+
+``` html
+
+```
+
+Then, run the dev server with:
+
+``` bash
+webpack-dev-server --hot --config build/webpack.dev.config.js
+```
+
+Finally, visit `http://localhost:8080/webpack-dev-server/` to see the app with hot reloading.
+
+For a complete example with hot reloading in action, see [vue-hackernews](https://github.com/vuejs/vue-hackernews).
## Style Imports
@@ -180,4 +251,6 @@ module.exports = {
## Example Project
-See [vue-loader-example](https://github.com/vuejs/vue-loader-example).
+For a simple setup example, see [vue-loader-example](https://github.com/vuejs/vue-loader-example).
+
+For an actual project with dev setup with hot reloading and production setup with minification, see [vue-hackernews](https://github.com/vuejs/vue-hackernews).
From d67b6ea26c8537d85519eb8ade42478505cce3bc Mon Sep 17 00:00:00 2001
From: Evan You
Date: Wed, 14 Oct 2015 22:29:10 -0400
Subject: [PATCH 066/281] adjust order in readme
---
README.md | 52 ++++++++++++++++++++++++++++------------------------
1 file changed, 28 insertions(+), 24 deletions(-)
diff --git a/README.md b/README.md
index 6f0822f3d..7078d4c7d 100644
--- a/README.md
+++ b/README.md
@@ -33,10 +33,10 @@ It allows you to write your components in this format:
- [Basic Usage](#basic-usage)
- [Pre-Processors](#pre-processors)
- [Template Pre-Processors](#template-pre-processors)
-- [Scoped Styles](#scoped-styles)
-- [Hot Reload](#hot-reload)
- [Style Imports](#style-imports)
- [Asset URL Handling](#asset-url-handling)
+- [Scoped Styles](#scoped-styles)
+- [Hot Reload](#hot-reload)
- [Advanced Loader Configuration](#advanced-loader-configuration)
- [ES6 with Babel Example](#example-using-es6-with-babel)
- [Extract CSS Example](#example-extracting-css-into-a-single-file)
@@ -92,8 +92,32 @@ You can also include Webpack loader queries in the `lang` attribute:
For template pre-processors, you should install `template-html-loader` plus the raw templating engine. For example to use `jade`, you will need to install both `template-html-loader` and `jade` instead of `jade-loader`.
+## Style Imports
+
+If you want, you can separate your styles into a separate file and import it using the `src` attribute:
+
+``` html
+
+```
+
+Beware that `src` imports follow similar rules to `require()` calls, which means for relative paths you need to start with `./`, and you can import resources from node modules: `
-```
-
-Beware that `src` imports follow similar rules to `require()` calls, which means for relative paths you need to start with `./`, and you can import resources from node modules: `
-
{{msg}}
+
+
```
## Table of Contents
- [Basic Usage](#basic-usage)
-- [Pre-Processors](#pre-processors)
+- [ES2015 by Default](#es2015-by-default)
+- [CSS Pre-Processors](#css-pre-processors)
- [Template Pre-Processors](#template-pre-processors)
- [Style Imports](#style-imports)
- [Asset URL Handling](#asset-url-handling)
- [Scoped CSS](#scoped-css)
- [Hot Reload](#hot-reload)
- [Advanced Loader Configuration](#advanced-loader-configuration)
- - [ES6 with Babel Example](#example-using-es6-with-babel)
- - [Extract CSS Example](#example-extracting-css-into-a-single-file)
- [Example Project](https://github.com/vuejs/vue-loader-example)
## Basic Usage
@@ -66,11 +65,56 @@ And this is all you need to do in your main entry file:
``` js
// main.js
var Vue = require('vue')
-var appOptions = require('./app.vue')
-var app = new Vue(appOptions).$mount('#app')
+var App = require('./app.vue')
+
+new Vue({
+ el: 'body',
+ components: {
+ app: App
+ }
+})
+```
+
+In your HTML:
+
+``` html
+
+
+
+
+```
+
+## ES2015 by Default
+
+`vue-loader` automatically applies Babel transforms to the JavaScript inside `*.vue` components. Write ES2015 today!
+
+The default Babel options used for Vue.js components are:
+
+``` js
+{
+ // use babel-runtime library for common helpers
+ optional: ['runtime'],
+ // use loose mode for faster builds
+ loose: 'all',
+ // disable non-standard stuff (e.g. JSX)
+ nonStandard: false
+}
+```
+
+If you wish to mofidy this, you can add a `babel` field in your webpack config, which will be merged with the default options. For example:
+
+``` js
+// webpack.config.js
+module.exports = {
+ // other configs...
+ babel: {
+ // enable stage 0 transforms
+ stage: 0
+ }
+}
```
-## Pre-Processors
+## CSS Pre-Processors
`vue-loader` allows you to use other Webpack loaders to pre-process the different parts inside your `*.vue` components. Just specify the loader to use with the `lang` attribute (you also need to install the loader, obviously):
@@ -204,9 +248,7 @@ For a complete example with hot reloading in action, see [vue-hackernews](https:
By default, `vue-loader` will try to use the loader with the same name as
the `lang` attribute, but you can configure which loader should be used.
-#### Example: Using ES6 with Babel
-
-To apply Babel transforms to all your JavaScript, use this Webpack config:
+#### Example: Use CoffeeScript for all `
+
```
Then, run the dev server with:
``` bash
-webpack-dev-server --inline --hot --config webpack.example.config.js
+webpack-dev-server --inline --hot
```
-Finally, visit `http://localhost:8080/webpack-dev-server/` to see the app with hot reloading.
+Finally, visit `http://localhost:8080/` to see the app with hot reloading.
For a complete example with hot reloading in action, see [vue-hackernews](https://github.com/vuejs/vue-hackernews).
From 24e42a018ef0d1f2f99a464813e8fedc0cf426e4 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Fri, 30 Oct 2015 10:39:29 -0400
Subject: [PATCH 098/281] show badge for master status
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index fb6dfac68..7c9a2507c 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# vue-loader [](https://circleci.com/gh/vuejs/vue-loader) [](https://www.npmjs.com/package/vue-loader)
+# vue-loader [](https://circleci.com/gh/vuejs/vue-loader/tree/master) [](https://www.npmjs.com/package/vue-loader)
> Vue.js component loader for [Webpack](http://webpack.github.io), using Webpack loaders for the parts.
From e8611e5f5f034b2b83290fd4f736317d5672b8c6 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Fri, 30 Oct 2015 10:40:58 -0400
Subject: [PATCH 099/281] use fury.io badge [ci skip]
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 7c9a2507c..61e3561bd 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# vue-loader [](https://circleci.com/gh/vuejs/vue-loader/tree/master) [](https://www.npmjs.com/package/vue-loader)
+# vue-loader [](https://circleci.com/gh/vuejs/vue-loader/tree/master) [](https://www.npmjs.com/package/vue-loader)
> Vue.js component loader for [Webpack](http://webpack.github.io), using Webpack loaders for the parts.
From b14b1e7c8cb3bb77ded7a544d913d8f8d4cde176 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Fri, 30 Oct 2015 11:36:57 -0400
Subject: [PATCH 100/281] fix scoped css for rules with pseudo classes
---
lib/style-rewriter.js | 6 +++++-
test/fixtures/scoped-css.vue | 3 +++
test/test.js | 1 +
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js
index 094c84b2d..b20e5d828 100644
--- a/lib/style-rewriter.js
+++ b/lib/style-rewriter.js
@@ -9,7 +9,11 @@ var addId = postcss.plugin('add-id', function () {
root.each(function (node) {
node.selector = selectorParser(function (selectors) {
selectors.each(function (selector) {
- selector.append(selectorParser.attribute({
+ var node = null
+ selector.each(function (n) {
+ if (n.type !== 'pseudo') node = n
+ })
+ selector.insertAfter(node, selectorParser.attribute({
attribute: currentId
}))
})
diff --git a/test/fixtures/scoped-css.vue b/test/fixtures/scoped-css.vue
index 515ee88f1..580745de0 100644
--- a/test/fixtures/scoped-css.vue
+++ b/test/fixtures/scoped-css.vue
@@ -2,6 +2,9 @@
.test {
color: yellow;
}
+.test:after {
+ content: 'bye!';
+}
h1 {
color: green;
}
diff --git a/test/test.js b/test/test.js
index 9bda3b9ad..3eeddfa93 100644
--- a/test/test.js
+++ b/test/test.js
@@ -101,6 +101,7 @@ describe('vue-loader', function () {
)
var style = window.document.querySelector('style').textContent
expect(style).to.contain('.test[' + id + '] {\n color: yellow;\n}')
+ expect(style).to.contain('.test[' + id + ']:after {\n content: \'bye!\';\n}')
expect(style).to.contain('h1[' + id + '] {\n color: green;\n}')
done()
})
From 4d4aa1812f6f7407b1a4049812abaad6dc0fe938 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Fri, 30 Oct 2015 11:37:06 -0400
Subject: [PATCH 101/281] bump
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index c59bcb11a..c9a4707f1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
- "version": "6.0.0",
+ "version": "6.0.1",
"description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
From a8e29755e7906b67bb31972f0b331b03c035212e Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sun, 1 Nov 2015 00:24:00 -0400
Subject: [PATCH 102/281] fix media query with scoped styles
---
lib/style-rewriter.js | 14 ++++++++++++--
test/fixtures/media-query.js | 1 +
test/fixtures/media-query.vue | 7 +++++++
test/test.js | 11 +++++++++++
4 files changed, 31 insertions(+), 2 deletions(-)
create mode 100644 test/fixtures/media-query.js
create mode 100644 test/fixtures/media-query.vue
diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js
index b20e5d828..fe1a01c10 100644
--- a/lib/style-rewriter.js
+++ b/lib/style-rewriter.js
@@ -6,7 +6,14 @@ var loaderUtils = require('loader-utils')
var currentId
var addId = postcss.plugin('add-id', function () {
return function (root) {
- root.each(function (node) {
+ root.each(function rewriteSelector (node) {
+ if (!node.selector) {
+ // handle media queries
+ if (node.type === 'atrule' && node.name === 'media') {
+ node.each(rewriteSelector)
+ }
+ return
+ }
node.selector = selectorParser(function (selectors) {
selectors.each(function (selector) {
var node = null
@@ -46,5 +53,8 @@ module.exports = function (css) {
.then(function (result) {
cb(null, result)
})
- .catch(cb)
+ .catch(function (e) {
+ console.log(e)
+ cb(e)
+ })
}
diff --git a/test/fixtures/media-query.js b/test/fixtures/media-query.js
new file mode 100644
index 000000000..1a292f332
--- /dev/null
+++ b/test/fixtures/media-query.js
@@ -0,0 +1 @@
+window.testModule = require('./media-query.vue')
diff --git a/test/fixtures/media-query.vue b/test/fixtures/media-query.vue
new file mode 100644
index 000000000..9dbe0ee21
--- /dev/null
+++ b/test/fixtures/media-query.vue
@@ -0,0 +1,7 @@
+
diff --git a/test/test.js b/test/test.js
index 3eeddfa93..9408613f9 100644
--- a/test/test.js
+++ b/test/test.js
@@ -159,4 +159,15 @@ describe('vue-loader', function () {
})
})
+ it('media-query', function (done) {
+ test({
+ entry: './test/fixtures/media-query.js'
+ }, function (window) {
+ var style = window.document.querySelector('style').textContent
+ var id = '_v-' + hash(require.resolve('./fixtures/media-query.vue'))
+ expect(style).to.contain('@media print {\n .foo[' + id + '] {\n color: #000;\n }\n}')
+ done()
+ })
+ })
+
})
From 812f24ddf3353202af4fdae5a6a8942980c45b62 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sun, 1 Nov 2015 11:17:19 -0500
Subject: [PATCH 103/281] fix compat with extract css plugin (close #51)
---
lib/loader.js | 27 ++++++++++++++++++++++++---
package.json | 3 ++-
test/fixtures/extract-css.js | 1 +
test/fixtures/extract-css.vue | 10 ++++++++++
test/test.js | 22 ++++++++++++++++++++++
5 files changed, 59 insertions(+), 4 deletions(-)
create mode 100644 test/fixtures/extract-css.js
create mode 100644 test/fixtures/extract-css.vue
diff --git a/lib/loader.js b/lib/loader.js
index 315a4689d..c18a6d137 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -65,10 +65,23 @@ module.exports = function (content) {
var lang = part.lang || defaultLang[type]
var loader = loaders[lang]
var rewriter = getRewriter(type, scoped)
+ var cssRE = /\b(css!?)\b/
+ var htmlRE = /\b((vue-)?html!?)\b/
if (loader !== undefined) {
- // lang with default or pre-configured loader
- if (loader) loader += '!'
- return loader + rewriter
+ // inject rewriter before css/html loader for
+ // extractTextPlugin use cases
+ if (cssRE.test(loader)) {
+ loader = loader.replace(cssRE, function (m, $1) {
+ return ensureBang($1) + rewriter
+ })
+ } else if (htmlRE.test(loader)) {
+ loader = loader.replace(htmlRE, function (m, $1) {
+ return ensureBang($1) + rewriter
+ })
+ } else {
+ loader = ensureBang(loader) + rewriter
+ }
+ return ensureBang(loader)
} else {
// unknown lang, assume a loader for it is used
switch (type) {
@@ -99,6 +112,14 @@ module.exports = function (content) {
'&index=' + index + '!'
}
+ function ensureBang (loader) {
+ if (loader.charAt(loader.length - 1) !== '!') {
+ return loader + '!'
+ } else {
+ return loader
+ }
+ }
+
var url = '!!' + parserPath + '!' + vueUrl
this.loadModule(url, function (err, source) {
if (err) return cb(err)
diff --git a/package.json b/package.json
index c9a4707f1..c0e2d1481 100644
--- a/package.json
+++ b/package.json
@@ -45,7 +45,7 @@
"chai": "^3.0.0",
"css-loader": "^0.21.0",
"eslint": "^1.6.0",
- "vue-html-loader": "^1.0.0",
+ "extract-text-webpack-plugin": "^0.8.2",
"jade": "^1.11.0",
"jsdom": "^6.5.1",
"mkdirp": "^0.5.1",
@@ -56,6 +56,7 @@
"style-loader": "^0.13.0",
"stylus-loader": "^1.4.0",
"template-html-loader": "^0.0.3",
+ "vue-html-loader": "^1.0.0",
"webpack": "^1.12.2"
}
}
diff --git a/test/fixtures/extract-css.js b/test/fixtures/extract-css.js
new file mode 100644
index 000000000..ce602cf28
--- /dev/null
+++ b/test/fixtures/extract-css.js
@@ -0,0 +1 @@
+require('./extract-css.vue')
diff --git a/test/fixtures/extract-css.vue b/test/fixtures/extract-css.vue
new file mode 100644
index 000000000..75034b07c
--- /dev/null
+++ b/test/fixtures/extract-css.vue
@@ -0,0 +1,10 @@
+
+
+
diff --git a/test/test.js b/test/test.js
index 9408613f9..7de307a1b 100644
--- a/test/test.js
+++ b/test/test.js
@@ -7,6 +7,7 @@ var assign = require('object-assign')
var rimraf = require('rimraf')
var hash = require('hash-sum')
var SourceMapConsumer = require('source-map').SourceMapConsumer
+var ExtractTextPlugin = require("extract-text-webpack-plugin")
describe('vue-loader', function () {
@@ -170,4 +171,25 @@ describe('vue-loader', function () {
})
})
+ it('extract CSS', function (done) {
+ webpack(Object.assign({}, globalConfig, {
+ entry: './test/fixtures/extract-css.js',
+ vue: {
+ loaders: {
+ css: ExtractTextPlugin.extract('css'),
+ stylus: ExtractTextPlugin.extract('css!stylus')
+ }
+ },
+ plugins: [
+ new ExtractTextPlugin('test.output.css')
+ ]
+ }), function (err) {
+ expect(err).to.be.null
+ getFile('test.output.css', function (data) {
+ expect(data).to.contain('h1 {\n color: #f00;\n}\nh2 {\n color: green;\n}')
+ done()
+ })
+ })
+ })
+
})
From 4d45aedbe214e90384d9c7feb731bb15d8edf634 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sun, 1 Nov 2015 11:28:45 -0500
Subject: [PATCH 104/281] bump 6.0.2
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index c0e2d1481..59ea2487a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
- "version": "6.0.1",
+ "version": "6.0.2",
"description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
From 1e7dd932edbf562c316875b11499ccd4ca4b6437 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sun, 1 Nov 2015 11:44:26 -0500
Subject: [PATCH 105/281] also repsect external autoprefixer options
---
lib/style-rewriter.js | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js
index fe1a01c10..aa9b55413 100644
--- a/lib/style-rewriter.js
+++ b/lib/style-rewriter.js
@@ -2,6 +2,7 @@ var postcss = require('postcss')
var selectorParser = require('postcss-selector-parser')
var hash = require('hash-sum')
var loaderUtils = require('loader-utils')
+var assign = require('object-assign')
var currentId
var addId = postcss.plugin('add-id', function () {
@@ -42,7 +43,12 @@ module.exports = function (css) {
processors.push(addId)
}
if (autoprefixOptions !== false) {
- autoprefixOptions = autoprefixOptions || { remove: false }
+ autoprefixOptions = assign(
+ {},
+ // also respect autoprefixer-loader options
+ this.options.autoprefixer,
+ autoprefixOptions
+ )
var autoprefixer = require('autoprefixer')(autoprefixOptions)
processors.push(autoprefixer)
}
From 9375f5cfefe532d420baca92e9448904d4249cc8 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sun, 1 Nov 2015 15:15:30 -0500
Subject: [PATCH 106/281] fix custom loaders with queries
---
lib/loader.js | 11 +++--------
test/test.js | 2 +-
2 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/lib/loader.js b/lib/loader.js
index c18a6d137..78bd57456 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -15,6 +15,7 @@ var defaultLoaders = {
js: 'babel?optional[]=runtime&loose=all&nonStandard=false'
}
+var rewriterInjectRE = /\b((css|(vue-)?html)(\?[^!]+)?!?)\b/
var rewriters = {
template: require.resolve('./template-rewriter'),
style: require.resolve('./style-rewriter')
@@ -65,17 +66,11 @@ module.exports = function (content) {
var lang = part.lang || defaultLang[type]
var loader = loaders[lang]
var rewriter = getRewriter(type, scoped)
- var cssRE = /\b(css!?)\b/
- var htmlRE = /\b((vue-)?html!?)\b/
if (loader !== undefined) {
// inject rewriter before css/html loader for
// extractTextPlugin use cases
- if (cssRE.test(loader)) {
- loader = loader.replace(cssRE, function (m, $1) {
- return ensureBang($1) + rewriter
- })
- } else if (htmlRE.test(loader)) {
- loader = loader.replace(htmlRE, function (m, $1) {
+ if (rewriterInjectRE.test(loader)) {
+ loader = loader.replace(rewriterInjectRE, function (m, $1) {
return ensureBang($1) + rewriter
})
} else {
diff --git a/test/test.js b/test/test.js
index 7de307a1b..058d8be4b 100644
--- a/test/test.js
+++ b/test/test.js
@@ -177,7 +177,7 @@ describe('vue-loader', function () {
vue: {
loaders: {
css: ExtractTextPlugin.extract('css'),
- stylus: ExtractTextPlugin.extract('css!stylus')
+ stylus: ExtractTextPlugin.extract('css?sourceMap!stylus')
}
},
plugins: [
From 12628f61d776b4bf737538f5dfa6911adeea2a3c Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sun, 1 Nov 2015 15:15:55 -0500
Subject: [PATCH 107/281] bump 6.0.3
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 59ea2487a..58c0f0b67 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
- "version": "6.0.2",
+ "version": "6.0.3",
"description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
From 788223473941b17b94fa0c07c7677f67ec2af746 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sun, 1 Nov 2015 22:28:12 -0500
Subject: [PATCH 108/281] properly support sourcemaps in style-rewriter
---
lib/style-rewriter.js | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js
index aa9b55413..74975ffef 100644
--- a/lib/style-rewriter.js
+++ b/lib/style-rewriter.js
@@ -30,18 +30,21 @@ var addId = postcss.plugin('add-id', function () {
}
})
-module.exports = function (css) {
+module.exports = function (css, map) {
this.cacheable()
var cb = this.async()
var query = loaderUtils.parseQuery(this.query)
var options = this.options.vue || {}
var autoprefixOptions = options.autoprefixer
+ var plugins = []
- var processors = []
+ // scoped css
if (query.scoped) {
- processors.push(addId)
+ plugins.push(addId)
}
+
+ // autoprefixer
if (autoprefixOptions !== false) {
autoprefixOptions = assign(
{},
@@ -50,14 +53,29 @@ module.exports = function (css) {
autoprefixOptions
)
var autoprefixer = require('autoprefixer')(autoprefixOptions)
- processors.push(autoprefixer)
+ plugins.push(autoprefixer)
+ }
+
+ // postcss options, for source maps
+ var file = loaderUtils.getRemainingRequest(this)
+ var opts
+ opts = {
+ from: file,
+ to: file,
+ map: {
+ inline: false,
+ annotation: false
+ }
+ }
+ if (map) {
+ opts.map.prev = map
}
currentId = '_v-' + hash(this.resourcePath)
- postcss(processors)
- .process(css)
+ postcss(plugins)
+ .process(css, opts)
.then(function (result) {
- cb(null, result)
+ cb(null, result.css, result.map)
})
.catch(function (e) {
console.log(e)
From 73def6f7b0bd498f132f3182d966182596e81a27 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sun, 1 Nov 2015 22:28:36 -0500
Subject: [PATCH 109/281] bump 6.0.4
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 58c0f0b67..44860ce87 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
- "version": "6.0.3",
+ "version": "6.0.4",
"description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
From 6af8b3b55190a8df7cbf5536f5bf278266541ac2 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Fri, 6 Nov 2015 17:10:51 -0500
Subject: [PATCH 110/281] support user-provided postcss plugins
---
README.md | 40 +++++++++++++++++++++++++++++-----------
lib/style-rewriter.js | 2 +-
package.json | 2 +-
3 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/README.md b/README.md
index 61e3561bd..e8172fc6c 100644
--- a/README.md
+++ b/README.md
@@ -33,7 +33,7 @@ export default {
- [Basic Usage](#basic-usage)
- [ES2015 by Default](#es2015-by-default)
- [CSS Pre-Processors](#css-pre-processors)
-- [Autoprefixing](#autoprefixing)
+- [PostCSS](#postcss)
- [Template Pre-Processors](#template-pre-processors)
- [Style Imports](#style-imports)
- [Asset URL Handling](#asset-url-handling)
@@ -133,19 +133,35 @@ You can also include Webpack loader queries in the `lang` attribute:
```
-## Autoprefixing
+## PostCSS
-Starting in 6.0.0, Any CSS output via `vue-loader` is piped through [autoprefixer](https://github.com/postcss/autoprefixer) by default. You can customize this behavior in the `vue` section of your webpack config:
+Any CSS output via `vue-loader` 6.0+ is piped through [PostCSS](https://github.com/postcss/postcss) for [scoped CSS](#scoped-css) rewriting and aut-prefixed by default using [autoprefixer](https://github.com/postcss/autoprefixer). You can configure autoprefixer or provide your own PostCSS plugins in the `vue` section of your webpack config:
``` js
// webpack.config.js
module.exports = {
// other configs...
vue: {
- // disable autoprefixing
- autoprefixer: false,
- // OR: custom options
- autoprefixer: { browsers: ['last 2 versions'] }
+ // configure autoprefixer
+ autoprefixer: {
+ browsers: ['last 2 versions']
+ }
+ }
+}
+```
+
+Using other PostCSS plugins:
+
+``` js
+// webpack.config.js
+module.exports = {
+ // other configs...
+ vue: {
+ // use custom postcss plugins
+ postcss: [require('cssnext')()],
+ // disable vue-loader autoprefixing.
+ // this is a good idea since cssnext comes with it too.
+ autoprefixer: false
}
}
```
@@ -180,7 +196,7 @@ For more details, see the respective documentations for [vue-html-loader](https:
> Experimental
-When a `
-
hi
+
hi
```
@@ -212,7 +228,9 @@ Into the following:
2. A child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS.
-3. Partials are not affected by scoped styles.
+3. If you are nesting a component inside itself, the styles may still leak down since they are considered the same component.
+
+4. Partials are not affected by scoped styles.
## Hot Reload
diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js
index 74975ffef..d8edb3e1f 100644
--- a/lib/style-rewriter.js
+++ b/lib/style-rewriter.js
@@ -37,7 +37,7 @@ module.exports = function (css, map) {
var query = loaderUtils.parseQuery(this.query)
var options = this.options.vue || {}
var autoprefixOptions = options.autoprefixer
- var plugins = []
+ var plugins = options.postcss || []
// scoped css
if (query.scoped) {
diff --git a/package.json b/package.json
index 44860ce87..ec3bd6b63 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
- "version": "6.0.4",
+ "version": "6.0.5",
"description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
From f2b2d558a35b38596486483aafd8e48c52154050 Mon Sep 17 00:00:00 2001
From: Daiwei
Date: Sun, 8 Nov 2015 20:41:38 -0500
Subject: [PATCH 111/281] Upgrade to Babel 6
---
lib/loader.js | 2 +-
package.json | 12 ++++++++----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/loader.js b/lib/loader.js
index 78bd57456..e3b1d2e3d 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -12,7 +12,7 @@ var defaultLang = {
var defaultLoaders = {
html: 'vue-html',
css: 'style!css',
- js: 'babel?optional[]=runtime&loose=all&nonStandard=false'
+ js: 'babel?presets[]=es2015&plugins[]=transform-runtime'
}
var rewriterInjectRE = /\b((css|(vue-)?html)(\?[^!]+)?!?)\b/
diff --git a/package.json b/package.json
index ec3bd6b63..8566da610 100644
--- a/package.json
+++ b/package.json
@@ -35,13 +35,17 @@
"vue-html-loader": "^1.0.0",
"css-loader": "^0.21.0",
"style-loader": "^0.13.0",
- "babel-loader": "^5.3.2",
- "babel-runtime": "^5.8.25",
+ "babel-loader": "^6.0.1",
+ "babel-plugin-transform-runtime": "^6.1.2",
+ "babel-preset-es2015": "^6.1.2",
+ "babel-runtime": "^6.0.14",
"vue-hot-reload-api": "^1.2.0"
},
"devDependencies": {
- "babel-core": "^5.8.25",
- "babel-loader": "^5.3.2",
+ "babel-core": "^6.1.2",
+ "babel-loader": "^6.0.1",
+ "babel-plugin-transform-runtime": "^6.1.2",
+ "babel-preset-es2015": "^6.1.2",
"chai": "^3.0.0",
"css-loader": "^0.21.0",
"eslint": "^1.6.0",
From e1f1430c2bb84399c687fa55b2c8034f02b8d96c Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 9 Nov 2015 13:07:17 -0500
Subject: [PATCH 112/281] fix test issues for babel 6
---
lib/loader.js | 11 +++++++++--
package.json | 7 ++++---
test/fixtures/basic.vue | 4 ++--
test/fixtures/pre.vue | 2 +-
test/test.js | 2 +-
5 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/lib/loader.js b/lib/loader.js
index e3b1d2e3d..d59a272b0 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -29,6 +29,11 @@ module.exports = function (content) {
var options = this.options.vue || {}
var vueUrl = loaderUtils.getRemainingRequest(this)
+ // respect user babel options
+ if (this.options.babel) {
+ defaultLoaders.js = 'babel'
+ }
+
// check if there are custom loaders specified with
// vueLoader.withLoaders(), otherwise use defaults
var loaders = assign({}, defaultLoaders, options.loaders)
@@ -139,8 +144,9 @@ module.exports = function (content) {
// add require for script
if (parts.script.length) {
- output += 'module.exports = ' +
- getRequire('script', parts.script[0], 0)
+ output +=
+ 'module.exports = ' + getRequire('script', parts.script[0], 0) + '\n' +
+ 'if (module.exports.__esModule) module.exports = module.exports.default\n'
}
// add require for template
@@ -178,6 +184,7 @@ module.exports = function (content) {
'hotAPI.createRecord(id, module.exports)\n' +
'module.hot.accept(' + JSON.stringify(accepted) + ', function () {\n' +
'var newOptions = ' + (scriptString ? 'require(' + scriptString + ')\n' : 'null\n') +
+ 'if (newOptions.__esModule) newOptions = newOptions.default\n' +
'var newTemplate = ' + (templateString ? 'require(' + templateString + ')\n' : 'null\n') +
'hotAPI.update(id, newOptions, newTemplate)\n' +
'})\n' +
diff --git a/package.json b/package.json
index 8566da610..637b5ea5a 100644
--- a/package.json
+++ b/package.json
@@ -20,7 +20,7 @@
"homepage": "https://github.com/vuejs/vue-loader",
"scripts": {
"lint": "eslint lib",
- "test": "eslint lib && mocha test/test.js --slow 5000"
+ "test": "eslint lib && mocha test/test.js --slow 5000 --timeout 10000"
},
"dependencies": {
"autoprefixer": "^6.0.3",
@@ -35,7 +35,7 @@
"vue-html-loader": "^1.0.0",
"css-loader": "^0.21.0",
"style-loader": "^0.13.0",
- "babel-loader": "^6.0.1",
+ "babel-loader": "^6.1.0",
"babel-plugin-transform-runtime": "^6.1.2",
"babel-preset-es2015": "^6.1.2",
"babel-runtime": "^6.0.14",
@@ -43,9 +43,10 @@
},
"devDependencies": {
"babel-core": "^6.1.2",
- "babel-loader": "^6.0.1",
+ "babel-loader": "^6.1.0",
"babel-plugin-transform-runtime": "^6.1.2",
"babel-preset-es2015": "^6.1.2",
+ "babel-runtime": "^6.0.14",
"chai": "^3.0.0",
"css-loader": "^0.21.0",
"eslint": "^1.6.0",
diff --git a/test/fixtures/basic.vue b/test/fixtures/basic.vue
index 5cf4c68ac..47a9344d8 100644
--- a/test/fixtures/basic.vue
+++ b/test/fixtures/basic.vue
@@ -9,8 +9,8 @@ comp-a h2 {
\ No newline at end of file
diff --git a/test/test.js b/test/test.js
index 2c5b5dd7a..243e5555a 100644
--- a/test/test.js
+++ b/test/test.js
@@ -130,6 +130,16 @@ describe('vue-loader', function () {
})
})
+ it('script import', function (done) {
+ test({
+ entry: './test/fixtures/script-import-entry.js'
+ }, function (window) {
+ var module = window.testModule
+ expect(module.data().msg).to.contain('Hello from Component A!')
+ done()
+ })
+ })
+
it('source map', function (done) {
var config = Object.assign({}, globalConfig, {
entry: './test/fixtures/basic.js',
From b385a1af11ab635840f5114487843f61ba245ff6 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Wed, 16 Dec 2015 17:38:20 -0500
Subject: [PATCH 150/281] docs wip
---
.gitignore | 5 +-
README.md | 29 +----
docs/README.md | 37 ++++++
docs/SUMMARY.md | 16 +++
docs/assets/CNAME | 1 +
docs/assets/circle.yml | 4 +
docs/book.json | 19 +++
docs/configurations/advanced.md | 33 +++++
docs/configurations/asset-url.md | 38 ++++++
docs/configurations/es2015.md | 70 ++++++++++
docs/configurations/extract-css.md | 34 +++++
docs/configurations/inline-loaders.md | 62 +++++++++
docs/configurations/postcss.md | 49 +++++++
docs/deploy.sh | 10 ++
docs/features/hot-reload.md | 0
docs/features/scoped-css.md | 0
docs/getting-started.md | 176 ++++++++++++++++++++++++++
docs/start/spec.md | 78 ++++++++++++
docs/start/tutorial.md | 175 +++++++++++++++++++++++++
docs/workflow/linting.md | 0
docs/workflow/testing.md | 0
package.json | 8 +-
22 files changed, 818 insertions(+), 26 deletions(-)
create mode 100644 docs/README.md
create mode 100644 docs/SUMMARY.md
create mode 100644 docs/assets/CNAME
create mode 100644 docs/assets/circle.yml
create mode 100644 docs/book.json
create mode 100644 docs/configurations/advanced.md
create mode 100644 docs/configurations/asset-url.md
create mode 100644 docs/configurations/es2015.md
create mode 100644 docs/configurations/extract-css.md
create mode 100644 docs/configurations/inline-loaders.md
create mode 100644 docs/configurations/postcss.md
create mode 100644 docs/deploy.sh
create mode 100644 docs/features/hot-reload.md
create mode 100644 docs/features/scoped-css.md
create mode 100644 docs/getting-started.md
create mode 100644 docs/start/spec.md
create mode 100644 docs/start/tutorial.md
create mode 100644 docs/workflow/linting.md
create mode 100644 docs/workflow/testing.md
diff --git a/.gitignore b/.gitignore
index e698d7971..0374b0709 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
-/node_modules
-/npm-debug.log
+node_modules
+npm-debug.log
test/output
+docs/_book
diff --git a/README.md b/README.md
index d0058e44d..59d9fd2fe 100644
--- a/README.md
+++ b/README.md
@@ -4,28 +4,7 @@
It allows you to write your components in this format:
-``` html
-
-
-
{{msg}}
-
-
-
-
-
-```
+
## Table of Contents
@@ -39,6 +18,9 @@ export default {
- [Asset URL Handling](#asset-url-handling)
- [Scoped CSS](#scoped-css)
- [Hot Reload](#hot-reload)
+- [Syntax Highlighting](#syntax-highlighting)
+- [Linting](#linting)
+- [Testing](#testing)
- [Advanced Loader Configuration](#advanced-loader-configuration)
- [Example Project](https://github.com/vuejs/vue-loader-example)
@@ -172,11 +154,12 @@ For template pre-processors, you should install `template-html-loader` plus the
## Src Imports
-If you want, you can separate your template and styles into separate files and import them using the `src` attribute:
+If you want, you can separate your templates, styles or scripts into separate files and import them using the `src` attribute:
``` html
+
```
Beware that `src` imports follow similar rules to `require()` calls, which means for relative paths you need to start with `./`, and you can import resources from installed NPM packages, e.g. `
+```
+
+Under the hood, the text content inside the `
+```
+
+However, note this makes your Vue component Webpack-specific and not compatible with Browserify and [vueify](https://github.com/vuejs/vueify). **If you intend to ship your Vue component as a reusable 3rd-party component, avoid using this syntax.**
diff --git a/docs/configurations/postcss.md b/docs/configurations/postcss.md
new file mode 100644
index 000000000..e80fe68fb
--- /dev/null
+++ b/docs/configurations/postcss.md
@@ -0,0 +1,49 @@
+# PostCSS and Autoprefixer
+
+Any CSS output processed by `vue-loader` is piped through [PostCSS](https://github.com/postcss/postcss) for [scoped CSS](../features/scoped-css.md) rewriting and aut-prefixed by default using [autoprefixer](https://github.com/postcss/autoprefixer).
+
+### Configuring Autoprefixer
+
+You can configure autoprefixer using the `autoprefixer` option under the `vue` section of your webpack config. See possible [autoprefixer options](https://github.com/postcss/autoprefixer#options). Also, you can pass in `false` to disable autoprefixing.
+
+Example:
+
+``` js
+// webpack.config.js
+module.exports = {
+ // other options...
+ module: {
+ loaders: [
+ {
+ test: /\.vue$/,
+ loader: 'vue'
+ }
+ ]
+ },
+ // vue-loader configurations
+ vue: {
+ // configure autoprefixer
+ autoprefixer: {
+ browsers: ['last 2 versions']
+ }
+ }
+}
+```
+
+### Using Custom PostCSS Plugins
+
+To use custom PostCSS pugins, pass an array to the `postcss` option under the `vue` section. Example using [CSSNext](http://cssnext.io/):
+
+``` js
+// webpack.config.js
+module.exports = {
+ // other configs...
+ vue: {
+ // use custom postcss plugins
+ postcss: [require('cssnext')()],
+ // disable vue-loader autoprefixing.
+ // this is a good idea since cssnext comes with it too.
+ autoprefixer: false
+ }
+}
+```
diff --git a/docs/deploy.sh b/docs/deploy.sh
new file mode 100644
index 000000000..1242aaf57
--- /dev/null
+++ b/docs/deploy.sh
@@ -0,0 +1,10 @@
+cd docs
+rm -rf _book
+gitbook build
+cp assets/circle.yml _book/circle.yml
+cp assets/CNAME _book/CNAME
+cd _book
+git init
+git add -A
+git commit -m 'update book'
+git push -f git@github.com:vuejs/vue-loader.git master:gh-pages
diff --git a/docs/features/hot-reload.md b/docs/features/hot-reload.md
new file mode 100644
index 000000000..e69de29bb
diff --git a/docs/features/scoped-css.md b/docs/features/scoped-css.md
new file mode 100644
index 000000000..e69de29bb
diff --git a/docs/getting-started.md b/docs/getting-started.md
new file mode 100644
index 000000000..beac721df
--- /dev/null
+++ b/docs/getting-started.md
@@ -0,0 +1,176 @@
+# Getting Started
+
+### Syntax Highlighting
+
+First thing first, you will probably want proper syntax highlighting for `*.vue` components. Currently there are syntax highlighting support for [Sublime Text](https://github.com/vuejs/vue-syntax-highlight), [Atom](https://atom.io/packages/language-vue) and [Vim](https://github.com/posva/vim-vue). Contributions for other editors/IDEs are highly appreciated! If you are not using any pre-processors in Vue components, you can also get by by treating `*.vue` files as HTML in your editor.
+
+### Project Structure
+
+We are going to walk through setting up a Webpack + `vue-loader` project from scratch. If you are interested in ready-to-run examples, check out [vue-loader-example](https://github.com/vuejs/vue-loader-example) and [vue-hackernews](https://github.com/vuejs/vue-hackernews). However, if you are not already a Webpack expert, I highly recommend going through the following tutorial to understand how the pieces fit together.
+
+A simple `vue-loader` based project structure looks like this:
+
+``` bash
+.
+├── index.html
+├── main.js
+├── components
+│  ├── App.vue
+│  ├── ComponentA.vue
+│  └── ComponentB.vue
+├── package.json
+└── webpack.config.js
+```
+
+### Installing Dependencies
+
+Before we write any code, we need to install the proper NPM dependencies. Let's run:
+
+``` bash
+# Create a package.json file.
+# fill in the questions as you desire.
+npm init
+
+# Install everything we need
+npm install\
+ webpack webpack-dev-server\
+ vue-loader vue-html-loader css-loader style-loader vue-hot-reload-api\
+ babel-loader babel-core babel-plugin-transform-runtime babel-preset-es2015\
+ babel-runtime@5\
+ --save-dev
+```
+
+That's a lot of dependencies, I know! This is mostly because `vue-loader` need to have other webpack loaders as **peer dependencies** rather than nested dependencies so that Webpack can find them.[^(1)]
+
+You may also notice that we are using `babel-runtime` version 5 instead of the latest 6.x - this is [intentional](https://github.com/vuejs/vue-loader/issues/96#issuecomment-162910917).
+
+After proper installation, your `package.json`'s `devDependencies` field should look like this:
+
+``` json
+...
+ "devDependencies": {
+ "babel-core": "^6.3.17",
+ "babel-loader": "^6.2.0",
+ "babel-plugin-transform-runtime": "^6.3.13",
+ "babel-preset-es2015": "^6.3.13",
+ "babel-runtime": "^5.8.34",
+ "css-loader": "^0.23.0",
+ "style-loader": "^0.13.0",
+ "vue-hot-reload-api": "^1.2.2",
+ "vue-html-loader": "^1.0.0",
+ "vue-loader": "^7.2.0",
+ "webpack": "^1.12.9",
+ "webpack-dev-server": "^1.14.0"
+ },
+...
+```
+
+### Configuring Webpack
+
+Here's the most basic Webpack configuration for `vue-loader`:
+
+``` js
+// webpack.config.js
+module.exports = {
+ // entry point of our application
+ entry: './main.js',
+ // where to place the compiled bundle
+ output: {
+ path: __dirname,
+ filename: 'build.js'
+ },
+ module: {
+ // `loaders` is an array of loaders to use.
+ // here we are only configuring vue-loader
+ loaders: [
+ {
+ test: /\.vue$/, // a regex for matching all files that end in `.vue`
+ loader: 'vue' // loader to use for matched files
+ }
+ ]
+ }
+}
+```
+
+With the above configuration, when you write the following in your JavaScript code:
+
+``` js
+var MyComponent = require('./my-component.vue')
+```
+
+Webpack knows it needs to pipe the contents of `./my-component.vue` through `vue-loader`, because the filename matches the regex we provided in the config.
+
+### Creating Other Files
+
+The app entry point, `main.js` typically looks like this:
+
+``` js
+// main.js
+var Vue = require('vue')
+// require a *.vue component
+var App = require('./components/App.vue')
+
+// mount a root Vue instance
+new Vue({
+ el: 'body',
+ components: {
+ // include the required component
+ // in the options
+ app: App
+ }
+})
+```
+
+Inside a `*.vue` component's `
+```
+
+Next, let's create an `index.html` that simply uses the bundled file:
+
+``` html
+
+
+
+
+
+```
+
+### Running It
+
+Finally, it's time to get it running! We will simply use [NPM scripts](https://docs.npmjs.com/misc/scripts) as our task runner, which is sufficient in most cases. Add the following to your `package.json`:
+
+``` json
+...
+"scripts": {
+ "dev": "webpack-dev-server --inline --hot"
+}
+...
+```
+
+Then run:
+
+``` bash
+npm run dev
+```
+
+And you should see your app working at `http://localhost:8080`, with hot-reloading enabled!
+
+---
+
+[^(1)] If you are using NPM version 2.x, when you do `npm install vue-loader --save-dev` it will install and save all the peer dependencies for you. However, if you are using NPM 3.x, these peer dependencies will no longer be automatically installed. You will have to install them explicitly like we did above. Another way to deal with it is to simply copy `vue-loader`'s peer dependencies into your `package.json`'s `devDependencies` field and then run `npm install`.
diff --git a/docs/start/spec.md b/docs/start/spec.md
new file mode 100644
index 000000000..a420ce17f
--- /dev/null
+++ b/docs/start/spec.md
@@ -0,0 +1,78 @@
+# Vue Component Spec
+
+A `*.vue` file is a custom file format that uses HTML-like syntax to describe a Vue component. Each `*.vue` file consists of three types of top-level language blocks: ``, `
+
+
+```
+
+`vue-loader` will parse the file, extract each language block, pipe them through other loaders if necessary, and finally assemble them back into a CommonJS module whose `module.exports` is a Vue.js component options object.
+
+`vue-loader` supports using non-default languages, such as CSS pre-processors and compile-to-HTML template languages, by specifying the `lang` attribute for a language block. The details are discussed in [Inline Loaders](../configurations/inline-loaders.md).
+
+Some more details on the language blocks:
+
+### ``
+
+- Default language: `html`.
+
+- Each `*.vue` file can contain at most one `` block at a time.
+
+- Contents will be extracted as a string and used as the `template` option for the compiled Vue component.
+
+### `
+```
+
+Beware that `src` imports follow the same path resolution rules to CommonJS `require()` calls, which means for relative paths you need to start with `./`, and you can import resources directly from installed NPM packages, e.g:
+
+``` html
+
+
+
+
+
hi
+
+```
+
+Into the following:
+
+``` html
+
+
+
+
hi
+
+```
+
+#### Notes
+
+1. You can include both scoped and non-scoped styles in the same component:
+
+ ``` html
+
+
+
+ ```
+
+2. A child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS.
+
+3. Partials are not affected by scoped styles.
+
+4. **Be careful with descendant selectors in recursive components!** For a CSS rule with the selector `.a .b`, if the element that matches `.a` contains a recursive child component, then all `.b` in that child component will be matched by the rule.
diff --git a/docs/start/spec.md b/docs/start/spec.md
index a420ce17f..06b7d0082 100644
--- a/docs/start/spec.md
+++ b/docs/start/spec.md
@@ -26,11 +26,19 @@ export default {
`vue-loader` will parse the file, extract each language block, pipe them through other loaders if necessary, and finally assemble them back into a CommonJS module whose `module.exports` is a Vue.js component options object.
-`vue-loader` supports using non-default languages, such as CSS pre-processors and compile-to-HTML template languages, by specifying the `lang` attribute for a language block. The details are discussed in [Inline Loaders](../configurations/inline-loaders.md).
+`vue-loader` supports using non-default languages, such as CSS pre-processors and compile-to-HTML template languages, by specifying the `lang` attribute for a language block. For example, you can use SASS for the style of your component like this:
-Some more details on the language blocks:
+``` html
+
+```
+
+More details can be found in [Inline Loaders](../configurations/inline-loaders.md).
+
+### Language Blocks
-### ``
+#### ``
- Default language: `html`.
@@ -38,7 +46,7 @@ Some more details on the language blocks:
- Contents will be extracted as a string and used as the `template` option for the compiled Vue component.
-### `
-
-```
-
-## ES2015 by Default
-
-`vue-loader` automatically applies Babel transforms to the JavaScript inside `*.vue` components. Write ES2015 today!
-
-**Compatibility Note:** vue-loader 7.0+ uses Babel 6. If you need to use Babel 5 for transpiling your code, use vue-loader 6.x.
-
-The default Babel options used for Vue.js components are:
-
-``` js
-{
- presets: ['es2015'],
- plugins: ['transform-runtime']
-}
-```
-
-If you wish to override this, you can add a `babel` field in your webpack config, which will be applied to all JavaScript processed by `babel-loader`. For example:
-
-``` js
-// webpack.config.js
-module.exports = {
- // other configs...
- babel: {
- // enable stage 0 transforms.
- // make sure to install babel-presets-stage-0
- presets: ['es2015', 'stage-0'],
- plugins: ['transform-runtime']
- }
-}
-```
-
-## CSS Pre-Processors
-
-`vue-loader` allows you to use other Webpack loaders to pre-process the different parts inside your `*.vue` components. Just specify the loader to use with the `lang` attribute (you also need to install the loader, obviously):
-
-``` html
-
-```
-
-You can also include Webpack loader queries in the `lang` attribute:
-
-``` html
-
-```
-
-## PostCSS
-
-Any CSS output via `vue-loader` 6.0+ is piped through [PostCSS](https://github.com/postcss/postcss) for [scoped CSS](#scoped-css) rewriting and aut-prefixed by default using [autoprefixer](https://github.com/postcss/autoprefixer). You can configure autoprefixer or provide your own PostCSS plugins in the `vue` section of your webpack config:
-
-``` js
-// webpack.config.js
-module.exports = {
- // other configs...
- vue: {
- // configure autoprefixer
- autoprefixer: {
- browsers: ['last 2 versions']
- }
- }
-}
-```
-
-Using other PostCSS plugins:
-
-``` js
-// webpack.config.js
-module.exports = {
- // other configs...
- vue: {
- // use custom postcss plugins
- postcss: [require('cssnext')()],
- // disable vue-loader autoprefixing.
- // this is a good idea since cssnext comes with it too.
- autoprefixer: false
- }
-}
-```
-
-## Template Pre-Processors
-
-For template pre-processors, you should install `template-html-loader` plus the raw templating engine. For example to use `jade`, you will need to install both `template-html-loader` and `jade` instead of `jade-loader`.
-
-## Src Imports
-
-If you want, you can separate your templates, styles or scripts into separate files and import them using the `src` attribute:
-
-``` html
-
-
-
-```
-
-Beware that `src` imports follow similar rules to `require()` calls, which means for relative paths you need to start with `./`, and you can import resources from installed NPM packages, e.g. `
-
-
hi
-
-```
-
-Into the following:
-
-``` html
-
-
-
hi
-
-```
-
-#### Notes
-
-1. You can include both scoped and non-scoped styles in the same component.
-
-2. A child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS.
-
-3. If you are nesting a component inside itself, the styles may still leak down since they are considered the same component.
-
-4. Partials are not affected by scoped styles.
-
-## Hot Reload
-
-> Experimental
-
-When using `webpack-dev-server` in hot mode, `vue-loader` enables hot component reloading for Vue.js 1.0.0+. An example config:
-
-``` js
-// webpack.config.js
-module.exports = {
- entry: './src/main.js',
- output: {
- publicPath: '/static/',
- filename: 'build.js'
- },
- module: {
- loaders: [
- { test: /\.vue$/, loader: 'vue' },
- ]
- },
- devtool: '#source-map'
-}
-```
-
-In `index.html`, include the bundle:
-
-``` html
-
-```
-
-Then, run the dev server with:
-
-``` bash
-webpack-dev-server --inline --hot
-```
-
-Finally, visit `http://localhost:8080/` to see the app with hot reloading.
-
-For a complete example with hot reloading in action, see [vue-hackernews](https://github.com/vuejs/vue-hackernews).
-
-### Hot Reload Notes
-
-- When a component is hot-reloaded, its current state is preserved. However, the component itself is destroyed and recreated, so all of its lifecycle hooks will be called accordingly. Make sure to properly teardown any side effects in your lifecycle hooks.
-
-- Private state for child components of a hot-reloaded component is not guaranteed to be preserved across reloads.
-
-- A root Vue instance or a manually mounted instance cannot be hot-reloaded. It will always force a full reload.
-
-## Advanced Loader configuration
-
-By default, `vue-loader` will try to use the loader with the same name as
-the `lang` attribute, but you can configure which loader should be used.
-
-#### Example: Use CoffeeScript for all `
```
-We will talk more about Babel/ES2015 configurations in another section.
-
### Templates
Processing templates is a little different, because most Webpack template loaders such as `jade-loader` returns a template function instead of compiled HTML string. So instead of using `jade-loader`, we will use `template-html-loader` plus the raw `jade` compiler:
From fe37d75e630d610d8eacb69377142c2f37faa3ff Mon Sep 17 00:00:00 2001
From: Evan You
Date: Fri, 18 Dec 2015 12:41:29 -0500
Subject: [PATCH 158/281] update docs regarding babelrc
---
docs/features/es2015.md | 2 ++
lib/loader.js | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/docs/features/es2015.md b/docs/features/es2015.md
index 4862861aa..dae2dd4f8 100644
--- a/docs/features/es2015.md
+++ b/docs/features/es2015.md
@@ -55,6 +55,8 @@ module.exports = {
}
```
+Alternatively, you can add a `.babelrc` file at the root of your project.
+
### Compiling `.js` Files with Babel
Since we are already using Babel, most likely you'll want to compile your normal `.js` files too! Here's how to do it in your Webpack config:
diff --git a/lib/loader.js b/lib/loader.js
index 4cdc2de66..265607873 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -36,7 +36,7 @@ module.exports = function (content) {
// respect user babel options
if (this.options.babel) {
- defaultLoaders.js = 'babel'
+ defaultLoaders.js = 'babel-loader'
}
// check if there are custom loaders specified with
From 72c0ab4cf627437081291177d34a337f1f929d2a Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sat, 19 Dec 2015 11:26:56 -0500
Subject: [PATCH 159/281] add vscode syntax highlight
---
docs/start/spec.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/start/spec.md b/docs/start/spec.md
index a29234813..1671f67d4 100644
--- a/docs/start/spec.md
+++ b/docs/start/spec.md
@@ -83,4 +83,4 @@ Beware that `src` imports follow the same path resolution rules to CommonJS `req
### Syntax Highlighting
-Currently there are syntax highlighting support for [Sublime Text](https://github.com/vuejs/vue-syntax-highlight), [Atom](https://atom.io/packages/language-vue) and [Vim](https://github.com/posva/vim-vue). Contributions for other editors/IDEs are highly appreciated! If you are not using any pre-processors in Vue components, you can also get by by treating `*.vue` files as HTML in your editor.
+Currently there are syntax highlighting support for [Sublime Text](https://github.com/vuejs/vue-syntax-highlight), [Atom](https://atom.io/packages/language-vue), [Vim](https://github.com/posva/vim-vue) and [Visual Studio Code](https://marketplace.visualstudio.com/items/liuji-jim.vue). Contributions for other editors/IDEs are highly appreciated! If you are not using any pre-processors in Vue components, you can also get by by treating `*.vue` files as HTML in your editor.
From 7b37fa9265fdb69c0150bc7d81d60fd7812cba54 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 21 Dec 2015 17:39:05 -0500
Subject: [PATCH 160/281] add dependency injection feature
---
lib/loader.js | 71 +++++++++++++++++++++++++---------------
package.json | 1 +
test/fixtures/inject.js | 1 +
test/fixtures/inject.vue | 15 +++++++++
test/test.js | 15 +++++++++
5 files changed, 76 insertions(+), 27 deletions(-)
create mode 100644 test/fixtures/inject.js
create mode 100644 test/fixtures/inject.vue
diff --git a/lib/loader.js b/lib/loader.js
index 265607873..eddabdee1 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -27,8 +27,8 @@ module.exports = function (content) {
var self = this
this.cacheable()
var cb = this.async()
- var output = ''
var options = this.options.vue || {}
+ var query = loaderUtils.parseQuery(this.query)
var vueUrl = loaderUtils.getRemainingRequest(this)
var filePath = this.resourcePath
var fileName = path.basename(filePath)
@@ -80,6 +80,7 @@ module.exports = function (content) {
var lang = part.lang || defaultLang[type]
var loader = loaders[lang]
var rewriter = getRewriter(type, scoped)
+ var injectString = (type === 'script' && query.inject) ? 'inject!' : ''
if (loader !== undefined) {
// inject rewriter before css/html loader for
// extractTextPlugin use cases
@@ -90,7 +91,7 @@ module.exports = function (content) {
} else {
loader = ensureBang(loader) + rewriter
}
- return ensureBang(loader)
+ return injectString + ensureBang(loader)
} else {
// unknown lang, assume a loader for it is used
switch (type) {
@@ -99,7 +100,7 @@ module.exports = function (content) {
case 'style':
return 'style!css!' + rewriter + lang + '!'
case 'script':
- return lang + '!'
+ return injectString + lang + '!'
}
}
}
@@ -139,6 +140,7 @@ module.exports = function (content) {
// which is an object that contains info about the vue file.
var parts = self.exec(source, url)
var hasLocalStyles = false
+ var output = 'var __vue_script__, __vue_template__\n'
// add requires for src imports
parts.styleImports.forEach(function (impt) {
@@ -157,46 +159,61 @@ module.exports = function (content) {
if (parts.script.length) {
script = parts.script[0]
output +=
- 'module.exports = ' + (
+ '__vue_script__ = ' + (
script.src
? getRequireForImport('script', script, 0)
: getRequire('script', script, 0)
- ) + '\nif (module.exports.__esModule) module.exports = module.exports.default\n'
+ )
}
// add require for template
var template
if (parts.template.length) {
template = parts.template[0]
- output += ';(typeof module.exports === "function" ' +
- '? module.exports.options ' +
- ': module.exports).template = ' + (
+ output += '__vue_template__ = ' + (
template.src
? getRequireForImport('template', template, hasLocalStyles)
: getRequire('template', template, 0, hasLocalStyles)
)
}
- // hot reload
- if (
- process.env.NODE_ENV !== 'production' &&
- (parts.script.length || parts.template.length)
- ) {
+ if (!query.inject) {
+ // attach template
+ output +=
+ 'module.exports = __vue_script__ || {}\n' +
+ 'if (module.exports.__esModule) module.exports = module.exports.default\n' +
+ ';(typeof module.exports === "function" ? module.exports.options : module.exports).template = __vue_template__\n'
+ // hot reload
+ if (
+ process.env.NODE_ENV !== 'production' &&
+ (parts.script.length || parts.template.length)
+ ) {
+ output +=
+ 'if (module.hot) {(function () {' +
+ ' module.hot.accept()\n' +
+ ' var hotAPI = require("vue-hot-reload-api")\n' +
+ ' hotAPI.install(require("vue"), true)\n' +
+ ' if (!hotAPI.compatible) return\n' +
+ ' var id = ' + JSON.stringify(filePath) + '\n' +
+ ' if (!module.hot.data) {\n' +
+ // initial insert
+ ' hotAPI.createRecord(id, module.exports)\n' +
+ ' } else {\n' +
+ // update
+ ' hotAPI.update(id, module.exports, __vue_template__)\n' +
+ ' }\n' +
+ '})()}'
+ }
+ } else {
output +=
- 'if (module.hot) {(function () {' +
- ' module.hot.accept()\n' +
- ' var hotAPI = require("vue-hot-reload-api")\n' +
- ' hotAPI.install(require("vue"), true)\n' +
- ' if (!hotAPI.compatible) return\n' +
- ' var id = ' + JSON.stringify(filePath) + '\n' +
- ' if (!module.hot.data) {\n' +
- // initial insert
- ' hotAPI.createRecord(id, module.exports)\n' +
- ' } else {\n' +
- // update
- ' hotAPI.update(id, module.exports, (typeof module.exports === "function" ? module.exports.options : module.exports).template)\n' +
- ' }\n' +
- '})()}'
+ 'module.exports = function (injections) {\n' +
+ ' var mod = __vue_script__\n' +
+ ' ? __vue_script__(injections)\n' +
+ ' : {}\n' +
+ ' if (mod.__esModule) mod = mod.default\n' +
+ ' ;(typeof mod === "function" ? mod.options : mod).template = __vue_template__\n' +
+ ' return mod\n' +
+ '}'
}
// done
diff --git a/package.json b/package.json
index 40741295c..2bc8a403f 100644
--- a/package.json
+++ b/package.json
@@ -58,6 +58,7 @@
"css-loader": "^0.21.0",
"eslint": "^1.6.0",
"extract-text-webpack-plugin": "^0.8.2",
+ "inject-loader": "^2.0.1",
"jade": "^1.11.0",
"jsdom": "^6.5.1",
"mkdirp": "^0.5.1",
diff --git a/test/fixtures/inject.js b/test/fixtures/inject.js
new file mode 100644
index 000000000..5a984f1d1
--- /dev/null
+++ b/test/fixtures/inject.js
@@ -0,0 +1 @@
+window.injector = require('!!vue?inject!./inject.vue')
diff --git a/test/fixtures/inject.vue b/test/fixtures/inject.vue
new file mode 100644
index 000000000..9f740605e
--- /dev/null
+++ b/test/fixtures/inject.vue
@@ -0,0 +1,15 @@
+
+
{{ msg }}
+
+
+
diff --git a/test/test.js b/test/test.js
index 243e5555a..68714e56c 100644
--- a/test/test.js
+++ b/test/test.js
@@ -211,4 +211,19 @@ describe('vue-loader', function () {
})
})
+ it('dependency injection', function () {
+ test({
+ entry: './test/fixtures/inject.js'
+ }, function (window) {
+ var module = window.injector({
+ '../service': {
+ msg: 'Hello from mocked service!'
+ }
+ })
+ expect(module.template).to.contain('
{{ msg }}
')
+ expect(module.data().msg).to.contain('Hello from mocked service!')
+ done()
+ })
+ })
+
})
From 358e0b76c439dc953db67aad4077158b0721c3b6 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 21 Dec 2015 17:44:27 -0500
Subject: [PATCH 161/281] tweak codegen
---
lib/loader.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/loader.js b/lib/loader.js
index eddabdee1..0fd643990 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -182,7 +182,7 @@ module.exports = function (content) {
output +=
'module.exports = __vue_script__ || {}\n' +
'if (module.exports.__esModule) module.exports = module.exports.default\n' +
- ';(typeof module.exports === "function" ? module.exports.options : module.exports).template = __vue_template__\n'
+ 'if (__vue_template__) { (typeof module.exports === "function" ? module.exports.options : module.exports).template = __vue_template__ }\n'
// hot reload
if (
process.env.NODE_ENV !== 'production' &&
@@ -211,7 +211,7 @@ module.exports = function (content) {
' ? __vue_script__(injections)\n' +
' : {}\n' +
' if (mod.__esModule) mod = mod.default\n' +
- ' ;(typeof mod === "function" ? mod.options : mod).template = __vue_template__\n' +
+ ' if (__vue_template__) { (typeof mod === "function" ? mod.options : mod).template = __vue_template__ }\n' +
' return mod\n' +
'}'
}
From 2faba5034372178ab012eea5a3af69d87ea20443 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 21 Dec 2015 17:44:50 -0500
Subject: [PATCH 162/281] 7.3.0
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 2bc8a403f..82ef59084 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
- "version": "7.2.0",
+ "version": "7.3.0",
"description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
From 03a4edb15bcb775683234fbf7a533306307f37c3 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 21 Dec 2015 18:33:46 -0500
Subject: [PATCH 163/281] update docs for mocks
---
docs/SUMMARY.md | 1 +
docs/workflow/testing-with-mocks.md | 70 +++++++++++++++++++++++++++++
docs/workflow/testing.md | 10 ++++-
3 files changed, 79 insertions(+), 2 deletions(-)
create mode 100644 docs/workflow/testing-with-mocks.md
diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md
index 7c675e154..14c8b0a10 100644
--- a/docs/SUMMARY.md
+++ b/docs/SUMMARY.md
@@ -15,3 +15,4 @@
- [Production Build](workflow/production.md)
- [Linting](workflow/linting.md)
- [Testing](workflow/testing.md)
+ - [Testing with Mocks](workflow/testing-with-mocks.md)
diff --git a/docs/workflow/testing-with-mocks.md b/docs/workflow/testing-with-mocks.md
new file mode 100644
index 000000000..171809d31
--- /dev/null
+++ b/docs/workflow/testing-with-mocks.md
@@ -0,0 +1,70 @@
+# Testing with Mocks
+
+> This feature requires `vue-loader@^7.3.0`.
+
+In a real world application, our components most likely have external dependencies. When writing unit tests for components, it would be ideal if we can mock these external dependencies so that our tests only rely the behavior of the component being tested.
+
+`vue-loader` provides a feature that allows you to inject arbitrary dependencies to a `*.vue` component, using [inject-loader](https://github.com/plasticine/inject-loader). The general idea is that instead of directly importing the component module, we use `inject-loader` to create a "module factory" function for that module. When this function gets called with an object of mocks, it returns an instances of the module with the mocks injected.
+
+Suppose we have a component like this:
+
+``` html
+
+
+
{{ msg }}
+
+
+
+```
+
+Here's how to import it with mocks:
+
+``` bash
+npm install inject-loader --save-dev
+```
+
+``` js
+// example.spec.js
+const ExampleInjector = require('!!vue?inject!./example.vue')
+```
+
+Notice that crazy require string - we are using some inline [webpack loader requests](https://webpack.github.io/docs/loaders.html) here. A quick explanation:
+
+- `!!` at the start means "disable all loaders from the global config";
+- `vue?inject!` means "use the `vue` loader, and pass in the `?inject` query". This tells `vue-loader` to compile the component in dependency-injection mode.
+
+The returned `ExampleInjector` is a factory function that can be called to create instances of the `example.vue` module:
+
+``` js
+const ExampleWithMocks = ExampleInjector({
+ // mock it
+ '../service': {
+ msg: 'Hello from a mocked service!'
+ }
+})
+```
+
+Finally, we can test the component like usual:
+
+``` js
+it('should render', () => {
+ const vm = new Vue({
+ template: '
',
+ components: {
+ 'test': ExampleWithMocks
+ }
+ }).$mount()
+ expect(vm.$el.querySelector('.msg').textContent).toBe('Hello from a mocked service!')
+})
+```
diff --git a/docs/workflow/testing.md b/docs/workflow/testing.md
index 4365abd98..515ef50d0 100644
--- a/docs/workflow/testing.md
+++ b/docs/workflow/testing.md
@@ -13,6 +13,12 @@ npm install\
```
``` js
+// we can just use the exact same webpack config by requiring it
+// however, remember to delete the original entry since we don't
+// need it during tests
+var webpackConfig = require('./webpack.config.js')
+delete webpackConfig.entry
+
// karma.conf.js
module.exports = function (config) {
config.set({
@@ -24,8 +30,8 @@ module.exports = function (config) {
preprocessors: {
'test/index.js': ['webpack']
},
- // we can just use the exact same webpack config by requiring it
- webpack: require('./webpack.config.js'),
+ // use the webpack config
+ webpack: webpackConfig,
// avoid walls of useless text
webpackMiddleware: {
noInfo: true
From 626d56857ca5929177820bdd860b0b762629de6f Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 21 Dec 2015 18:37:35 -0500
Subject: [PATCH 164/281] typo
---
docs/workflow/testing-with-mocks.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/workflow/testing-with-mocks.md b/docs/workflow/testing-with-mocks.md
index 171809d31..97f099fa2 100644
--- a/docs/workflow/testing-with-mocks.md
+++ b/docs/workflow/testing-with-mocks.md
@@ -4,7 +4,7 @@
In a real world application, our components most likely have external dependencies. When writing unit tests for components, it would be ideal if we can mock these external dependencies so that our tests only rely the behavior of the component being tested.
-`vue-loader` provides a feature that allows you to inject arbitrary dependencies to a `*.vue` component, using [inject-loader](https://github.com/plasticine/inject-loader). The general idea is that instead of directly importing the component module, we use `inject-loader` to create a "module factory" function for that module. When this function gets called with an object of mocks, it returns an instances of the module with the mocks injected.
+`vue-loader` provides a feature that allows you to inject arbitrary dependencies to a `*.vue` component, using [inject-loader](https://github.com/plasticine/inject-loader). The general idea is that instead of directly importing the component module, we use `inject-loader` to create a "module factory" function for that module. When this function gets called with an object of mocks, it returns an instance of the module with the mocks injected.
Suppose we have a component like this:
From 10a77fd5f9d2be55bd6b2cd8877cba363278a4a4 Mon Sep 17 00:00:00 2001
From: Terence Zhong <305740424@qq.com>
Date: Tue, 22 Dec 2015 09:46:51 +0800
Subject: [PATCH 165/281] allow postcss options to be a function and close
issue #106
---
lib/style-rewriter.js | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js
index 707d1d121..3896ee3cd 100644
--- a/lib/style-rewriter.js
+++ b/lib/style-rewriter.js
@@ -36,9 +36,13 @@ module.exports = function (css, map) {
var query = loaderUtils.parseQuery(this.query)
var options = this.options.vue || {}
var autoprefixOptions = options.autoprefixer
+
+ // plugins
var plugins = options.postcss
- ? options.postcss.slice() // make sure to copy it
- : []
+ if (typeof plugins === 'function') {
+ plugins = plugins.call(this, this)
+ }
+ plugins = plugins ? plugins.slice() : [] // make sure to copy it
// scoped css
if (query.scoped) {
From 6b3c0eeff073859ec99b0ece8f637e450ed9f8cc Mon Sep 17 00:00:00 2001
From: Terence Zhong <305740424@qq.com>
Date: Tue, 22 Dec 2015 09:59:22 +0800
Subject: [PATCH 166/281] instead of null, expect error not exist in tests
---
test/test.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/test.js b/test/test.js
index 68714e56c..8cb736ce5 100644
--- a/test/test.js
+++ b/test/test.js
@@ -34,7 +34,7 @@ describe('vue-loader', function () {
function getFile (file, cb) {
fs.readFile(path.resolve(outputDir, file), 'utf-8', function (err, data) {
- expect(err).to.be.null
+ expect(err).to.be.not.exist
cb(data)
})
}
From c2b4bc1d3bca49f9b86672bab0e64496fc8b474f Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sat, 26 Dec 2015 21:17:05 -0500
Subject: [PATCH 167/281] parser can be sync
---
lib/parser.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/parser.js b/lib/parser.js
index 29a185657..7926e0600 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -3,7 +3,7 @@ var parser = new parse5.Parser(null, { locationInfo: true })
module.exports = function (content) {
this.cacheable()
- var cb = this.async()
+
var output = {
template: [],
style: [],
@@ -24,10 +24,10 @@ module.exports = function (content) {
(type === 'script' || type === 'template') &&
output[type].length > 0
) {
- return cb(new Error(
+ throw new Error(
'[vue-loader] Only one
diff --git a/test/test.js b/test/test.js
index 97fa04b5f..a548469ff 100644
--- a/test/test.js
+++ b/test/test.js
@@ -82,7 +82,7 @@ describe('vue-loader', function () {
'' +
''
)
- expect(module.data().msg).to.contain('Hello from babel!')
+ expect(module.data().msg).to.contain('Hello from coffee!')
var style = window.document.querySelector('style').textContent
expect(style).to.contain('body {\n font: 100% Helvetica, sans-serif;\n color: #999;\n}')
done()
From db7737e981b3cd748144543bf3dd7abf102c085c Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sat, 2 Jan 2016 10:41:39 -0500
Subject: [PATCH 187/281] 7.5.2
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index ef0102476..2865691a1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
- "version": "7.5.1",
+ "version": "7.5.2",
"description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
From 32e5aa8ef7f0f7fd67898bea20725db0479af351 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 4 Jan 2016 14:40:19 -0500
Subject: [PATCH 188/281] use de-indent as a dep
---
.gitignore | 1 +
lib/deindent.js | 41 -----------------------------------------
lib/parser.js | 2 +-
package.json | 1 +
4 files changed, 3 insertions(+), 42 deletions(-)
delete mode 100644 lib/deindent.js
diff --git a/.gitignore b/.gitignore
index 0374b0709..6c2848eb9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ node_modules
npm-debug.log
test/output
docs/_book
+.DS_Store
diff --git a/lib/deindent.js b/lib/deindent.js
deleted file mode 100644
index fec85889f..000000000
--- a/lib/deindent.js
+++ /dev/null
@@ -1,41 +0,0 @@
-// For some reason, if a script code block has a base indent
-// level, the eval-source-map gets messed up. So we have to
-// manually deindent script code blocks here.
-
-var splitRE = /\r?\n/g
-var emptyRE = /^\s*$/
-
-module.exports = function deindent (str) {
- var lines = str.split(splitRE)
- var min = Infinity
- var type, cur, c
- for (var i = 0; i < lines.length; i++) {
- var line = lines[i]
- if (!emptyRE.test(line)) {
- if (!type) {
- c = line.charAt(0)
- if (c === ' ' || c === '\t') {
- type = c
- } else {
- return str
- }
- } else {
- cur = count(line, type)
- if (cur < min) {
- min = cur
- }
- }
- }
- }
- return lines.map(function (line) {
- return line.slice(min)
- }).join('\n')
-}
-
-function count (line, type) {
- var i = 0
- while (line.charAt(i) === type) {
- i++
- }
- return i
-}
diff --git a/lib/parser.js b/lib/parser.js
index 393afc731..546a663ac 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -3,7 +3,7 @@ var parser = new parse5.Parser(null, { locationInfo: true })
var cache = require('lru-cache')(100)
var SourceMapGenerator = require('source-map').SourceMapGenerator
var hash = require('hash-sum')
-var deindent = require('./deindent')
+var deindent = require('de-indent')
var splitRE = /\r?\n/g
var emptyRE = /^\s*$/
diff --git a/package.json b/package.json
index 2865691a1..82f04b26c 100644
--- a/package.json
+++ b/package.json
@@ -30,6 +30,7 @@
},
"dependencies": {
"autoprefixer": "^6.0.3",
+ "de-indent": "^1.0.0",
"hash-sum": "^1.0.2",
"loader-utils": "^0.2.10",
"lru-cache": "^2.7.0",
From 7dab1602112015867aeb1af0a21a9a53d0e65cef Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 4 Jan 2016 17:12:10 -0500
Subject: [PATCH 189/281] upgrade to parse5 2.0
---
lib/parser.js | 29 ++++++++++++++---------------
lib/template-rewriter.js | 6 ++----
package.json | 2 +-
3 files changed, 17 insertions(+), 20 deletions(-)
diff --git a/lib/parser.js b/lib/parser.js
index 546a663ac..f08d2ce42 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -1,5 +1,4 @@
var parse5 = require('parse5')
-var parser = new parse5.Parser(null, { locationInfo: true })
var cache = require('lru-cache')(100)
var SourceMapGenerator = require('source-map').SourceMapGenerator
var hash = require('hash-sum')
@@ -22,7 +21,9 @@ module.exports = function (content, filename) {
styleImports: []
}
- var fragment = parser.parseFragment(content)
+ var fragment = parse5.parseFragment(content, {
+ locationInfo: true
+ })
fragment.childNodes.forEach(function (node) {
var type = node.tagName
@@ -30,6 +31,10 @@ module.exports = function (content, filename) {
var src = getAttribute(node, 'src')
var scoped = getAttribute(node, 'scoped') != null
+ if (!output[type]) {
+ return
+ }
+
// node count check
if (
(type === 'script' || type === 'template') &&
@@ -63,25 +68,19 @@ module.exports = function (content, filename) {
return
}
- if (!node.childNodes || !node.childNodes.length) {
+ // skip empty script/style tags
+ if (type !== 'template' && (!node.childNodes || !node.childNodes.length)) {
return
}
- if (!output[type]) {
- return
- }
-
- // Work around changes in parse5 >= 1.2.0
- if (node.childNodes[0].nodeName === '#document-fragment') {
- node = node.childNodes[0]
- if (!node.childNodes.length) {
- return
- }
+ // template content is nested inside the content fragment
+ if (type === 'template') {
+ node = node.content
}
// extract part
- var start = node.childNodes[0].__location.start
- var end = node.childNodes[node.childNodes.length - 1].__location.end
+ var start = node.childNodes[0].__location.startOffset
+ var end = node.childNodes[node.childNodes.length - 1].__location.endOffset
var result
var lineOffset
if (type === 'script') {
diff --git a/lib/template-rewriter.js b/lib/template-rewriter.js
index ba7b9b6ef..2a0e9f5d6 100644
--- a/lib/template-rewriter.js
+++ b/lib/template-rewriter.js
@@ -1,13 +1,11 @@
var parse5 = require('parse5')
-var parser = new parse5.Parser()
-var serializer = new parse5.Serializer()
var loaderUtils = require('loader-utils')
module.exports = function (html) {
this.cacheable()
var query = loaderUtils.parseQuery(this.query)
var id = query.id
- var tree = parser.parseFragment(html)
+ var tree = parse5.parseFragment(html)
walk(tree, function (node) {
if (node.attrs) {
node.attrs.push({
@@ -16,7 +14,7 @@ module.exports = function (html) {
})
}
})
- return serializer.serialize(tree)
+ return parse5.serialize(tree)
}
function walk (tree, fn) {
diff --git a/package.json b/package.json
index 82f04b26c..5e39fadba 100644
--- a/package.json
+++ b/package.json
@@ -35,7 +35,7 @@
"loader-utils": "^0.2.10",
"lru-cache": "^2.7.0",
"object-assign": "^4.0.0",
- "parse5": "^1.5.0",
+ "parse5": "^2.0.2",
"postcss": "^5.0.10",
"postcss-selector-parser": "^1.1.2",
"source-map": "^0.5.3"
From f623eeeb3197e528a26ed99665bf45e699bac38c Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 4 Jan 2016 17:23:01 -0500
Subject: [PATCH 190/281] validate template
---
lib/loader.js | 2 +-
lib/parser.js | 6 +++++-
lib/selector.js | 2 +-
package.json | 3 ++-
4 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/lib/loader.js b/lib/loader.js
index 356ba5bdb..e5724bbed 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -135,7 +135,7 @@ module.exports = function (content) {
}
}
- var parts = parse(content, fileName)
+ var parts = parse(content, fileName, this.emitWarning)
var hasLocalStyles = false
var output = 'var __vue_script__, __vue_template__\n'
diff --git a/lib/parser.js b/lib/parser.js
index f08d2ce42..5636699dc 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -1,4 +1,5 @@
var parse5 = require('parse5')
+var validateTemplate = require('vue-template-validator')
var cache = require('lru-cache')(100)
var SourceMapGenerator = require('source-map').SourceMapGenerator
var hash = require('hash-sum')
@@ -6,7 +7,7 @@ var deindent = require('de-indent')
var splitRE = /\r?\n/g
var emptyRE = /^\s*$/
-module.exports = function (content, filename) {
+module.exports = function (content, filename, warn) {
var cacheKey = hash(filename + content)
// source-map cache busting for hot-reloadded modules
@@ -76,6 +77,9 @@ module.exports = function (content, filename) {
// template content is nested inside the content fragment
if (type === 'template') {
node = node.content
+ if (!lang) {
+ validateTemplate(node, content, warn)
+ }
}
// extract part
diff --git a/lib/selector.js b/lib/selector.js
index 9b5975471..990bd1917 100644
--- a/lib/selector.js
+++ b/lib/selector.js
@@ -6,7 +6,7 @@ module.exports = function (content) {
this.cacheable()
var query = loaderUtils.parseQuery(this.query)
var filename = path.basename(this.resourcePath)
- var parts = parse(content, filename)
+ var parts = parse(content, filename, this.emitWarning)
var part = parts[query.type][query.index]
this.callback(null, part.content, part.map)
}
diff --git a/package.json b/package.json
index 5e39fadba..8db79e379 100644
--- a/package.json
+++ b/package.json
@@ -38,7 +38,8 @@
"parse5": "^2.0.2",
"postcss": "^5.0.10",
"postcss-selector-parser": "^1.1.2",
- "source-map": "^0.5.3"
+ "source-map": "^0.5.3",
+ "vue-template-validator": "^1.0.0"
},
"peerDependencies": {
"vue-html-loader": "^1.0.0",
From be92a6a264a64866501791034ce6df406adb83e4 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 4 Jan 2016 17:58:04 -0500
Subject: [PATCH 191/281] use emitError for template syntax errors
---
lib/loader.js | 2 +-
lib/selector.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/loader.js b/lib/loader.js
index e5724bbed..6b98f06fe 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -135,7 +135,7 @@ module.exports = function (content) {
}
}
- var parts = parse(content, fileName, this.emitWarning)
+ var parts = parse(content, fileName, this.emitError)
var hasLocalStyles = false
var output = 'var __vue_script__, __vue_template__\n'
diff --git a/lib/selector.js b/lib/selector.js
index 990bd1917..1dd697861 100644
--- a/lib/selector.js
+++ b/lib/selector.js
@@ -6,7 +6,7 @@ module.exports = function (content) {
this.cacheable()
var query = loaderUtils.parseQuery(this.query)
var filename = path.basename(this.resourcePath)
- var parts = parse(content, filename, this.emitWarning)
+ var parts = parse(content, filename, this.emitError)
var part = parts[query.type][query.index]
this.callback(null, part.content, part.map)
}
From ceae62033d3a04e4b749391b4242c7ce8d487780 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 4 Jan 2016 20:01:27 -0500
Subject: [PATCH 192/281] raise warnings in the main loader only
---
lib/loader.js | 8 +++++++-
lib/parser.js | 8 +++++---
lib/selector.js | 2 +-
3 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/lib/loader.js b/lib/loader.js
index 6b98f06fe..60d129f4c 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -135,10 +135,16 @@ module.exports = function (content) {
}
}
- var parts = parse(content, fileName, this.emitError)
+ var parts = parse(content, fileName)
var hasLocalStyles = false
var output = 'var __vue_script__, __vue_template__\n'
+ // check if there are any template syntax errors
+ var templateWarnings = parts.template.length && parts.template[0].warnings
+ if (templateWarnings) {
+ templateWarnings.forEach(this.emitError)
+ }
+
// add requires for src imports
parts.styleImports.forEach(function (impt) {
if (impt.scoped) hasLocalStyles = true
diff --git a/lib/parser.js b/lib/parser.js
index 5636699dc..34038a788 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -7,7 +7,7 @@ var deindent = require('de-indent')
var splitRE = /\r?\n/g
var emptyRE = /^\s*$/
-module.exports = function (content, filename, warn) {
+module.exports = function (content, filename) {
var cacheKey = hash(filename + content)
// source-map cache busting for hot-reloadded modules
@@ -31,6 +31,7 @@ module.exports = function (content, filename, warn) {
var lang = getAttribute(node, 'lang')
var src = getAttribute(node, 'src')
var scoped = getAttribute(node, 'scoped') != null
+ var warnings = null
if (!output[type]) {
return
@@ -78,7 +79,7 @@ module.exports = function (content, filename, warn) {
if (type === 'template') {
node = node.content
if (!lang) {
- validateTemplate(node, content, warn)
+ warnings = validateTemplate(node, content)
}
}
@@ -129,7 +130,8 @@ module.exports = function (content, filename, warn) {
lang: lang,
scoped: scoped,
content: result,
- map: map.toJSON()
+ map: map.toJSON(),
+ warnings: warnings
})
})
diff --git a/lib/selector.js b/lib/selector.js
index 1dd697861..9b5975471 100644
--- a/lib/selector.js
+++ b/lib/selector.js
@@ -6,7 +6,7 @@ module.exports = function (content) {
this.cacheable()
var query = loaderUtils.parseQuery(this.query)
var filename = path.basename(this.resourcePath)
- var parts = parse(content, filename, this.emitError)
+ var parts = parse(content, filename)
var part = parts[query.type][query.index]
this.callback(null, part.content, part.map)
}
From 8bb87febea364319fa52cbd63bd06cd71d8c04c5 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Mon, 4 Jan 2016 22:37:24 -0500
Subject: [PATCH 193/281] upgrade jsdom
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 8db79e379..a6135b5e5 100644
--- a/package.json
+++ b/package.json
@@ -66,7 +66,7 @@
"extract-text-webpack-plugin": "^0.8.2",
"inject-loader": "^2.0.1",
"jade": "^1.11.0",
- "jsdom": "^6.5.1",
+ "jsdom": "^7.2.2",
"mkdirp": "^0.5.1",
"mocha": "^2.2.5",
"node-libs-browser": "^0.5.3",
From 16004cec6811ac97fd8192c618b4545c4549619b Mon Sep 17 00:00:00 2001
From: Evan You
Date: Tue, 5 Jan 2016 11:08:49 -0500
Subject: [PATCH 194/281] also deindent style/template content
---
lib/parser.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/parser.js b/lib/parser.js
index 34038a788..09390d7dd 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -98,7 +98,7 @@ module.exports = function (content, filename) {
commentScript(content.slice(end), lang)
} else {
lineOffset = content.slice(0, start).split(splitRE).length - 1
- result = content.slice(start, end)
+ result = deindent(content.slice(start, end))
}
// generate source map
From 60356c270165d2631c95bc3de863029ac89154ec Mon Sep 17 00:00:00 2001
From: Evan You
Date: Tue, 5 Jan 2016 11:58:36 -0500
Subject: [PATCH 195/281] only generate sourcemap if needed
---
lib/loader.js | 2 +-
lib/parser.js | 50 +++++++++++++++++++++++++------------------------
lib/selector.js | 2 +-
3 files changed, 28 insertions(+), 26 deletions(-)
diff --git a/lib/loader.js b/lib/loader.js
index 60d129f4c..8b2945aae 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -135,7 +135,7 @@ module.exports = function (content) {
}
}
- var parts = parse(content, fileName)
+ var parts = parse(content, fileName, this.sourceMap)
var hasLocalStyles = false
var output = 'var __vue_script__, __vue_template__\n'
diff --git a/lib/parser.js b/lib/parser.js
index 09390d7dd..4c384b78a 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -7,7 +7,7 @@ var deindent = require('de-indent')
var splitRE = /\r?\n/g
var emptyRE = /^\s*$/
-module.exports = function (content, filename) {
+module.exports = function (content, filename, needMap) {
var cacheKey = hash(filename + content)
// source-map cache busting for hot-reloadded modules
@@ -32,6 +32,7 @@ module.exports = function (content, filename) {
var src = getAttribute(node, 'src')
var scoped = getAttribute(node, 'scoped') != null
var warnings = null
+ var map = null
if (!output[type]) {
return
@@ -101,36 +102,37 @@ module.exports = function (content, filename) {
result = deindent(content.slice(start, end))
}
- // generate source map
- var map = new SourceMapGenerator()
- map.setSourceContent(filenameWithHash, content)
- result.split(splitRE).forEach(function (line, index) {
- map.addMapping({
- source: filenameWithHash,
- original: {
- line: index + 1 + lineOffset,
- column: 0
- },
- generated: {
- line: index + 1,
- column: 0
- }
+ if (needMap) {
+ // generate source map
+ map = new SourceMapGenerator()
+ map.setSourceContent(filenameWithHash, content)
+ result.split(splitRE).forEach(function (line, index) {
+ map.addMapping({
+ source: filenameWithHash,
+ original: {
+ line: index + 1 + lineOffset,
+ column: 0
+ },
+ generated: {
+ line: index + 1,
+ column: 0
+ }
+ })
})
- })
-
- // workaround for Webpack eval-source-map bug
- // https://github.com/webpack/webpack/pull/1816
- // in case the script was piped through another loader
- // that doesn't pass down the source map properly.
- if (type === 'script' && !lang) {
- result += '\n/* generated by vue-loader */\n'
+ // workaround for Webpack eval-source-map bug
+ // https://github.com/webpack/webpack/pull/1816
+ // in case the script was piped through another loader
+ // that doesn't pass down the source map properly.
+ if (type === 'script' && !lang) {
+ result += '\n/* generated by vue-loader */\n'
+ }
}
output[type].push({
lang: lang,
scoped: scoped,
content: result,
- map: map.toJSON(),
+ map: map && map.toJSON(),
warnings: warnings
})
})
diff --git a/lib/selector.js b/lib/selector.js
index 9b5975471..11dc029ff 100644
--- a/lib/selector.js
+++ b/lib/selector.js
@@ -6,7 +6,7 @@ module.exports = function (content) {
this.cacheable()
var query = loaderUtils.parseQuery(this.query)
var filename = path.basename(this.resourcePath)
- var parts = parse(content, filename)
+ var parts = parse(content, filename, this.sourceMap)
var part = parts[query.type][query.index]
this.callback(null, part.content, part.map)
}
From 96f64929dd77eb16985b1bc6502d8bf8c448d4e3 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Tue, 5 Jan 2016 12:03:25 -0500
Subject: [PATCH 196/281] fix source map test
---
test/test.js | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/test/test.js b/test/test.js
index a548469ff..63f2433d7 100644
--- a/test/test.js
+++ b/test/test.js
@@ -152,12 +152,11 @@ describe('vue-loader', function () {
getFile('test.build.js', function (code) {
var line
var col
- var lines = code.split(/\r?\n/g)
var targetRE = /^\s+msg: 'Hello from Component A!'/
- lines.some(function (l, i) {
+ code.split(/\r?\n/g).some(function (l, i) {
if (targetRE.test(l)) {
- line = i
- col = lines[i - 1].length
+ line = i + 1
+ col = l.length
return true
}
})
From 577a547231055d8ee4178d3ea964d382abaf11b1 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Tue, 5 Jan 2016 13:28:01 -0500
Subject: [PATCH 197/281] use parse5 2.1.0
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index a6135b5e5..0be3dd265 100644
--- a/package.json
+++ b/package.json
@@ -35,7 +35,7 @@
"loader-utils": "^0.2.10",
"lru-cache": "^2.7.0",
"object-assign": "^4.0.0",
- "parse5": "^2.0.2",
+ "parse5": "^2.1.0",
"postcss": "^5.0.10",
"postcss-selector-parser": "^1.1.2",
"source-map": "^0.5.3",
From ce9337f4264a42e12000276c12b80840b9b8f4ba Mon Sep 17 00:00:00 2001
From: Evan You
Date: Tue, 5 Jan 2016 13:35:34 -0500
Subject: [PATCH 198/281] no need to modify source url in style-rewriter now we
have cache busting
---
lib/style-rewriter.js | 5 -----
1 file changed, 5 deletions(-)
diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js
index cd58016d4..f66af3da5 100644
--- a/lib/style-rewriter.js
+++ b/lib/style-rewriter.js
@@ -81,11 +81,6 @@ module.exports = function (css, map) {
.process(css, opts)
.then(function (result) {
var map = result.map && result.map.toJSON()
- // ensure we give the style source a unique name
- // so that Webpack doesn't get confused
- if (map) {
- map.sources[0] = query.file + '.style'
- }
cb(null, result.css, map)
})
.catch(function (e) {
From bfccd14d782d0dcf23dd6a7ac25f0edc6b6da7fb Mon Sep 17 00:00:00 2001
From: Evan You
Date: Tue, 5 Jan 2016 14:22:10 -0500
Subject: [PATCH 199/281] use vue-style-loader instead of style-loader
---
docs/start/tutorial.md | 4 ++--
lib/loader.js | 4 ++--
package.json | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/docs/start/tutorial.md b/docs/start/tutorial.md
index 30feb7bba..67833fafe 100644
--- a/docs/start/tutorial.md
+++ b/docs/start/tutorial.md
@@ -30,7 +30,7 @@ npm init
# Install everything we need
npm install\
webpack webpack-dev-server\
- vue-loader vue-html-loader css-loader style-loader vue-hot-reload-api\
+ vue-loader vue-html-loader css-loader vue-style-loader vue-hot-reload-api\
babel-loader babel-core babel-plugin-transform-runtime babel-preset-es2015\
babel-runtime@5\
--save-dev
@@ -52,9 +52,9 @@ After proper installation, your `package.json`'s `devDependencies` field should
"babel-preset-es2015": "^6.3.13",
"babel-runtime": "^5.8.34",
"css-loader": "^0.23.0",
- "style-loader": "^0.13.0",
"vue-hot-reload-api": "^1.2.2",
"vue-html-loader": "^1.0.0",
+ "vue-style-loader": "^1.0.0",
"vue-loader": "^7.2.0",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0"
diff --git a/lib/loader.js b/lib/loader.js
index 8b2945aae..acf37d06a 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -13,7 +13,7 @@ var defaultLang = {
var defaultLoaders = {
html: 'vue-html-loader',
- css: 'style-loader!css-loader',
+ css: 'vue-style-loader!css-loader',
js: 'babel-loader?presets[]=es2015&plugins[]=transform-runtime'
}
@@ -40,7 +40,7 @@ module.exports = function (content) {
// enable css source map if needed
if (this.sourceMap) {
- defaultLoaders.css = 'style-loader!css-loader?sourceMap'
+ defaultLoaders.css = 'vue-style-loader!css-loader?sourceMap'
}
// check if there are custom loaders specified via
diff --git a/package.json b/package.json
index 0be3dd265..69ed8e68c 100644
--- a/package.json
+++ b/package.json
@@ -44,7 +44,7 @@
"peerDependencies": {
"vue-html-loader": "^1.0.0",
"css-loader": "*",
- "style-loader": "*",
+ "vue-style-loader": "^1.0.0",
"babel-loader": "^6.1.0",
"babel-core": "^6.1.2",
"babel-plugin-transform-runtime": "^6.1.2",
@@ -71,7 +71,7 @@
"mocha": "^2.2.5",
"node-libs-browser": "^0.5.3",
"rimraf": "^2.4.0",
- "style-loader": "^0.13.0",
+ "vue-style-loader": "^1.0.0",
"stylus-loader": "^1.4.0",
"template-html-loader": "^0.0.3",
"vue-hot-reload-api": "^1.2.0",
From fd3ce5ab8629b6e8cc2d7a3f0a1a48321818e2d9 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Tue, 5 Jan 2016 14:26:18 -0500
Subject: [PATCH 200/281] 8.0.0
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 69ed8e68c..7949d8871 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
- "version": "7.5.2",
+ "version": "8.0.0",
"description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
From 9639ace8a25cce2e66c83fab0c9f9acfd573a63e Mon Sep 17 00:00:00 2001
From: Zhangdroid
Date: Thu, 7 Jan 2016 00:05:13 +0800
Subject: [PATCH 201/281] change "cssnext" to "postcss-cssnext"
---
docs/features/postcss.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/features/postcss.md b/docs/features/postcss.md
index ca45bd05e..487b9e71f 100644
--- a/docs/features/postcss.md
+++ b/docs/features/postcss.md
@@ -40,7 +40,7 @@ module.exports = {
// other configs...
vue: {
// use custom postcss plugins
- postcss: [require('cssnext')()],
+ postcss: [require('postcss-cssnext')()],
// disable vue-loader autoprefixing.
// this is a good idea since cssnext comes with it too.
autoprefixer: false
From fa03c63106395e5b1c3acc2b06f7677a9562d082 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Wed, 6 Jan 2016 18:26:33 -0500
Subject: [PATCH 202/281] do not add mappings for empty/comment lines (fix
module.exports source map bug)
---
lib/loader.js | 2 +-
lib/parser.js | 41 ++++++++++++++++++++++++-----------------
test/fixtures/basic.vue | 14 +++++++-------
test/test.js | 2 +-
4 files changed, 33 insertions(+), 26 deletions(-)
diff --git a/lib/loader.js b/lib/loader.js
index acf37d06a..efd8e168a 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -14,7 +14,7 @@ var defaultLang = {
var defaultLoaders = {
html: 'vue-html-loader',
css: 'vue-style-loader!css-loader',
- js: 'babel-loader?presets[]=es2015&plugins[]=transform-runtime'
+ js: 'babel-loader?presets[]=es2015&plugins[]=transform-runtime&comments=false'
}
var rewriterInjectRE = /\b((css|(vue-)?html)(-loader)?(\?[^!]+)?!?)\b/
diff --git a/lib/parser.js b/lib/parser.js
index 4c384b78a..b490b64a8 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -106,18 +106,27 @@ module.exports = function (content, filename, needMap) {
// generate source map
map = new SourceMapGenerator()
map.setSourceContent(filenameWithHash, content)
+
+ // do not add mappings for comment lines - babel's source map
+ // somehow gets messed up because of it
+ var isCommentLine = function (line) {
+ return type === 'script' && !lang && line.indexOf('//') === 0
+ }
+
result.split(splitRE).forEach(function (line, index) {
- map.addMapping({
- source: filenameWithHash,
- original: {
- line: index + 1 + lineOffset,
- column: 0
- },
- generated: {
- line: index + 1,
- column: 0
- }
- })
+ if (!emptyRE.test(line) && !isCommentLine(line)) {
+ map.addMapping({
+ source: filenameWithHash,
+ original: {
+ line: index + 1 + lineOffset,
+ column: 0
+ },
+ generated: {
+ line: index + 1,
+ column: 0
+ }
+ })
+ }
})
// workaround for Webpack eval-source-map bug
// https://github.com/webpack/webpack/pull/1816
@@ -145,19 +154,17 @@ function commentScript (content, lang) {
return content
.split(splitRE)
.map(function (line) {
- if (emptyRE.test(line)) {
- return line
- }
+ line = emptyRE.test(line) ? '' : ' ' + line
switch (lang) {
case 'coffee':
case 'coffee-jsx':
case 'coffee-redux':
- return '# ' + line
+ return '#' + line
case 'purs':
case 'ulmus':
- return '-- ' + line
+ return '--' + line
default:
- return '// ' + line
+ return '//' + line
}
})
.join('\n')
diff --git a/test/fixtures/basic.vue b/test/fixtures/basic.vue
index 47a9344d8..5035c8304 100644
--- a/test/fixtures/basic.vue
+++ b/test/fixtures/basic.vue
@@ -1,15 +1,9 @@
-
-
{{msg}}
+
+
diff --git a/test/test.js b/test/test.js
index 63f2433d7..7c5bf77ff 100644
--- a/test/test.js
+++ b/test/test.js
@@ -165,7 +165,7 @@ describe('vue-loader', function () {
column: col
})
expect(pos.source.indexOf('basic.vue') > -1)
- expect(pos.line).to.equal(15)
+ expect(pos.line).to.equal(9)
done()
})
})
From d249aa4a8838817061ed39de497980b264995989 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Wed, 6 Jan 2016 18:36:44 -0500
Subject: [PATCH 203/281] also skip comment line source maps for other langs
---
lib/parser.js | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/lib/parser.js b/lib/parser.js
index b490b64a8..0c6223c4a 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -6,6 +6,13 @@ var hash = require('hash-sum')
var deindent = require('de-indent')
var splitRE = /\r?\n/g
var emptyRE = /^\s*$/
+var commentSymbols = {
+ 'coffee': '#',
+ 'coffee-jsx': '#',
+ 'coffee-redux': '#',
+ 'purs': '--',
+ 'ulmus': '--'
+}
module.exports = function (content, filename, needMap) {
@@ -110,7 +117,8 @@ module.exports = function (content, filename, needMap) {
// do not add mappings for comment lines - babel's source map
// somehow gets messed up because of it
var isCommentLine = function (line) {
- return type === 'script' && !lang && line.indexOf('//') === 0
+ return type === 'script' &&
+ line.indexOf(getCommentSymbol(lang)) === 0
}
result.split(splitRE).forEach(function (line, index) {
@@ -151,25 +159,19 @@ module.exports = function (content, filename, needMap) {
}
function commentScript (content, lang) {
+ var symbol = getCommentSymbol(lang)
return content
.split(splitRE)
.map(function (line) {
- line = emptyRE.test(line) ? '' : ' ' + line
- switch (lang) {
- case 'coffee':
- case 'coffee-jsx':
- case 'coffee-redux':
- return '#' + line
- case 'purs':
- case 'ulmus':
- return '--' + line
- default:
- return '//' + line
- }
+ return symbol + (emptyRE.test(line) ? '' : ' ' + line)
})
.join('\n')
}
+function getCommentSymbol (lang) {
+ return commentSymbols[lang] || '//'
+}
+
function getAttribute (node, name) {
if (node.attrs) {
var i = node.attrs.length
From 34bf82c7835ca2a3b1c6faa578f6e01fd1422bce Mon Sep 17 00:00:00 2001
From: Evan You
Date: Wed, 6 Jan 2016 18:37:05 -0500
Subject: [PATCH 204/281] 8.0.1
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 7949d8871..335fada40 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
- "version": "8.0.0",
+ "version": "8.0.1",
"description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
From b79e048c651178cda4fc56a3317439652778ff97 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Thu, 7 Jan 2016 09:14:33 -0500
Subject: [PATCH 205/281] preserve EOL when creating comment scripts
---
lib/parser.js | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/parser.js b/lib/parser.js
index 0c6223c4a..be4a40981 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -160,12 +160,16 @@ module.exports = function (content, filename, needMap) {
function commentScript (content, lang) {
var symbol = getCommentSymbol(lang)
- return content
- .split(splitRE)
- .map(function (line) {
+ var lines = content.split(splitRE)
+ return lines.map(function (line, index) {
+ // preserve EOL
+ if (index === lines.length - 1 && emptyRE.test(line)) {
+ return ''
+ } else {
return symbol + (emptyRE.test(line) ? '' : ' ' + line)
- })
- .join('\n')
+ }
+ })
+ .join('\n')
}
function getCommentSymbol (lang) {
From baad51ac0efc2ee93dac2aa0bd259c2f405b347d Mon Sep 17 00:00:00 2001
From: Evan You
Date: Thu, 7 Jan 2016 09:14:53 -0500
Subject: [PATCH 206/281] 8.0.2
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 335fada40..f2d77cd64 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-loader",
- "version": "8.0.1",
+ "version": "8.0.2",
"description": "Vue.js component loader for Webpack",
"main": "index.js",
"repository": {
From cf7ae96b87528857e596f969dc1ea2e0f59b1b94 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Wed, 13 Jan 2016 00:53:38 -0500
Subject: [PATCH 207/281] add warning for ignored named exports
---
lib/loader.js | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lib/loader.js b/lib/loader.js
index efd8e168a..805650a48 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -167,6 +167,16 @@ module.exports = function (content) {
? getRequireForImport('script', script, 0)
: getRequire('script', script, 0)
)
+ // check and warn named exports
+ if (!this.minimize) {
+ output +=
+ 'if (__vue_script__ &&\n' +
+ ' __vue_script__.__esModule &&\n' +
+ ' Object.keys(__vue_script__).length > 1) {\n' +
+ ' console.warn("[vue-loader] ' + path.relative(process.cwd(), filePath) +
+ ': named exports in *.vue files are ignored.")' +
+ '}\n'
+ }
}
// add require for template
From b36eb07ab67f29aace1954e3462c1ba75c51dde2 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Fri, 22 Jan 2016 11:22:47 -0500
Subject: [PATCH 208/281] Avoid style import duplication when extracted (fix
#139)
Ensure non-scoped style imports have the same identifier by only
adding style-rewriter query parameters when the style is scoped,
becuase extract-text-webpack-plugin relies on the module
identifier for dedupe.
---
lib/loader.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/loader.js b/lib/loader.js
index 805650a48..8f898ac80 100644
--- a/lib/loader.js
+++ b/lib/loader.js
@@ -110,12 +110,12 @@ module.exports = function (content) {
}
function getRewriter (type, scoped) {
- var meta = '?id=' + moduleId + '&file=' + fileName
+ var meta = '?id=' + moduleId
switch (type) {
case 'template':
return scoped ? (rewriters.template + meta + '!') : ''
case 'style':
- return rewriters.style + meta + (scoped ? '&scoped=true!' : '!')
+ return rewriters.style + (scoped ? meta + '&scoped=true!' : '!')
default:
return ''
}
From 416b26379fd9e3c2231047a2894a167356b9c0a0 Mon Sep 17 00:00:00 2001
From: Evan You
Date: Sun, 24 Jan 2016 11:45:48 -0500
Subject: [PATCH 209/281] fix scoped CSS rewrite for due to parse5
upgrade (fix #141)
---
lib/template-rewriter.js | 8 ++++++--
test/fixtures/scoped-css.vue | 1 +
test/test.js | 3 ++-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/lib/template-rewriter.js b/lib/template-rewriter.js
index 2a0e9f5d6..e57c66287 100644
--- a/lib/template-rewriter.js
+++ b/lib/template-rewriter.js
@@ -20,8 +20,12 @@ module.exports = function (html) {
function walk (tree, fn) {
if (tree.childNodes) {
tree.childNodes.forEach(function (node) {
- fn(node)
- walk(node, fn)
+ if (node.tagName === 'template') {
+ walk(node.content, fn)
+ } else {
+ fn(node)
+ walk(node, fn)
+ }
})
}
}
diff --git a/test/fixtures/scoped-css.vue b/test/fixtures/scoped-css.vue
index 580745de0..c6b2d4c64 100644
--- a/test/fixtures/scoped-css.vue
+++ b/test/fixtures/scoped-css.vue
@@ -13,4 +13,5 @@ h1 {
hi
hi
+
yo
diff --git a/test/test.js b/test/test.js
index 7c5bf77ff..d8e53d9b0 100644
--- a/test/test.js
+++ b/test/test.js
@@ -97,7 +97,8 @@ describe('vue-loader', function () {
var id = '_v-' + hash(require.resolve('./fixtures/scoped-css.vue'))
expect(module.template).to.contain(
'