Some browsers do not support es6 writing.

The

project is built using Node.js, and the page is written in the public folder in the root directory.
now some browsers (such as IE,360) do not recognize the writing of es6 (mainly using arrow function and ``, etc.).
how to solve this problem?

the solution now is to introduce a
< script src= "browser.min.js" > < / script >
in the html page first, and then introduce other js files with < script type= "text/babel" src= "> < / script > referencing,
but feel that this way affects the performance of the page a little bit, and the page loads slowly.

would you like to know how to solve it? (or do you want to change back to the way es5 is written? )

Sep.01,2021

if you just use the syntax sugar of es6,
can use babel-cli to transfer npx babel src-- out-dir lib
or use node

const babel = require("babel-core")
babel.transformFile("./src/index.js", {extends:'./.babelrc'},function (err, result) {
    let { code, map, ast } = result;
   
  });

get the converted es5 code and then write it to the lib directory or other processing


Don't quote like that, just run the translated code using bable.

distinguish between the directory of source code and the directory of bable translated code.


AOT.


babel conversion. Most browsers are compatible with ES6 code


code running in browsers. Generally, code running in browsers is converted to es5 using bable. For example, for projects with separate front and rear ends, people are used to using webpack+bable to build


code in front end scaffolding first. After writing, put the compiled files under the public folder


es6 into syntax and core methods. Incompatible methods can introduce ployfill, syntax. You can only use babel to convert


Why do I use your method to write es6 browser will also report syntax errors

Menu