Skip to content

Commit 90fab42

Browse files
committed
Replace buble with babel
1 parent 1f23940 commit 90fab42

File tree

2 files changed

+45
-36
lines changed

2 files changed

+45
-36
lines changed

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@
4444
"dependencies": {
4545
"@babel/core": "^7.1.6",
4646
"@babel/plugin-proposal-class-properties": "7.1.0",
47-
"@babel/plugin-syntax-jsx": "^7.0.0",
4847
"@babel/polyfill": "^7.0.0",
48+
"@babel/preset-env": "^7.2.0",
49+
"@babel/preset-react": "^7.0.0",
4950
"asyncro": "^3.0.0",
5051
"autoprefixer": "^9.0.0",
5152
"babel-plugin-transform-async-to-promises": "^0.8.1",
@@ -57,8 +58,7 @@
5758
"gzip-size": "^5.0.0",
5859
"pretty-bytes": "^5.1.0",
5960
"rollup": "^0.67.3",
60-
"rollup-plugin-babel": "^4.1.0-0",
61-
"rollup-plugin-buble": "^0.19.4",
61+
"rollup-plugin-babel": "^4.0.3",
6262
"rollup-plugin-bundle-size": "^1.0.1",
6363
"rollup-plugin-commonjs": "^9.0.0",
6464
"rollup-plugin-es3": "^1.1.0",
@@ -79,7 +79,6 @@
7979
"devDependencies": {
8080
"@babel/cli": "^7.1.5",
8181
"@babel/node": "^7.0.0",
82-
"@babel/preset-env": "^7.1.6",
8382
"babel-core": "^7.0.0-bridge.0",
8483
"babel-jest": "^23.6.0",
8584
"directory-tree": "^2.1.0",

src/index.js

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { rollup, watch } from 'rollup';
99
import commonjs from 'rollup-plugin-commonjs';
1010
import babel from 'rollup-plugin-babel';
1111
import nodeResolve from 'rollup-plugin-node-resolve';
12-
import buble from 'rollup-plugin-buble';
1312
import { terser } from 'rollup-plugin-terser';
1413
import postcss from 'rollup-plugin-postcss';
1514
import alias from 'rollup-plugin-strict-alias';
@@ -152,7 +151,7 @@ export default async function microbundle(options) {
152151
for (let i = 0; i < entries.length; i++) {
153152
for (let j = 0; j < formats.length; j++) {
154153
steps.push(
155-
createConfig(options, entries[i], formats[j], i === 0 && j === 0),
154+
await createConfig(options, entries[i], formats[j], i === 0 && j === 0),
156155
);
157156
}
158157
}
@@ -226,7 +225,7 @@ export default async function microbundle(options) {
226225
);
227226
}
228227

229-
function createConfig(options, entry, format, writeMeta) {
228+
async function createConfig(options, entry, format, writeMeta) {
230229
let { pkg } = options;
231230

232231
let external = ['dns', 'fs', 'path', 'url'].concat(
@@ -377,26 +376,46 @@ function createConfig(options, entry, format, writeMeta) {
377376
},
378377
}),
379378
!useTypescript && flow({ all: true, pretty: true }),
380-
// Only used for async await
381-
babel({
382-
// We mainly use bublé to transpile JS and only use babel to
383-
// transpile down `async/await`. To prevent conflicts with user
384-
// supplied configurations we set this option to false. Note
385-
// that we never supported using custom babel configs anyway.
386-
babelrc: false,
387-
exclude: 'node_modules/**',
388-
plugins: [
389-
require.resolve('@babel/plugin-syntax-jsx'),
390-
[
391-
require.resolve('babel-plugin-transform-async-to-promises'),
392-
{ inlineHelpers: true, externalHelpers: true },
393-
],
394-
[
395-
require.resolve('@babel/plugin-proposal-class-properties'),
396-
{ loose: true },
397-
],
398-
],
399-
}),
379+
babel(
380+
(await isFile('.babelrc')) || (await isFile('.babelrc.js'))
381+
? {
382+
// Babelrc exists, allow project to configure babel
383+
exclude: 'node_modules/**',
384+
}
385+
: {
386+
// No babelrc exists, use default config
387+
exclude: 'node_modules/**',
388+
presets: [
389+
['@babel/preset-react', { pragma: options.jsx }],
390+
[
391+
'@babel/preset-env',
392+
{
393+
loose: true,
394+
exclude: [
395+
// Disabling preset-env async/await support so we can use
396+
// plugin-transform-async-to-promises
397+
'transform-async-to-generator',
398+
'transform-regenerator',
399+
],
400+
},
401+
],
402+
],
403+
plugins: [
404+
[
405+
require.resolve(
406+
'babel-plugin-transform-async-to-promises',
407+
),
408+
{ inlineHelpers: true, externalHelpers: true },
409+
],
410+
[
411+
require.resolve(
412+
'@babel/plugin-proposal-class-properties',
413+
),
414+
{ loose: true },
415+
],
416+
],
417+
},
418+
),
400419
{
401420
// Custom plugin that removes shebang from code because newer
402421
// versions of bublé bundle their own private version of `acorn`
@@ -419,15 +438,6 @@ function createConfig(options, entry, format, writeMeta) {
419438
};
420439
},
421440
},
422-
buble({
423-
exclude: 'node_modules/**',
424-
jsx: options.jsx || 'h',
425-
objectAssign: options.assign || 'Object.assign',
426-
transforms: {
427-
dangerousForOf: true,
428-
dangerousTaggedTemplateString: true,
429-
},
430-
}),
431441
// We should upstream this to rollup
432442
// format==='cjs' && replace({
433443
// [`module.exports = ${rollupName};`]: '',

0 commit comments

Comments
 (0)