Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundle ES6 files without transpilation

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!

like image 503
sunny-mittal Avatar asked Feb 25 '26 14:02

sunny-mittal


1 Answers

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"]
      }
    }]
  ]
}
like image 171
Prashant Avatar answered Feb 27 '26 04:02

Prashant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!