From 5bf77aa849498015aff48cba0f98467108ec6155 Mon Sep 17 00:00:00 2001 From: Thomas Ghysels Date: Mon, 15 Aug 2016 22:02:30 +0200 Subject: [PATCH 1/3] Refactor babel dependency to buble --- config/build.js | 8 +- dist/rollup-plugin-vue.common.js | 494 +++++++++++++------------------ package.json | 5 +- 3 files changed, 221 insertions(+), 286 deletions(-) diff --git a/config/build.js b/config/build.js index aff39f1..a6a457c 100644 --- a/config/build.js +++ b/config/build.js @@ -1,6 +1,6 @@ "use strict"; -const babel = require('rollup-plugin-babel'); +const buble = require('rollup-plugin-buble'); const rollup = require('rollup'); const replace = require('rollup-plugin-replace'); const zlib = require('zlib'); @@ -21,8 +21,10 @@ fs.writeFileSync('src/index.js', main); rollup.rollup({ entry: 'src/index.js', plugins: [ - babel({ - presets: ['es2015-rollup'] + buble({ + transforms: { + dangerousForOf: true + } }) ] }) diff --git a/dist/rollup-plugin-vue.common.js b/dist/rollup-plugin-vue.common.js index 7291e93..f7e84f0 100644 --- a/dist/rollup-plugin-vue.common.js +++ b/dist/rollup-plugin-vue.common.js @@ -10,7 +10,8 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau var rollupPluginutils = require('rollup-pluginutils'); var deIndent = _interopDefault(require('de-indent')); var validateTemplate = _interopDefault(require('vue-template-validator')); -var path = _interopDefault(require('path')); +var path = require('path'); +var path__default = path['default']; var parse5 = _interopDefault(require('parse5')); var htmlMinifier = _interopDefault(require('html-minifier')); var chalk = _interopDefault(require('chalk')); @@ -19,52 +20,26 @@ var fs = _interopDefault(require('fs')); var postcss = _interopDefault(require('postcss')); var objectAssign = _interopDefault(require('object-assign')); -var babelHelpers = {}; - -babelHelpers.classCallCheck = function (instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } -}; - -babelHelpers.createClass = function () { - function defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps); - if (staticProps) defineProperties(Constructor, staticProps); - return Constructor; - }; -}(); - -babelHelpers; - var defaultBabelOptions = { presets: ['es2015-rollup'] -}; -var babelRcPath = path.resolve(process.cwd(), '.babelrc'); -var babelOptions = fs.existsSync(babelRcPath) ? getBabelRc() || defaultBabelOptions : defaultBabelOptions; +} +var babelRcPath = path__default.resolve(process.cwd(), '.babelrc') +var babelOptions = fs.existsSync(babelRcPath) + ? getBabelRc() || defaultBabelOptions + : defaultBabelOptions -function getBabelRc() { - var rc = null; +function getBabelRc () { + var rc = null try { - rc = JSON.parse(fs.readFileSync(babelRcPath, 'utf-8')); + rc = JSON.parse(fs.readFileSync(babelRcPath, 'utf-8')) } catch (e) { - throw new Error('[rollup-plugin-vue] Your .babelrc seems to be incorrectly formatted.'); + throw new Error('[rollup-plugin-vue] Your .babelrc seems to be incorrectly formatted.') } - return rc; + return rc } var options = { - autoprefixer: { remove: false }, + autoprefixer: {remove: false}, babel: babelOptions, htmlMinifier: { customAttrSurround: [[/@/, new RegExp('')], [/:/, new RegExp('')]], @@ -83,36 +58,36 @@ var options = { plugins: [], options: {} } -}; +} -function last(arr) { +function last (arr) { if (arr && arr.length) { - return arr[arr.length - 1]; + return arr[arr.length - 1] } - return arr; + return arr } var babel$1 = { - compile: function compile(code, _, id) { - var res = babel.transform(code, options.babel); + compile: function compile (code, _, id) { + var res = babel.transform(code, options.babel) return { code: res.code, map: res.map, type: 'script' - }; + } }, - inject: function inject(script, template) { - var matches = /(export default[^{]*\{)/g.exec(script); + inject: function inject (script, template) { + var matches = /(export default[^{]*\{)/g.exec(script) if (matches) { - return script.split(matches[1]).join(matches[1] + ' template: ' + JSON.stringify(template) + ','); + return script.split(matches[1]).join(((matches[1]) + " template: " + (JSON.stringify(template)) + ",")) } - console.log('Lang: babel\n Script: ' + last(script.split('export default'))); - throw new Error('[rollup-vue-plugin] failed to inject template in script.\n Create an issue at https://github.com/znck/rollup-plugin-vue/issues. Include above text.'); + console.log('Lang: babel\n Script: ' + last(script.split('export default'))) + throw new Error('[rollup-vue-plugin] failed to inject template in script.\n Create an issue at https://github.com/znck/rollup-plugin-vue/issues. Include above text.') } -}; +} -var compilers = { babel: babel$1 }; +var compilers = {babel: babel$1} -require('es6-promise').polyfill(); +require('es6-promise').polyfill() /** * Ensure there's only one template node. @@ -120,14 +95,14 @@ require('es6-promise').polyfill(); * @param {DocumentFragment} fragment * @return {Boolean} */ -function validateNodeCount(fragment) { - var count = 0; +function validateNodeCount (fragment) { + var count = 0 fragment.childNodes.forEach(function (node) { if (node.nodeName === 'template') { - count++; + count++ } - }); - return count <= 1; + }) + return count <= 1 } /** @@ -136,9 +111,9 @@ function validateNodeCount(fragment) { * @param {string} content * @returns {DocumentFragment} */ -function parseContent(content) { +function parseContent (content) { // noinspection JSValidateTypes - return parse5.parseFragment(content, { locationInfo: true }); + return parse5.parseFragment(content, {locationInfo: true}) } /** @@ -147,13 +122,13 @@ function parseContent(content) { * @param {Node} node * @return {String|undefined} */ -function checkLang(node) { +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 } } } @@ -165,245 +140,204 @@ function checkLang(node) { * @param content * @returns {string} */ -function padContent(content) { - return content.split(/\r?\n/g).map(function () { - return ''; - }).join('\n'); +function padContent (content) { + return content + .split(/\r?\n/g) + .map(function () { return '' }) + .join('\n') } -var Compiler = function () { - function Compiler() { - var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - babelHelpers.classCallCheck(this, Compiler); - - this.options = options; - } - - babelHelpers.createClass(Compiler, [{ - key: 'compile', - value: function compile(content, filePath) { - var _this = this; - - // 1. Parse the file into an HTML tree - var fragment = parseContent(content); +var Compiler = function Compiler (options) { + if ( options === void 0 ) options = {}; - // 2. Check number of nodes. - if (!validateNodeCount(fragment)) { - throw new Error('Only one script tag and one template tag allowed per *.vue file.'); - } + this.options = options +}; +Compiler.prototype.compile = function compile (content, filePath) { + var this$1 = this; - // 3. Walk through the top level nodes and check for their - // types & languages. If there are pre-processing needed, - // then push it into a jobs list. - /** - * @type {{script: Node, template: Node, style: Node}} - */ - var components = {}; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + // 1. Parse the file into an HTML tree + var fragment = parseContent(content) - try { - for (var _iterator = fragment.childNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var node = _step.value; - - components[node.nodeName] = node; - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } + // 2. Check number of nodes. + if (!validateNodeCount(fragment)) { + throw new Error('Only one script tag and one template tag allowed per *.vue file.') + } - var promise = new Promise(function (resolve) { - resolve(); - }); - return promise.then(function () { - return _this.processTemplate(components.template, filePath, content); - }).then(function (template) { + // 3. Walk through the top level nodes and check for their + // types & languages. If there are pre-processing needed, + // then push it into a jobs list. + /** + * @type {{script: Node, template: Node, style: Node}} + */ + var components = {} + for (var i = 0, list = fragment.childNodes; i < list.length; i += 1) { + var node = list[i]; + + components[node.nodeName] = node + } + var promise = new Promise(function (resolve) {resolve()}) + return promise + .then(function () { + return this$1.processTemplate(components.template, filePath, content) + }) + .then(function (template) { if (components.style) { - return _this.processStyle(components.style, filePath, content).then(function (style) { - return { template: template.code, style: style.code }; - }); + return this$1.processStyle(components.style, filePath, content) + .then(function (style) { + return {template: template.code, style: style.code} + }) } - return { template: template.code, style: '' }; - }).then(function (compiled) { - return _this.processScript(components.script, filePath, content, compiled); - }); - } - - /** - * Check src import for a node, relative to the filePath if - * available. Using readFileSync for now since this is a - * rare use case. - * - * @param {Node} node - * @param {String} filePath - * @return {String} - */ - - }, { - key: 'checkSrc', - value: function checkSrc(node, filePath) { - // TODO: Up next. ${node}, ${filePath} - return null; - } - - /** - * Compile template: DeIndent and minify html. - * @param {Node} node - * @param {string} filePath - * @param {string} content - */ - - }, { - key: 'processTemplate', - value: function processTemplate(node, filePath, content) { - var _this2 = this; - - var template = deIndent(this.checkSrc(node, filePath) || parse5.serialize(node.content)); - var lang = checkLang(node); - if (!lang) { - var warnings = validateTemplate(node.content, content); - if (warnings) { - (function () { - var relativePath = path.relative(process.cwd(), filePath); - warnings.forEach(function (msg) { - console.warn(chalk.red('\n Error in ' + relativePath + ':\n ' + msg)); - }); - })(); - } - } - return this.compileAsPromise('template', template, lang, filePath).then(function (res) { - res.code = htmlMinifier.minify(res.code, _this2.options.htmlMinifier); - return res; - }); - } - /** - * @param {Node} node - * @param {string} filePath - * @param {string} content - * @param {*} compiled - */ + return {template: template.code, style: ''} + }) + .then(function (compiled) { + return this$1.processScript(components.script, filePath, content, compiled) + }) +}; - }, { - key: 'processScript', - value: function processScript(node, filePath, content, compiled) { - var lang = checkLang(node) || 'babel'; - var script = this.checkSrc(node, filePath); - var template = compiled.template; +/** + * Check src import for a node, relative to the filePath if + * available. Using readFileSync for now since this is a + * rare use case. + * + * @param {Node} node + * @param {String} filePath + * @return {String} + */ +Compiler.prototype.checkSrc = function checkSrc (node, filePath) { + // TODO: Up next. ${node}, ${filePath} + return null +}; - if (!script) { - script = parse5.serialize(node); - // pad the script to ensure correct line number for syntax errors - var location = content.indexOf(script); - var before = padContent(content.slice(0, location)); - script = before + script; - } - script = this.injectTemplate(script, template, lang); - script = deIndent(script); - return this.compileAsPromise('script', script, lang, filePath).then(function (res) { - return { code: res.code }; - }); +/** + * Compile template: DeIndent and minify html. + * @param {Node} node + * @param {string} filePath + * @param {string} content + */ +Compiler.prototype.processTemplate = function processTemplate (node, filePath, content) { + var this$1 = this; + + var template = deIndent(this.checkSrc(node, filePath) || parse5.serialize(node.content)) + var lang = checkLang(node) + if (!lang) { + var warnings = validateTemplate(node.content, content) + if (warnings) { + var relativePath = path.relative(process.cwd(), filePath) + warnings.forEach(function (msg) { + console.warn(chalk.red(("\n Error in " + relativePath + ":\n " + msg))) + }) } - /** - * @param {Node} node - * @param {string} filePath - * @param {string} content - */ + } + return this.compileAsPromise('template', template, lang, filePath) + .then(function (res) { + res.code = htmlMinifier.minify(res.code, this$1.options.htmlMinifier) + return res + }) +}; +/** + * @param {Node} node + * @param {string} filePath + * @param {string} content + * @param {*} compiled + */ +Compiler.prototype.processScript = function processScript (node, filePath, content, compiled) { + var lang = checkLang(node) || 'babel' + var script = this.checkSrc(node, filePath) + var template = compiled.template; + if (!script) { + script = parse5.serialize(node) + // pad the script to ensure correct line number for syntax errors + var location = content.indexOf(script) + var before = padContent(content.slice(0, location)) + script = before + script + } + script = this.injectTemplate(script, template, lang) + script = deIndent(script) + return this.compileAsPromise('script', script, lang, filePath) + .then(function (res) { + return {code: res.code} + }) +}; +/** + * @param {Node} node + * @param {string} filePath + * @param {string} content + */ +Compiler.prototype.processStyle = function processStyle (node, filePath, content) { + var this$1 = this; + + var lang = checkLang(node) || 'css' + var style = this.checkSrc(node, filePath) + var injectFnName = '__$styleInject' + if (!style) { + style = parse5.serialize(node) + var location = content.indexOf(style) + var before = padContent(content.slice(0, location)) + style = before + style + } + var options = this.options.postcss + options.from = filePath + options.to = filePath + return this.compileAsPromise('style', style, lang, filePath) + .then(function (res) { + return postcss(this$1.options.postcss.plugins || []) + .process(res.code, options) + .then(function (res) { + var code = "export " + injectFnName + "(" + (JSON.stringify(res.css)) + ");" + return {code: code, type: 'style'} + }) + }) +}; - }, { - key: 'processStyle', - value: function processStyle(node, filePath, content) { - var _this3 = this; +Compiler.prototype.compileAsPromise = function compileAsPromise (type, code, lang, filePath) { + var this$1 = this; - var lang = checkLang(node) || 'css'; - var style = this.checkSrc(node, filePath); - var injectFnName = '__$styleInject'; - if (!style) { - style = parse5.serialize(node); - var location = content.indexOf(style); - var before = padContent(content.slice(0, location)); - style = before + style; + var compiler = compilers[lang] + if (compiler) { + return new Promise(function (resolve, reject) { + try { + var compiled = compiler.compile(code, this$1, filePath) + resolve(compiled) + } catch (e) { + reject(e) } - var options = this.options.postcss; - options.from = filePath; - options.to = filePath; - return this.compileAsPromise('style', style, lang, filePath).then(function (res) { - return postcss(_this3.options.postcss.plugins || []).process(res.code, options).then(function (res) { - var code = 'export ' + injectFnName + '(' + JSON.stringify(res.css) + ');'; - return { code: code, type: 'style' }; - }); - }); - } - }, { - key: 'compileAsPromise', - value: function compileAsPromise(type, code, lang, filePath) { - var _this4 = this; + }) + } + return Promise.resolve({code: code, type: type}) +}; - var compiler = compilers[lang]; - if (compiler) { - return new Promise(function (resolve, reject) { - try { - var compiled = compiler.compile(code, _this4, filePath); - resolve(compiled); - } catch (e) { - reject(e); - } - }); - } - return Promise.resolve({ code: code, type: type }); - } - }, { - key: 'injectTemplate', - value: function injectTemplate(script, template, lang) { - var compiler = compilers[lang]; - if (compiler) { - return compiler.inject(script, template); - } - throw new Error('rollup-plugin-vue cannot inject template in ' + lang + ' script.'); - } - }]); - return Compiler; -}(); +Compiler.prototype.injectTemplate = function injectTemplate (script, template, lang) { + var compiler = compilers[lang] + if (compiler) { + return compiler.inject(script, template) + } + throw new Error(("rollup-plugin-vue cannot inject template in " + lang + " script.")) +}; -function plugin() { - var options$$ = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; +function plugin (options$$) { + if ( options$$ === void 0 ) options$$ = {}; - options$$ = objectAssign({}, options, options$$, { extensions: ['.vue'] }); - var filter = rollupPluginutils.createFilter(options$$.include, options$$.exclude); - var extensions = options$$.extensions; - delete options$$.extensions; - delete options$$.include; - delete options$$.exclude; + options$$ = objectAssign({}, options, options$$, {extensions: ['.vue'] }) + var filter = rollupPluginutils.createFilter(options$$.include, options$$.exclude) + var extensions = options$$.extensions + delete options$$.extensions + delete options$$.include + delete options$$.exclude - var compiler = new Compiler(options$$); + var compiler = new Compiler(options$$) return { - transform: function transform(code, id) { - if (!filter(id)) { - return null; - } - if (extensions.indexOf(path.extname(id)) === -1) { - return null; - } + transform: function transform (code, id) { + if (!filter(id)) { return null } + if (extensions.indexOf(path__default.extname(id)) === -1) { return null } return new Promise(function (resolve) { - compiler.compile(code, id).then(function (compiled) { - return resolve(compiled); - }); - }); + compiler + .compile(code, id) + .then(function (compiled) { return resolve(compiled); }) + }) } - }; + } } module.exports = plugin; \ No newline at end of file diff --git a/package.json b/package.json index fb788e7..b23e6bb 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,7 @@ "homepage": "https://github.com/znck/rollup-plugin-vue#readme", "dependencies": { "autoprefixer": "latest", - "babel-core": "latest", - "babel-preset-es2015-rollup": "^1.1.1", + "buble": "latest", "chalk": "latest", "cssnano": "latest", "de-indent": "latest", @@ -39,7 +38,7 @@ "postcss": "latest", "postcss-selector-parser": "latest", "promise": "latest", - "rollup-plugin-babel": "latest", + "rollup-plugin-buble": "latest", "rollup-pluginutils": "latest", "vue-template-validator": "latest" }, From a0e313b95dbf914f3e94b8ba917995e39c628e2e Mon Sep 17 00:00:00 2001 From: Thomas Ghysels Date: Mon, 15 Aug 2016 22:42:00 +0200 Subject: [PATCH 2/3] Refactor compiler to use buble --- dist/rollup-plugin-vue.common.js | 33 ++++++++++++++-------------- src/compiler.js | 2 +- src/compilers/.babelrc | 3 --- src/compilers/{babel.js => buble.js} | 6 ++--- src/compilers/index.js | 4 ++-- src/options.js | 21 +++++++++--------- 6 files changed, 34 insertions(+), 35 deletions(-) delete mode 100644 src/compilers/.babelrc rename src/compilers/{babel.js => buble.js} (81%) diff --git a/dist/rollup-plugin-vue.common.js b/dist/rollup-plugin-vue.common.js index f7e84f0..f5692e2 100644 --- a/dist/rollup-plugin-vue.common.js +++ b/dist/rollup-plugin-vue.common.js @@ -15,32 +15,33 @@ var path__default = path['default']; var parse5 = _interopDefault(require('parse5')); var htmlMinifier = _interopDefault(require('html-minifier')); var chalk = _interopDefault(require('chalk')); -var babel = _interopDefault(require('babel-core')); +var buble = _interopDefault(require('buble')); var fs = _interopDefault(require('fs')); var postcss = _interopDefault(require('postcss')); var objectAssign = _interopDefault(require('object-assign')); -var defaultBabelOptions = { - presets: ['es2015-rollup'] +var defaultBubleOptions = { + transforms: { + modules: false + } } -var babelRcPath = path__default.resolve(process.cwd(), '.babelrc') -var babelOptions = fs.existsSync(babelRcPath) - ? getBabelRc() || defaultBabelOptions - : defaultBabelOptions +// Not sure if 'buble.config.js' is the supposed filename +var bubleOptionsPath = path__default.resolve(process.cwd(), 'buble.config.js') +var bubleOptions = fs.existsSync(bubleOptionsPath) && getBubleConfig() || defaultBubleOptions -function getBabelRc () { +function getBubleConfig () { var rc = null try { - rc = JSON.parse(fs.readFileSync(babelRcPath, 'utf-8')) + rc = JSON.parse(fs.readFileSync(bubleOptionsPath, 'utf-8')) } catch (e) { - throw new Error('[rollup-plugin-vue] Your .babelrc seems to be incorrectly formatted.') + throw new Error('[rollup-plugin-vue] Your buble.config.js seems to be incorrectly formatted.') } return rc } var options = { autoprefixer: {remove: false}, - babel: babelOptions, + buble: bubleOptions, htmlMinifier: { customAttrSurround: [[/@/, new RegExp('')], [/:/, new RegExp('')]], collapseWhitespace: true, @@ -66,9 +67,9 @@ function last (arr) { } return arr } -var babel$1 = { +var buble$1 = { compile: function compile (code, _, id) { - var res = babel.transform(code, options.babel) + var res = buble.transform(code, options.buble) return { code: res.code, map: res.map, @@ -80,12 +81,12 @@ var babel$1 = { if (matches) { return script.split(matches[1]).join(((matches[1]) + " template: " + (JSON.stringify(template)) + ",")) } - console.log('Lang: babel\n Script: ' + last(script.split('export default'))) + console.log('Lang: buble\n Script: ' + last(script.split('export default'))) throw new Error('[rollup-vue-plugin] failed to inject template in script.\n Create an issue at https://github.com/znck/rollup-plugin-vue/issues. Include above text.') } } -var compilers = {babel: babel$1} +var compilers = {buble: buble$1} require('es6-promise').polyfill() @@ -241,7 +242,7 @@ Compiler.prototype.processTemplate = function processTemplate (node, filePath, c * @param {*} compiled */ Compiler.prototype.processScript = function processScript (node, filePath, content, compiled) { - var lang = checkLang(node) || 'babel' + var lang = checkLang(node) || 'buble' var script = this.checkSrc(node, filePath) var template = compiled.template; if (!script) { diff --git a/src/compiler.js b/src/compiler.js index 5bb622f..d49b22f 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -154,7 +154,7 @@ export default class Compiler { * @param {*} compiled */ processScript (node, filePath, content, compiled) { - const lang = checkLang(node) || 'babel' + const lang = checkLang(node) || 'buble' let script = this.checkSrc(node, filePath) let {template} = compiled if (!script) { diff --git a/src/compilers/.babelrc b/src/compilers/.babelrc deleted file mode 100644 index 13b7688..0000000 --- a/src/compilers/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["es2015-rollup"] -} \ No newline at end of file diff --git a/src/compilers/babel.js b/src/compilers/buble.js similarity index 81% rename from src/compilers/babel.js rename to src/compilers/buble.js index bbbbbe1..3145823 100644 --- a/src/compilers/babel.js +++ b/src/compilers/buble.js @@ -1,4 +1,4 @@ -import babel from 'babel-core' +import buble from 'buble' import options from '../options' function last (arr) { if (arr && arr.length) { @@ -8,7 +8,7 @@ function last (arr) { } export default { compile (code, _, id) { - const res = babel.transform(code, options.babel) + const res = buble.transform(code, options.buble) return { code: res.code, map: res.map, @@ -20,7 +20,7 @@ export default { if (matches) { return script.split(matches[1]).join(`${matches[1]} template: ${JSON.stringify(template)},`) } - console.log('Lang: babel\n Script: ' + last(script.split('export default'))) + console.log('Lang: buble\n Script: ' + last(script.split('export default'))) throw new Error('[rollup-vue-plugin] failed to inject template in script.\n Create an issue at https://github.com/znck/rollup-plugin-vue/issues. Include above text.') } } diff --git a/src/compilers/index.js b/src/compilers/index.js index 85a0282..5361830 100644 --- a/src/compilers/index.js +++ b/src/compilers/index.js @@ -1,2 +1,2 @@ -import babel from './babel' -export default {babel} +import buble from './buble' +export default {buble} diff --git a/src/options.js b/src/options.js index 7ed6b3b..8542d56 100644 --- a/src/options.js +++ b/src/options.js @@ -1,27 +1,28 @@ import fs from 'fs' import path from 'path' -let defaultBabelOptions = { - presets: ['es2015-rollup'] +let defaultBubleOptions = { + transforms: { + modules: false + } } -let babelRcPath = path.resolve(process.cwd(), '.babelrc') -let babelOptions = fs.existsSync(babelRcPath) - ? getBabelRc() || defaultBabelOptions - : defaultBabelOptions +// Not sure if 'buble.config.js' is the supposed filename +let bubleOptionsPath = path.resolve(process.cwd(), 'buble.config.js') +let bubleOptions = fs.existsSync(bubleOptionsPath) && getBubleConfig() || defaultBubleOptions -function getBabelRc () { +function getBubleConfig () { let rc = null try { - rc = JSON.parse(fs.readFileSync(babelRcPath, 'utf-8')) + rc = JSON.parse(fs.readFileSync(bubleOptionsPath, 'utf-8')) } catch (e) { - throw new Error('[rollup-plugin-vue] Your .babelrc seems to be incorrectly formatted.') + throw new Error('[rollup-plugin-vue] Your buble.config.js seems to be incorrectly formatted.') } return rc } export default { autoprefixer: {remove: false}, - babel: babelOptions, + buble: bubleOptions, htmlMinifier: { customAttrSurround: [[/@/, new RegExp('')], [/:/, new RegExp('')]], collapseWhitespace: true, From f75e2cc20b7766e402003e881e8ffb7e75cf25a9 Mon Sep 17 00:00:00 2001 From: Thomas Ghysels Date: Mon, 15 Aug 2016 22:46:42 +0200 Subject: [PATCH 3/3] Fix import bug --- dist/rollup-plugin-vue.common.js | 2 +- src/compiler.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/rollup-plugin-vue.common.js b/dist/rollup-plugin-vue.common.js index f5692e2..434ef38 100644 --- a/dist/rollup-plugin-vue.common.js +++ b/dist/rollup-plugin-vue.common.js @@ -11,7 +11,7 @@ var rollupPluginutils = require('rollup-pluginutils'); var deIndent = _interopDefault(require('de-indent')); var validateTemplate = _interopDefault(require('vue-template-validator')); var path = require('path'); -var path__default = path['default']; +var path__default = _interopDefault(path); var parse5 = _interopDefault(require('parse5')); var htmlMinifier = _interopDefault(require('html-minifier')); var chalk = _interopDefault(require('chalk')); diff --git a/src/compiler.js b/src/compiler.js index d49b22f..95ed55b 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -1,6 +1,6 @@ import deIndent from 'de-indent' import validateTemplate from 'vue-template-validator' -import * as path from 'path' +import {relative} from 'path' import parse5 from 'parse5' import htmlMinifier from 'html-minifier' import chalk from 'chalk' @@ -135,7 +135,7 @@ export default class Compiler { if (!lang) { const warnings = validateTemplate(node.content, content) if (warnings) { - const relativePath = path.relative(process.cwd(), filePath) + const relativePath = relative(process.cwd(), filePath) warnings.forEach(function (msg) { console.warn(chalk.red(`\n Error in ${relativePath}:\n ${msg}`)) })