Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit a0e313b

Browse files
committed
Refactor compiler to use buble
1 parent 5bf77aa commit a0e313b

File tree

6 files changed

+34
-35
lines changed

6 files changed

+34
-35
lines changed

dist/rollup-plugin-vue.common.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,33 @@ var path__default = path['default'];
1515
var parse5 = _interopDefault(require('parse5'));
1616
var htmlMinifier = _interopDefault(require('html-minifier'));
1717
var chalk = _interopDefault(require('chalk'));
18-
var babel = _interopDefault(require('babel-core'));
18+
var buble = _interopDefault(require('buble'));
1919
var fs = _interopDefault(require('fs'));
2020
var postcss = _interopDefault(require('postcss'));
2121
var objectAssign = _interopDefault(require('object-assign'));
2222

23-
var defaultBabelOptions = {
24-
presets: ['es2015-rollup']
23+
var defaultBubleOptions = {
24+
transforms: {
25+
modules: false
26+
}
2527
}
26-
var babelRcPath = path__default.resolve(process.cwd(), '.babelrc')
27-
var babelOptions = fs.existsSync(babelRcPath)
28-
? getBabelRc() || defaultBabelOptions
29-
: defaultBabelOptions
28+
// Not sure if 'buble.config.js' is the supposed filename
29+
var bubleOptionsPath = path__default.resolve(process.cwd(), 'buble.config.js')
30+
var bubleOptions = fs.existsSync(bubleOptionsPath) && getBubleConfig() || defaultBubleOptions
3031

31-
function getBabelRc () {
32+
function getBubleConfig () {
3233
var rc = null
3334
try {
34-
rc = JSON.parse(fs.readFileSync(babelRcPath, 'utf-8'))
35+
rc = JSON.parse(fs.readFileSync(bubleOptionsPath, 'utf-8'))
3536
} catch (e) {
36-
throw new Error('[rollup-plugin-vue] Your .babelrc seems to be incorrectly formatted.')
37+
throw new Error('[rollup-plugin-vue] Your buble.config.js seems to be incorrectly formatted.')
3738
}
3839
return rc
3940
}
4041

4142
var options = {
4243
autoprefixer: {remove: false},
43-
babel: babelOptions,
44+
buble: bubleOptions,
4445
htmlMinifier: {
4546
customAttrSurround: [[/@/, new RegExp('')], [/:/, new RegExp('')]],
4647
collapseWhitespace: true,
@@ -66,9 +67,9 @@ function last (arr) {
6667
}
6768
return arr
6869
}
69-
var babel$1 = {
70+
var buble$1 = {
7071
compile: function compile (code, _, id) {
71-
var res = babel.transform(code, options.babel)
72+
var res = buble.transform(code, options.buble)
7273
return {
7374
code: res.code,
7475
map: res.map,
@@ -80,12 +81,12 @@ var babel$1 = {
8081
if (matches) {
8182
return script.split(matches[1]).join(((matches[1]) + " template: " + (JSON.stringify(template)) + ","))
8283
}
83-
console.log('Lang: babel\n Script: ' + last(script.split('export default')))
84+
console.log('Lang: buble\n Script: ' + last(script.split('export default')))
8485
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.')
8586
}
8687
}
8788

88-
var compilers = {babel: babel$1}
89+
var compilers = {buble: buble$1}
8990

9091
require('es6-promise').polyfill()
9192

@@ -241,7 +242,7 @@ Compiler.prototype.processTemplate = function processTemplate (node, filePath, c
241242
* @param {*} compiled
242243
*/
243244
Compiler.prototype.processScript = function processScript (node, filePath, content, compiled) {
244-
var lang = checkLang(node) || 'babel'
245+
var lang = checkLang(node) || 'buble'
245246
var script = this.checkSrc(node, filePath)
246247
var template = compiled.template;
247248
if (!script) {

src/compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export default class Compiler {
154154
* @param {*} compiled
155155
*/
156156
processScript (node, filePath, content, compiled) {
157-
const lang = checkLang(node) || 'babel'
157+
const lang = checkLang(node) || 'buble'
158158
let script = this.checkSrc(node, filePath)
159159
let {template} = compiled
160160
if (!script) {

src/compilers/.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/compilers/babel.js renamed to src/compilers/buble.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import babel from 'babel-core'
1+
import buble from 'buble'
22
import options from '../options'
33
function last (arr) {
44
if (arr && arr.length) {
@@ -8,7 +8,7 @@ function last (arr) {
88
}
99
export default {
1010
compile (code, _, id) {
11-
const res = babel.transform(code, options.babel)
11+
const res = buble.transform(code, options.buble)
1212
return {
1313
code: res.code,
1414
map: res.map,
@@ -20,7 +20,7 @@ export default {
2020
if (matches) {
2121
return script.split(matches[1]).join(`${matches[1]} template: ${JSON.stringify(template)},`)
2222
}
23-
console.log('Lang: babel\n Script: ' + last(script.split('export default')))
23+
console.log('Lang: buble\n Script: ' + last(script.split('export default')))
2424
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.')
2525
}
2626
}

src/compilers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import babel from './babel'
2-
export default {babel}
1+
import buble from './buble'
2+
export default {buble}

src/options.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
import fs from 'fs'
22
import path from 'path'
33

4-
let defaultBabelOptions = {
5-
presets: ['es2015-rollup']
4+
let defaultBubleOptions = {
5+
transforms: {
6+
modules: false
7+
}
68
}
7-
let babelRcPath = path.resolve(process.cwd(), '.babelrc')
8-
let babelOptions = fs.existsSync(babelRcPath)
9-
? getBabelRc() || defaultBabelOptions
10-
: defaultBabelOptions
9+
// Not sure if 'buble.config.js' is the supposed filename
10+
let bubleOptionsPath = path.resolve(process.cwd(), 'buble.config.js')
11+
let bubleOptions = fs.existsSync(bubleOptionsPath) && getBubleConfig() || defaultBubleOptions
1112

12-
function getBabelRc () {
13+
function getBubleConfig () {
1314
let rc = null
1415
try {
15-
rc = JSON.parse(fs.readFileSync(babelRcPath, 'utf-8'))
16+
rc = JSON.parse(fs.readFileSync(bubleOptionsPath, 'utf-8'))
1617
} catch (e) {
17-
throw new Error('[rollup-plugin-vue] Your .babelrc seems to be incorrectly formatted.')
18+
throw new Error('[rollup-plugin-vue] Your buble.config.js seems to be incorrectly formatted.')
1819
}
1920
return rc
2021
}
2122

2223
export default {
2324
autoprefixer: {remove: false},
24-
babel: babelOptions,
25+
buble: bubleOptions,
2526
htmlMinifier: {
2627
customAttrSurround: [[/@/, new RegExp('')], [/:/, new RegExp('')]],
2728
collapseWhitespace: true,

0 commit comments

Comments
 (0)