I'm probably missing something obvious, but I searched a lot before posting this and was, honestly, shocked to not find a solution. I want to bundle my ES6 files into a single module but, since ES6 is supported by the browser I use for testing, don't actually want to transpile anything. I can't figure out how to do it. I'm using webpack and saw a suggestion to simply omit the presets and plugins in my .babelrc file, but I get an error saying an object spread line has an unexpected token (the spread operator). How do I simply traverse the import/export paths to bundle the code but leave it as ES6? Huge thanks in advance!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use babel-preset-env
And, target transpilation for your specific browser. If that browser supports all ES6
features, then it won't be transpiled down to ES5
.
E.g.
Your .babelrc
could look like
{
"presets": [
["env", {
"targets": {
"chrome": 60
}
}]
]
}
You can also target multiple browsers so that your code works everywhere.
{
"presets": [
["env", {
"targets": {
"chrome": 60,
"browsers": ["last 2 versions", "safari 7"]
}
}]
]
}