捆绑ES6文件而不进行转译 [英] Bundle ES6 files without transpilation

查看:73
本文介绍了捆绑ES6文件而不进行转译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能缺少明显的东西,但是在发布此消息之前我进行了很多搜索,说实话,我为找不到解决方案感到震惊.我想将我的ES6文件捆绑到一个模块中,但是,由于我用于测试的浏览器支持ES6,因此实际上并不需要任何内容​​.我不知道该怎么做.我使用的是webpack,看到了一个建议,可以简单地忽略.babelrc文件中的预设和插件,但是却收到一条错误消息,指出对象传播行具有意外的标记(传播操作符).如何简单遍历导入/导出路径以捆绑代码,但将其保留为ES6?提前谢谢!

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!

推荐答案

使用 babel-preset- env

并且,针对您的特定浏览器进行目标移植.如果该浏览器支持所有ES6功能,则不会将其转换为ES5.

And, target transpilation for your specific browser. If that browser supports all ES6 features, then it won't be transpiled down to ES5.

例如

您的.babelrc可能看起来像

{
  "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"]
      }
    }]
  ]
}

这篇关于捆绑ES6文件而不进行转译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆