Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-loader

Package Overview
Dependencies
Maintainers
1
Versions
304
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-loader - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

test/fixtures/basic.js

109

index.js

@@ -1,13 +0,17 @@

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 = {

@@ -17,3 +21,4 @@ template: 'html!template-html-loader?raw&engine=',

script: ''
};
}
var defaultLang = {

@@ -23,45 +28,83 @@ template: 'html',

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;
this.loadModule(url, function(err, source, map, module) {
if (err) return cb(err);
var self = this
var url = "!!" + require.resolve("./parser.js") + "!" + vueUrl
this.loadModule(url, function(err, source) {
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')
}
{
"name": "vue-loader",
"version": "2.0.0",
"version": "2.0.1",
"description": "Vue.js component loader for Webpack",

@@ -21,6 +21,8 @@ "main": "index.js",

"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",
"source-map": "^0.4.2"
"parse5": "^1.1.4"
},

@@ -31,3 +33,22 @@ "peerDependencies": {

"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"
}
}

@@ -1,14 +0,12 @@

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 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 = {

@@ -19,50 +17,29 @@ template: {},

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);
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 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)
});
var start = node.children[0].__location.start
var end = node.children[node.children.length - 1].__location.end
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));
cb(null, 'module.exports = ' + JSON.stringify(output))
}
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 type = path[0]
var lang = path[1] || ''
cb(null, parts[type][lang])
})
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc