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

rollup-plugin-vue

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-vue - npm Package Compare versions

Comparing version 4.0.0-alpha.1 to 4.0.0

CHANGELOG.md

408

dist/rollup-plugin-vue.common.js

@@ -5,59 +5,59 @@ 'use strict';

var _JSON$stringify = _interopDefault(require('@babel/runtime/core-js/json/stringify'));
var rollupPluginutils = require('rollup-pluginutils');
var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator'));
var _extends = _interopDefault(require('@babel/runtime/helpers/extends'));
var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator'));
var _JSON$stringify = _interopDefault(require('@babel/runtime/core-js/json/stringify'));
var rollupPluginutils = require('rollup-pluginutils');
var compiler = require('vue-component-compiler');
var componentCompiler = require('@vue/component-compiler');
var path = require('path');
var logger = _interopDefault(require('debug'));
var _WeakMap = _interopDefault(require('@babel/runtime/core-js/weak-map'));
var _Set = _interopDefault(require('@babel/runtime/core-js/set'));
var _objectSpread = _interopDefault(require('@babel/runtime/helpers/objectSpread'));
var componentCompilerUtils = require('@vue/component-compiler-utils');
var hash = _interopDefault(require('hash-sum'));
var debug = logger('rollup-plugin-vue');
function s(any) {
return _JSON$stringify(any, null, 2);
function createVueFilter(include, exclude) {
var filter = rollupPluginutils.createFilter(include, exclude);
return function (id) {
return filter(id) && id.endsWith('.vue');
};
}
function relative$1(p) {
if (p.startsWith(process.cwd())) {
p = p.replace(process.cwd(), '');
p = p.replace(/^[\\/]/, '');
}
return p;
var REGEX = /\.vue\?{[^}]+}#\.[a-z]+$/i;
function isVuePartRequest(id) {
return REGEX.test(id);
}
function inline(src) {
return "import target from '".concat(src, "'\nexport default target");
function createVuePartRequest(filename, lang, type, index) {
return filename + '?' + _JSON$stringify({
type: type,
index: index
}) + '#.' + (lang || createVuePartRequest.defaultLang[type]);
}
createVuePartRequest.defaultLang = {
template: 'html',
styles: 'css',
script: 'js'
/**
* @export
* @param {string} id
* @returns {{filename: string, meta: { type: string, index?: number }} | undefined}
*/
function inlineStyle(_ref, descriptor, _ref2) {
var id = _ref.id,
index = _ref.index,
code = _ref.code,
map = _ref.map,
modules = _ref.modules;
var isServer = _ref2.isServer,
isProduction = _ref2.isProduction,
inject = _ref2.inject;
var output = "const cssModules = ".concat(modules ? s(modules) : '{}', "\n");
output += "export const style = ".concat(s(code), "\n") + "export const map = ".concat(s(map), "\n") + "const content = [[".concat(index, ", style, ").concat(descriptor.attrs.media && s(descriptor.attrs.media), ", ").concat(isProduction ? 'undefined' : 'map', " ]]\n");
};
function parseVuePartRequest(id) {
if (!id.includes('.vue')) return;
var length = id.indexOf('.vue') + 4;
var filename = id.substr(0, length);
var query = id.substr(length + 1).replace(/#.[a-z]+$/, '');
if (inject) {
if (isServer) {
output += "import inject from 'vue-component-compiler/src/runtime/inject-style-server'\n" + "cssModules.__inject__ = context => inject(".concat(s(id), ", content, ").concat(isProduction, ", context)\n");
} else {
output += "import inject from 'vue-component-compiler/src/runtime/inject-style-client'\n" + "cssModules.__inject__ = () => inject(".concat(s(id), ", content, ").concat(isProduction, ")\n");
}
}
output += "export default cssModules";
return output;
try {
var meta = JSON.parse(query);
return {
filename: filename,
meta: meta
};
} catch (e) {}
}
function makeId(id, type, lang, index) {
return id + '?' + _JSON$stringify({
type: type,
index: index
}) + '#.' + lang;
function resolveVuePart(descriptors, id) {
var descriptor = descriptors[id.filename];
var part = descriptor[id.meta.type];
return Array.isArray(part) ? part[id.meta.index] : part;
}

@@ -67,108 +67,110 @@

var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
debug('Yo! rolling vue!');
var filter = rollupPluginutils.createFilter(opts.include, opts.exclude);
var cache = {};
var isVue = createVueFilter(opts.include, opts.exclude);
delete opts.include;
delete opts.exclude;
var vueOptions = {
hasStyleInjectFn: true,
isServer: opts.server === true || process.env.VUE_ENV === 'server',
isProduction: opts.production === true || process.env.NODE_ENV === 'production'
};
var cwd = process.cwd();
var compiler = componentCompiler.createDefaultCompiler(opts);
return {
name: 'vue',
transform: function () {
var _transform = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee(source, filename) {
var descriptor, result;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (isVue(filename)) {
_context.next = 2;
break;
}
function parseId(id) {
var relative$$1 = path.relative(cwd, id);
return _context.abrupt("return");
if (/\.vue\?\{[^#]+\}#\./.test(id)) {
var start = id.lastIndexOf('?');
var end = id.lastIndexOf('#');
case 2:
descriptor = compiler.compileToDescriptor(filename, source);
try {
var parsed = JSON.parse(id.substring(start + 1, end));
parsed.id = id.substring(0, start);
parsed.relative = relative$$1;
return parsed;
} catch (e) {
console.error(e);
}
}
if (descriptor.template && descriptor.template.errors && descriptor.template.errors.length) {
console.error('> Errors: ' + path.relative(process.cwd(), filename) + '\n' + descriptor.template.errors.map(function (it) {
return ' - ' + it;
}).join('\n'));
}
if (!filter(id) || id.endsWith('.vue')) return {
sfc: true,
id: id,
relative: relative$$1
};
return {
ignore: true,
id: id,
relative: relative$$1
};
}
if (descriptor.template && descriptor.template.tips && descriptor.template.tips.length) {
console.log('> Tips: ' + path.relative(process.cwd(), filename) + '\n' + descriptor.template.tips.map(function (it) {
return ' - ' + it;
}).join('\n'));
}
return {
name: 'vue',
resolveId: function resolveId(request) {
var q = parseId(request);
if (q.ignore || q.sfc) return;
debug(" > Resolve --> ".concat(q.relative));
var descriptor = cache[q.id];
if (!descriptor) throw Error("SFC (".concat(q.id, ") is not processed."));
var part = descriptor[q.type] || (q.type === 'style' ? descriptor.styles[q.index] : descriptor.customBlocks[q.index]);
result = componentCompiler.assemble(compiler, filename, descriptor);
return _context.abrupt("return", result.code);
if (part && part.src) {
return part.src;
}
case 7:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
return request;
},
load: function load(request) {
var q = parseId(request);
if (q.ignore || q.sfc) return;
debug(" > Load --> ".concat(q.relative));
var id = q.id;
var filename = relative$1(id);
var descriptor = cache[id];
if (!descriptor) throw Error("SFC (".concat(filename, ") is not processed."));
return function transform(_x, _x2) {
return _transform.apply(this, arguments);
};
}()
};
}
switch (q.type) {
case 'template':
if (!descriptor.template) return '';
if (descriptor.template.src) return;
return {
code: descriptor.template.content,
map: descriptor.template.map
};
function vue$1() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var isVue = createVueFilter(opts.include, opts.exclude);
var isProduction = process.env.NODE_ENV === 'production';
var compiler = componentCompiler.createDefaultCompiler(opts.compiler);
createVuePartRequest.defaultLang = _objectSpread({}, createVuePartRequest.defaultLang, opts.defaultLang);
var blacklisted = new _Set(opts.blacklistCustomBlocks || []);
delete opts.include;
delete opts.exclude;
var descriptors = new _WeakMap();
case 'script':
if (!descriptor.script) return {
code: 'export default {}\n',
map: {
mappings: ''
}
};
return {
code: descriptor.script.src ? inline(descriptor.script.src) : descriptor.script.content,
map: descriptor.script.map
};
function compileTemplate(id, _ref, source) {
var functional = _ref.functional;
case 'style':
var style = descriptor.styles[q.index];
if (style.src) return;
return {
code: style.content,
map: style.map
};
var _compiler$compileToDe = compiler.compileToDescriptor(id.filename, "<template ".concat(functional ? 'functional' : '', ">\n").concat(source, "\n</template>")),
template = _compiler$compileToDe.template;
case 'custom':
var block = descriptor.customBlocks[q.index];
if (block.src) return;
return block.content;
if (template.errors && template.errors.length) {
console.error('> Errors: ' + path.relative(process.cwd(), id.filename) + '\n' + template.errors.map(function (it) {
return ' - ' + it;
}).join('\n'));
}
if (template.tips && template.tips.length) {
console.log('> Tips: ' + path.relative(process.cwd(), id.filename) + '\n' + template.tips.map(function (it) {
return ' - ' + it;
}).join('\n'));
}
return "".concat(template.code, "\n export { render, staticRenderFns }");
}
return {
name: 'vue.delegate',
resolveId: function resolveId(id) {
if (isVuePartRequest(id)) {
var ref = parseVuePartRequest(id);
var element = resolveVuePart(descriptors, ref);
if (element.src) return path.resolve(path.dirname(ref.filename), element.src);
return id;
}
},
load: function load(id) {
if (!isVuePartRequest(id)) return;
id = parseVuePartRequest(id);
return resolveVuePart(descriptors, id).content;
},
transform: function () {
var _transform = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee(source, request) {
var q, filename, scopeId, descriptor, code, output, style, result;
_regeneratorRuntime.mark(function _callee(source, filename) {
var descriptor, scopeId, input, result, id, element, _compiler$compileToDe2, styles;
return _regeneratorRuntime.wrap(function _callee$(_context) {

@@ -178,108 +180,65 @@ while (1) {

case 0:
q = parseId(request);
if (!(q.ignore || q.dep)) {
_context.next = 3;
if (!isVue(filename)) {
_context.next = 9;
break;
}
return _context.abrupt("return");
descriptor = descriptors[filename] = componentCompilerUtils.parse({
filename: filename,
source: source,
needMap: true
});
scopeId = 'data-v-' + (isProduction ? hash(path.basename(filename) + source) : hash(filename + source));
input = {
scopeId: scopeId,
styles: [],
customBlocks: []
};
case 3:
filename = relative$1(q.id);
scopeId = compiler.generateScopeId(filename, source, vueOptions.isProduction);
if (descriptor.template) {
input.template = {
code: "\n import * as template from '".concat(createVuePartRequest(filename, descriptor.template.lang, 'template'), "'\n var render = template.render\n var staticRenderFns = template.staticRenderFns \n "),
functional: 'functional' in descriptor.template.attrs
};
}
if (!q.sfc) {
_context.next = 11;
break;
if (descriptor.script) {
input.script = {
code: "\n export * from '".concat(createVuePartRequest(filename, descriptor.script.lang, 'script'), "'\n import script from '").concat(createVuePartRequest(filename, descriptor.script.lang, 'script'), "'\n export default script\n ")
};
}
debug(">> Transform: ".concat(q.relative));
descriptor = compiler.parse(source, filename);
cache[q.id] = descriptor;
code = compiler.assemble({
script: {
id: descriptor.script && makeId(q.id, 'script', descriptor.script.lang || 'js'),
descriptor: descriptor.script
},
render: {
id: descriptor.template && makeId(q.id, 'template', descriptor.template.lang || 'html'),
descriptor: descriptor.template
},
styles: descriptor.styles.map(function (style, index) {
return {
id: makeId(q.id, 'style', style.lang || 'css', index),
descriptor: style
};
}),
customBlocks: vueOptions.isProduction ? [] : descriptor.customBlocks.map(function (block, index) {
return {
id: makeId(q.id, 'custom', block.lang || block.type),
descriptor: block
};
})
}, filename, _extends({}, vueOptions, {
scopeId: scopeId,
moduleIdentifier: scopeId
}));
return _context.abrupt("return", {
code: code,
map: {
mappings: ''
}
result = componentCompiler.assemble(compiler, filename, input, opts);
descriptor.customBlocks.forEach(function (block, index) {
if (blacklisted.has(block.type)) return;
result.code += '\n' + "export * from '".concat(createVuePartRequest(filename, block.attrs.lang || createVuePartRequest.defaultLang[block.type] || block.type, 'customBlocks', index), "'");
});
return _context.abrupt("return", result);
case 11:
if (!(q.type === 'template')) {
_context.next = 16;
case 9:
if (!isVuePartRequest(filename)) {
_context.next = 19;
break;
}
debug(" > Compile --> ".concat(q.relative));
output = compiler.compileTemplate({
code: source,
descriptor: cache[q.id].template
}, q.id, _extends({}, vueOptions, {
scopeId: scopeId
}));
if (!output.map) output.map = {
mappings: ''
};
return _context.abrupt("return", output);
id = parseVuePartRequest(filename);
element = resolveVuePart(descriptors, id);
case 16:
if (!(q.type === 'style')) {
_context.next = 23;
if (!(id.meta.type === 'styles')) {
_context.next = 17;
break;
}
debug(" > Compile --> ".concat(q.relative));
style = cache[q.id].styles[q.index];
_context.next = 21;
return compiler.compileStyle({
code: source,
descriptor: style
}, q.id, _extends({}, vueOptions, {
scopeId: scopeId,
async: true
}));
_compiler$compileToDe2 = compiler.compileToDescriptor(id.filename, "<style ".concat(element.scoped ? 'scoped' : '', " ").concat(element.module ? 'module' + (typeof element.module === 'string' ? '="' + element.module + '"' : '') : '', ">\n").concat(source, "\n</style>")), styles = _compiler$compileToDe2.styles;
return _context.abrupt("return", styles[0]);
case 21:
result = _context.sent;
return _context.abrupt("return", {
code: inlineStyle({
id: path.relative(cwd, q.id),
index: q.index,
code: result.code,
modules: result.modules,
map: result.map
}, style, _extends({}, vueOptions, {
inject: !opts.extract
})),
map: {
mappings: ''
}
});
case 17:
if (!(id.meta.type === 'template')) {
_context.next = 19;
break;
}
case 23:
return _context.abrupt("return", compileTemplate(id, element, source));
case 19:
case "end":

@@ -299,2 +258,5 @@ return _context.stop();

vue.delegate = vue$1;
module.exports = vue;
//# sourceMappingURL=rollup-plugin-vue.common.js.map

@@ -0,60 +1,58 @@

import _JSON$stringify from '@babel/runtime/core-js/json/stringify';
import { createFilter } from 'rollup-pluginutils';
import _regeneratorRuntime from '@babel/runtime/regenerator';
import _extends from '@babel/runtime/helpers/extends';
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
import _JSON$stringify from '@babel/runtime/core-js/json/stringify';
import { createFilter } from 'rollup-pluginutils';
import { assemble, compileStyle, compileTemplate, generateScopeId, parse } from 'vue-component-compiler';
import * as compiler from 'vue-component-compiler';
import { relative } from 'path';
import * as path from 'path';
import logger from 'debug';
import { createDefaultCompiler, assemble } from '@vue/component-compiler';
import { relative, resolve, dirname, basename } from 'path';
import _WeakMap from '@babel/runtime/core-js/weak-map';
import _Set from '@babel/runtime/core-js/set';
import _objectSpread from '@babel/runtime/helpers/objectSpread';
import { parse } from '@vue/component-compiler-utils';
import hash from 'hash-sum';
var debug = logger('rollup-plugin-vue');
function s(any) {
return _JSON$stringify(any, null, 2);
function createVueFilter(include, exclude) {
var filter = createFilter(include, exclude);
return function (id) {
return filter(id) && id.endsWith('.vue');
};
}
function relative$1(p) {
if (p.startsWith(process.cwd())) {
p = p.replace(process.cwd(), '');
p = p.replace(/^[\\/]/, '');
}
return p;
var REGEX = /\.vue\?{[^}]+}#\.[a-z]+$/i;
function isVuePartRequest(id) {
return REGEX.test(id);
}
function inline(src) {
return "import target from '".concat(src, "'\nexport default target");
function createVuePartRequest(filename, lang, type, index) {
return filename + '?' + _JSON$stringify({
type: type,
index: index
}) + '#.' + (lang || createVuePartRequest.defaultLang[type]);
}
createVuePartRequest.defaultLang = {
template: 'html',
styles: 'css',
script: 'js'
/**
* @export
* @param {string} id
* @returns {{filename: string, meta: { type: string, index?: number }} | undefined}
*/
function inlineStyle(_ref, descriptor, _ref2) {
var id = _ref.id,
index = _ref.index,
code = _ref.code,
map = _ref.map,
modules = _ref.modules;
var isServer = _ref2.isServer,
isProduction = _ref2.isProduction,
inject = _ref2.inject;
var output = "const cssModules = ".concat(modules ? s(modules) : '{}', "\n");
output += "export const style = ".concat(s(code), "\n") + "export const map = ".concat(s(map), "\n") + "const content = [[".concat(index, ", style, ").concat(descriptor.attrs.media && s(descriptor.attrs.media), ", ").concat(isProduction ? 'undefined' : 'map', " ]]\n");
};
function parseVuePartRequest(id) {
if (!id.includes('.vue')) return;
var length = id.indexOf('.vue') + 4;
var filename = id.substr(0, length);
var query = id.substr(length + 1).replace(/#.[a-z]+$/, '');
if (inject) {
if (isServer) {
output += "import inject from 'vue-component-compiler/src/runtime/inject-style-server'\n" + "cssModules.__inject__ = context => inject(".concat(s(id), ", content, ").concat(isProduction, ", context)\n");
} else {
output += "import inject from 'vue-component-compiler/src/runtime/inject-style-client'\n" + "cssModules.__inject__ = () => inject(".concat(s(id), ", content, ").concat(isProduction, ")\n");
}
}
output += "export default cssModules";
return output;
try {
var meta = JSON.parse(query);
return {
filename: filename,
meta: meta
};
} catch (e) {}
}
function makeId(id, type, lang, index) {
return id + '?' + _JSON$stringify({
type: type,
index: index
}) + '#.' + lang;
function resolveVuePart(descriptors, id) {
var descriptor = descriptors[id.filename];
var part = descriptor[id.meta.type];
return Array.isArray(part) ? part[id.meta.index] : part;
}

@@ -64,108 +62,110 @@

var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
debug('Yo! rolling vue!');
var filter = createFilter(opts.include, opts.exclude);
var cache = {};
var isVue = createVueFilter(opts.include, opts.exclude);
delete opts.include;
delete opts.exclude;
var vueOptions = {
hasStyleInjectFn: true,
isServer: opts.server === true || process.env.VUE_ENV === 'server',
isProduction: opts.production === true || process.env.NODE_ENV === 'production'
};
var cwd = process.cwd();
var compiler = createDefaultCompiler(opts);
return {
name: 'vue',
transform: function () {
var _transform = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee(source, filename) {
var descriptor, result;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (isVue(filename)) {
_context.next = 2;
break;
}
function parseId(id) {
var relative$$1 = relative(cwd, id);
return _context.abrupt("return");
if (/\.vue\?\{[^#]+\}#\./.test(id)) {
var start = id.lastIndexOf('?');
var end = id.lastIndexOf('#');
case 2:
descriptor = compiler.compileToDescriptor(filename, source);
try {
var parsed = JSON.parse(id.substring(start + 1, end));
parsed.id = id.substring(0, start);
parsed.relative = relative$$1;
return parsed;
} catch (e) {
console.error(e);
}
}
if (descriptor.template && descriptor.template.errors && descriptor.template.errors.length) {
console.error('> Errors: ' + relative(process.cwd(), filename) + '\n' + descriptor.template.errors.map(function (it) {
return ' - ' + it;
}).join('\n'));
}
if (!filter(id) || id.endsWith('.vue')) return {
sfc: true,
id: id,
relative: relative$$1
};
return {
ignore: true,
id: id,
relative: relative$$1
};
}
if (descriptor.template && descriptor.template.tips && descriptor.template.tips.length) {
console.log('> Tips: ' + relative(process.cwd(), filename) + '\n' + descriptor.template.tips.map(function (it) {
return ' - ' + it;
}).join('\n'));
}
return {
name: 'vue',
resolveId: function resolveId(request) {
var q = parseId(request);
if (q.ignore || q.sfc) return;
debug(" > Resolve --> ".concat(q.relative));
var descriptor = cache[q.id];
if (!descriptor) throw Error("SFC (".concat(q.id, ") is not processed."));
var part = descriptor[q.type] || (q.type === 'style' ? descriptor.styles[q.index] : descriptor.customBlocks[q.index]);
result = assemble(compiler, filename, descriptor);
return _context.abrupt("return", result.code);
if (part && part.src) {
return part.src;
}
case 7:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
return request;
},
load: function load(request) {
var q = parseId(request);
if (q.ignore || q.sfc) return;
debug(" > Load --> ".concat(q.relative));
var id = q.id;
var filename = relative$1(id);
var descriptor = cache[id];
if (!descriptor) throw Error("SFC (".concat(filename, ") is not processed."));
return function transform(_x, _x2) {
return _transform.apply(this, arguments);
};
}()
};
}
switch (q.type) {
case 'template':
if (!descriptor.template) return '';
if (descriptor.template.src) return;
return {
code: descriptor.template.content,
map: descriptor.template.map
};
function vue$1() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var isVue = createVueFilter(opts.include, opts.exclude);
var isProduction = process.env.NODE_ENV === 'production';
var compiler = createDefaultCompiler(opts.compiler);
createVuePartRequest.defaultLang = _objectSpread({}, createVuePartRequest.defaultLang, opts.defaultLang);
var blacklisted = new _Set(opts.blacklistCustomBlocks || []);
delete opts.include;
delete opts.exclude;
var descriptors = new _WeakMap();
case 'script':
if (!descriptor.script) return {
code: 'export default {}\n',
map: {
mappings: ''
}
};
return {
code: descriptor.script.src ? inline(descriptor.script.src) : descriptor.script.content,
map: descriptor.script.map
};
function compileTemplate(id, _ref, source) {
var functional = _ref.functional;
case 'style':
var style = descriptor.styles[q.index];
if (style.src) return;
return {
code: style.content,
map: style.map
};
var _compiler$compileToDe = compiler.compileToDescriptor(id.filename, "<template ".concat(functional ? 'functional' : '', ">\n").concat(source, "\n</template>")),
template = _compiler$compileToDe.template;
case 'custom':
var block = descriptor.customBlocks[q.index];
if (block.src) return;
return block.content;
if (template.errors && template.errors.length) {
console.error('> Errors: ' + relative(process.cwd(), id.filename) + '\n' + template.errors.map(function (it) {
return ' - ' + it;
}).join('\n'));
}
if (template.tips && template.tips.length) {
console.log('> Tips: ' + relative(process.cwd(), id.filename) + '\n' + template.tips.map(function (it) {
return ' - ' + it;
}).join('\n'));
}
return "".concat(template.code, "\n export { render, staticRenderFns }");
}
return {
name: 'vue.delegate',
resolveId: function resolveId(id) {
if (isVuePartRequest(id)) {
var ref = parseVuePartRequest(id);
var element = resolveVuePart(descriptors, ref);
if (element.src) return resolve(dirname(ref.filename), element.src);
return id;
}
},
load: function load(id) {
if (!isVuePartRequest(id)) return;
id = parseVuePartRequest(id);
return resolveVuePart(descriptors, id).content;
},
transform: function () {
var _transform = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee(source, request) {
var q, filename, scopeId, descriptor, code, output, style, result;
_regeneratorRuntime.mark(function _callee(source, filename) {
var descriptor, scopeId, input, result, id, element, _compiler$compileToDe2, styles;
return _regeneratorRuntime.wrap(function _callee$(_context) {

@@ -175,108 +175,65 @@ while (1) {

case 0:
q = parseId(request);
if (!(q.ignore || q.dep)) {
_context.next = 3;
if (!isVue(filename)) {
_context.next = 9;
break;
}
return _context.abrupt("return");
descriptor = descriptors[filename] = parse({
filename: filename,
source: source,
needMap: true
});
scopeId = 'data-v-' + (isProduction ? hash(basename(filename) + source) : hash(filename + source));
input = {
scopeId: scopeId,
styles: [],
customBlocks: []
};
case 3:
filename = relative$1(q.id);
scopeId = generateScopeId(filename, source, vueOptions.isProduction);
if (descriptor.template) {
input.template = {
code: "\n import * as template from '".concat(createVuePartRequest(filename, descriptor.template.lang, 'template'), "'\n var render = template.render\n var staticRenderFns = template.staticRenderFns \n "),
functional: 'functional' in descriptor.template.attrs
};
}
if (!q.sfc) {
_context.next = 11;
break;
if (descriptor.script) {
input.script = {
code: "\n export * from '".concat(createVuePartRequest(filename, descriptor.script.lang, 'script'), "'\n import script from '").concat(createVuePartRequest(filename, descriptor.script.lang, 'script'), "'\n export default script\n ")
};
}
debug(">> Transform: ".concat(q.relative));
descriptor = parse(source, filename);
cache[q.id] = descriptor;
code = assemble({
script: {
id: descriptor.script && makeId(q.id, 'script', descriptor.script.lang || 'js'),
descriptor: descriptor.script
},
render: {
id: descriptor.template && makeId(q.id, 'template', descriptor.template.lang || 'html'),
descriptor: descriptor.template
},
styles: descriptor.styles.map(function (style, index) {
return {
id: makeId(q.id, 'style', style.lang || 'css', index),
descriptor: style
};
}),
customBlocks: vueOptions.isProduction ? [] : descriptor.customBlocks.map(function (block, index) {
return {
id: makeId(q.id, 'custom', block.lang || block.type),
descriptor: block
};
})
}, filename, _extends({}, vueOptions, {
scopeId: scopeId,
moduleIdentifier: scopeId
}));
return _context.abrupt("return", {
code: code,
map: {
mappings: ''
}
result = assemble(compiler, filename, input, opts);
descriptor.customBlocks.forEach(function (block, index) {
if (blacklisted.has(block.type)) return;
result.code += '\n' + "export * from '".concat(createVuePartRequest(filename, block.attrs.lang || createVuePartRequest.defaultLang[block.type] || block.type, 'customBlocks', index), "'");
});
return _context.abrupt("return", result);
case 11:
if (!(q.type === 'template')) {
_context.next = 16;
case 9:
if (!isVuePartRequest(filename)) {
_context.next = 19;
break;
}
debug(" > Compile --> ".concat(q.relative));
output = compileTemplate({
code: source,
descriptor: cache[q.id].template
}, q.id, _extends({}, vueOptions, {
scopeId: scopeId
}));
if (!output.map) output.map = {
mappings: ''
};
return _context.abrupt("return", output);
id = parseVuePartRequest(filename);
element = resolveVuePart(descriptors, id);
case 16:
if (!(q.type === 'style')) {
_context.next = 23;
if (!(id.meta.type === 'styles')) {
_context.next = 17;
break;
}
debug(" > Compile --> ".concat(q.relative));
style = cache[q.id].styles[q.index];
_context.next = 21;
return compileStyle({
code: source,
descriptor: style
}, q.id, _extends({}, vueOptions, {
scopeId: scopeId,
async: true
}));
_compiler$compileToDe2 = compiler.compileToDescriptor(id.filename, "<style ".concat(element.scoped ? 'scoped' : '', " ").concat(element.module ? 'module' + (typeof element.module === 'string' ? '="' + element.module + '"' : '') : '', ">\n").concat(source, "\n</style>")), styles = _compiler$compileToDe2.styles;
return _context.abrupt("return", styles[0]);
case 21:
result = _context.sent;
return _context.abrupt("return", {
code: inlineStyle({
id: relative(cwd, q.id),
index: q.index,
code: result.code,
modules: result.modules,
map: result.map
}, style, _extends({}, vueOptions, {
inject: !opts.extract
})),
map: {
mappings: ''
}
});
case 17:
if (!(id.meta.type === 'template')) {
_context.next = 19;
break;
}
case 23:
return _context.abrupt("return", compileTemplate(id, element, source));
case 19:
case "end":

@@ -296,2 +253,5 @@ return _context.stop();

vue.delegate = vue$1;
export default vue;
//# sourceMappingURL=rollup-plugin-vue.js.map
{
"name": "rollup-plugin-vue",
"version": "4.0.0-alpha.1",
"version": "4.0.0",
"description": "Roll .vue files",

@@ -11,6 +11,7 @@ "main": "dist/rollup-plugin-vue.common.js",

"lint": "prettier --no-semi --single-quote --write **/*.js **/*.vue !test/target/** !dist/**",
"prebuild": "npm run lint",
"prepare": "npm run test",
"pretest": "npm run build",
"test": "jest"
"prepare": "npm run build",
"pretest": "npm run lint && npm run build",
"test": "jest",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
"version": "npm run changelog && git add CHANGELOG.md"
},

@@ -37,16 +38,31 @@ "repository": {

"@babel/runtime": "^7.0.0-beta.39",
"@vue/component-compiler": "^3.1.0",
"@vue/component-compiler-utils": "^1.2.1",
"debug": "^2.6.0",
"rollup-pluginutils": "^2.0.1",
"vue-component-compiler": "git+https://github.com/vuejs/vue-component-compiler.git"
"hash-sum": "^1.0.2",
"rollup-pluginutils": "^2.0.1"
},
"devDependencies": {
"@babel/core": "^7.0.0-beta.39",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.39",
"@babel/plugin-transform-runtime": "^7.0.0-beta.39",
"@babel/preset-env": "^7.0.0-beta.39",
"@babel/core": "^7.0.0-beta.46",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.46",
"@babel/plugin-transform-runtime": "^7.0.0-beta.46",
"@babel/preset-env": "^7.0.0-beta.46",
"babel-core": "7.0.0-bridge.0",
"conventional-changelog": "^1.1.24",
"jest": "^22.4.2",
"prettier": "^1.10.2",
"rollup": "^0.41.4",
"rollup-plugin-babel": "^4.0.0-beta.0"
"node-sass": "^4.9.0",
"pug": "^2.0.3",
"puppeteer": "^1.3.0",
"rollup": "^0.58.2",
"rollup-plugin-babel": "^4.0.0-beta.4",
"rollup-plugin-commonjs": "^9.1.0",
"rollup-plugin-image": "^1.0.2",
"rollup-plugin-md": "^0.0.7",
"rollup-plugin-node-resolve": "^3.3.0",
"vue": "^2.5.16",
"vue-template-compiler": "^2.5.16"
},
"peerDependencies": {
"vue-template-compiler": "*"
}
}

@@ -10,4 +10,2 @@ <div class="text-xs-center" align="center" style="margin: 20px">

> See [docs](http://vuejs.github.io/rollup-plugin-vue) for installing, using and contributing.
<p align="center">

@@ -41,2 +39,15 @@ <a href="https://circleci.com/gh/vuejs/rollup-plugin-vue">

## Usage
```js
import vue from 'rollup-plugin-vue'
export default {
entry: 'main.js',
plugins: [
vue(/* options */)
]
}
```
## Security

@@ -43,0 +54,0 @@

@@ -1,262 +0,6 @@

import { createFilter } from 'rollup-pluginutils'
import * as compiler from 'vue-component-compiler'
import * as path from 'path'
import logger from 'debug'
import inline from './simple'
import delegate from './delegate'
const debug = logger('rollup-plugin-vue')
inline.delegate = delegate
function s(any) {
return JSON.stringify(any, null, 2)
}
function relative(p) {
if (p.startsWith(process.cwd())) {
p = p.replace(process.cwd(), '')
p = p.replace(/^[\\/]/, '')
}
return p
}
function inline(src) {
return `import target from '${src}'\nexport default target`
}
function inlineStyle(
{ id, index, code, map, modules },
descriptor,
{ isServer, isProduction, inject }
) {
let output = `const cssModules = ${modules ? s(modules) : '{}'}\n`
output +=
`export const style = ${s(code)}\n` +
`export const map = ${s(map)}\n` +
`const content = [[${index}, style, ${descriptor.attrs.media &&
s(descriptor.attrs.media)}, ${isProduction ? 'undefined' : 'map'} ]]\n`
if (inject) {
if (isServer) {
output +=
`import inject from 'vue-component-compiler/src/runtime/inject-style-server'\n` +
`cssModules.__inject__ = context => inject(${s(
id
)}, content, ${isProduction}, context)\n`
} else {
output +=
`import inject from 'vue-component-compiler/src/runtime/inject-style-client'\n` +
`cssModules.__inject__ = () => inject(${s(
id
)}, content, ${isProduction})\n`
}
}
output += `export default cssModules`
return output
}
function makeId(id, type, lang, index) {
return id + '?' + JSON.stringify({ type, index }) + '#.' + lang
}
export default function vue(opts = {}) {
debug('Yo! rolling vue!')
const filter = createFilter(opts.include, opts.exclude)
const cache = {}
delete opts.include
delete opts.exclude
const vueOptions = {
hasStyleInjectFn: true,
isServer: opts.server === true || process.env.VUE_ENV === 'server',
isProduction:
opts.production === true || process.env.NODE_ENV === 'production'
}
const cwd = process.cwd()
function parseId(id) {
const relative = path.relative(cwd, id)
if (/\.vue\?\{[^#]+\}#\./.test(id)) {
const start = id.lastIndexOf('?')
const end = id.lastIndexOf('#')
try {
const parsed = JSON.parse(id.substring(start + 1, end))
parsed.id = id.substring(0, start)
parsed.relative = relative
return parsed
} catch (e) {
console.error(e)
}
}
if (!filter(id) || id.endsWith('.vue')) return { sfc: true, id, relative }
return { ignore: true, id, relative }
}
return {
name: 'vue',
resolveId(request) {
const q = parseId(request)
if (q.ignore || q.sfc) return
debug(` > Resolve --> ${q.relative}`)
const descriptor = cache[q.id]
if (!descriptor) throw Error(`SFC (${q.id}) is not processed.`)
const part =
descriptor[q.type] ||
(q.type === 'style'
? descriptor.styles[q.index]
: descriptor.customBlocks[q.index])
if (part && part.src) {
return part.src
}
return request
},
load(request) {
const q = parseId(request)
if (q.ignore || q.sfc) return
debug(` > Load --> ${q.relative}`)
const id = q.id
const filename = relative(id)
const descriptor = cache[id]
if (!descriptor) throw Error(`SFC (${filename}) is not processed.`)
switch (q.type) {
case 'template':
if (!descriptor.template) return ''
if (descriptor.template.src) return
return {
code: descriptor.template.content,
map: descriptor.template.map
}
case 'script':
if (!descriptor.script)
return { code: 'export default {}\n', map: { mappings: '' } }
return {
code: descriptor.script.src
? inline(descriptor.script.src)
: descriptor.script.content,
map: descriptor.script.map
}
case 'style':
const style = descriptor.styles[q.index]
if (style.src) return
return {
code: style.content,
map: style.map
}
case 'custom':
const block = descriptor.customBlocks[q.index]
if (block.src) return
return block.content
}
},
async transform(source, request) {
const q = parseId(request)
if (q.ignore || q.dep) return
const filename = relative(q.id)
const scopeId = compiler.generateScopeId(
filename,
source,
vueOptions.isProduction
)
if (q.sfc) {
debug(`>> Transform: ${q.relative}`)
const descriptor = compiler.parse(source, filename)
cache[q.id] = descriptor
const code = compiler.assemble(
{
script: {
id:
descriptor.script &&
makeId(q.id, 'script', descriptor.script.lang || 'js'),
descriptor: descriptor.script
},
render: {
id:
descriptor.template &&
makeId(q.id, 'template', descriptor.template.lang || 'html'),
descriptor: descriptor.template
},
styles: descriptor.styles.map((style, index) => ({
id: makeId(q.id, 'style', style.lang || 'css', index),
descriptor: style
})),
customBlocks: vueOptions.isProduction
? []
: descriptor.customBlocks.map((block, index) => ({
id: makeId(q.id, 'custom', block.lang || block.type),
descriptor: block
}))
},
filename,
{ ...vueOptions, scopeId, moduleIdentifier: scopeId }
)
return { code, map: { mappings: '' } }
}
if (q.type === 'template') {
debug(` > Compile --> ${q.relative}`)
const output = compiler.compileTemplate(
{ code: source, descriptor: cache[q.id].template },
q.id,
{ ...vueOptions, scopeId }
)
if (!output.map) output.map = { mappings: '' }
return output
}
if (q.type === 'style') {
debug(` > Compile --> ${q.relative}`)
const style = cache[q.id].styles[q.index]
const result = await compiler.compileStyle(
{ code: source, descriptor: style },
q.id,
{ ...vueOptions, scopeId, async: true }
)
return {
code: inlineStyle(
{
id: path.relative(cwd, q.id),
index: q.index,
code: result.code,
modules: result.modules,
map: result.map
},
style,
{ ...vueOptions, inject: !opts.extract }
),
map: { mappings: '' }
}
}
}
}
}
export default inline
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