简体   繁体   中英

How to use Babel in Deno?

At the moment deno bundle does not support targeting older ES version such as ES3, since it's by default targeting ESNext, it makes the bundled code unable to be executed in certain environments.

Therefore, I wanted to use Babel to transpile the bundled code to a more compatible version ES.

You can achieve this by importing Babel standalone from jspm.io .

import babelstandalone from "https://dev.jspm.io/@babel/standalone"

const code = `var x = 5`
const transformed = babelstandalone.transform(code, { 
  presets: ['env'] 
}).code
console.log(transformed)

If you intended to run the transformed code in browser, you will need to import runtime.js . You can do so by including the following script tag in your HTML file.

<script src="https://unpkg.com/regenerator-runtime@0.13.1/runtime.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM