-
Notifications
You must be signed in to change notification settings - Fork 361
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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5951baa
Replace buble with babel
eliihen 9e85232
Fix async not transpiled with TS
marvinhagemeister 7224ad2
Merge pull request #1 from FezVrasta/buble-to-babel
48949b9
Merge remote-tracking branch 'origin/master' into buble-to-babel
ForsakenHarmony e1b44ef
Fix snapshots + babel plugin update
ForsakenHarmony 5513253
Merge branch 'master' into buble-to-babel
developit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -238,6 +238,54 @@ export default async function microbundle(inputOptions) { | |
); | ||
} | ||
|
||
function createBabelConfig(options) { | ||
const partialConfig = loadPartialConfig(); | ||
const hasBabelConfigFile = partialConfig.hasFilesystemConfig(); | ||
|
||
// 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'], | ||
eliihen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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'); | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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` | ||
|
@@ -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, | ||
eliihen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dangerousTaggedTemplateString: true, | ||
}, | ||
}), | ||
// We should upstream this to rollup | ||
// format==='cjs' && replace({ | ||
// [`module.exports = ${rollupName};`]: '', | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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 likerollup-plugin-babel
should be exposing this as a feature, which is what we do forbabel-loader
so that people can do the same thing.There was a problem hiding this comment.
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.