Skip to content

Replace bublé with babel #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ Libraries often wish to rename internal object properties or class members to sm

```json
{
"mangle": {
"regex": "^_"
}
"mangle": {
"regex": "^_"
}
}
```

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@
"dependencies": {
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "7.2.1",
"@babel/plugin-transform-for-of": "^7.2.0",
"@babel/plugin-syntax-jsx": "^7.2.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.2.0",
"@babel/preset-react": "^7.0.0",
"asyncro": "^3.0.0",
"autoprefixer": "^9.0.0",
"babel-plugin-transform-async-to-promises": "^0.8.3",
Expand All @@ -58,8 +61,7 @@
"pretty-bytes": "^5.1.0",
"rollup": "^0.67.3",
"rollup-plugin-alias": "^1.5.1",
"rollup-plugin-babel": "^4.1.0-0",
"rollup-plugin-buble": "^0.19.4",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-bundle-size": "^1.0.1",
"rollup-plugin-commonjs": "^9.0.0",
"rollup-plugin-es3": "^1.1.0",
Expand All @@ -79,7 +81,6 @@
"devDependencies": {
"@babel/cli": "^7.2.0",
"@babel/node": "^7.2.2",
"@babel/preset-env": "^7.2.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"cross-env": "^5.2.0",
Expand Down
81 changes: 50 additions & 31 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import cssnano from 'cssnano';
import { rollup, watch } from 'rollup';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import { loadPartialConfig, DEFAULT_EXTENSIONS } from '@babel/core';
import nodeResolve from 'rollup-plugin-node-resolve';
import buble from 'rollup-plugin-buble';
import { terser } from 'rollup-plugin-terser';
import alias from 'rollup-plugin-alias';
import postcss from 'rollup-plugin-postcss';
Expand Down Expand Up @@ -238,6 +238,54 @@ export default async function microbundle(inputOptions) {
);
}

function createBabelConfig(options) {
const partialConfig = loadPartialConfig();
const hasBabelConfigFile = partialConfig.hasFilesystemConfig();
Copy link
Author

@eliihen eliihen Dec 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this function does not respect the babel field in package.json. The only way I can see is adding a special case for detecting this field. Thoughts?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that loadPartialConfig is meant to be called per-file, because some files may have a .babelrc and some may not. That is what drove my comment above. It seems like rollup-plugin-babel should be exposing this as a feature, which is what we do for babel-loader so that people can do the same thing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@loganfsmyth: I see, thanks for the clarification. So if we go for that solution, that would mean this is impeded on rollup-plugin-babel exposing this feature.

I can make an issue over at rollup-plugin-babel to the best of my ability and see where that takes us.


// Allow project to configure babel with local config file
if (hasBabelConfigFile) {
return {
extensions: [...DEFAULT_EXTENSIONS, '.ts', '.tsx'],
};
}

// No babelrc exists, use default config
// TODO move this into a separate babel-preset-microbundle package
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we start by moving this into its own file?

return {
babelrc: false,
extensions: [...DEFAULT_EXTENSIONS, '.ts', '.tsx'],
presets: [
[require.resolve('@babel/preset-react'), { pragma: options.jsx }],
[
require.resolve('@babel/preset-env'),
{
loose: true,
exclude: [
// Disabling preset-env async/await support so we can use
// plugin-transform-async-to-promises
'transform-async-to-generator',
'transform-regenerator',
],
},
],
],
plugins: [
[
require.resolve('babel-plugin-transform-async-to-promises'),
{ inlineHelpers: true, externalHelpers: true },
],
[
require.resolve('@babel/plugin-proposal-class-properties'),
{ loose: true },
],
[
require.resolve('@babel/plugin-transform-for-of'),
{ assumeArray: true },
],
],
};
}

async function getConfigFromPkgJson(cwd) {
try {
const pkgJSON = await readFile(resolve(cwd, 'package.json'), 'utf8');
Expand Down Expand Up @@ -508,27 +556,7 @@ function createConfig(options, entry, format, writeMeta) {
},
}),
!useTypescript && flow({ all: true, pretty: true }),
// Only used for async await
babel({
// We mainly use bublé to transpile JS and only use babel to
// transpile down `async/await`. To prevent conflicts with user
// supplied configurations we set this option to false. Note
// that we never supported using custom babel configs anyway.
babelrc: false,
extensions: EXTENSIONS,
exclude: 'node_modules/**',
plugins: [
require.resolve('@babel/plugin-syntax-jsx'),
[
require.resolve('babel-plugin-transform-async-to-promises'),
{ inlineHelpers: true, externalHelpers: true },
],
[
require.resolve('@babel/plugin-proposal-class-properties'),
{ loose: true },
],
],
}),
babel(createBabelConfig(options)),
{
// Custom plugin that removes shebang from code because newer
Copy link
Contributor

@FezVrasta FezVrasta Dec 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this? If yes maybe it's worth to update the comment to explain why

// versions of bublé bundle their own private version of `acorn`
Expand All @@ -551,15 +579,6 @@ function createConfig(options, entry, format, writeMeta) {
};
},
},
buble({
exclude: 'node_modules/**',
jsx: options.jsx || 'h',
objectAssign: options.assign || 'Object.assign',
transforms: {
dangerousForOf: true,
dangerousTaggedTemplateString: true,
},
}),
// We should upstream this to rollup
// format==='cjs' && replace({
// [`module.exports = ${rollupName};`]: '',
Expand Down
Loading