Does Laravel Mix ES8 support?

I am compiling javascript files using the Laravel combination, and since I am not very knowledgeable about Babel and package.json, I want to ask if Laravel Mix ES8, especially async / await, is supported?

If I try, I can’t tell if Mix async / await is overwriting to ES5 or if async / await is just supported by my browser, which is the latest version. I still want it to be transferred to ES2015, so the application will still work in browsers that only support ES5.

+5
source share
1 answer

async / wait with Laravel Mix:

If you use Laravel Mix out of the box and use async and expect, you will receive the following error message:

Unprepared ReferenceError: restoreatorRuntime not defined

But Laravel Mix uses Babel to support ES2015. We can configure compilation if we need to.

To get async / wait to work, add the .babelrc file to the root directory with this content:

 { "presets": ["es2015", "stage-3"], "plugins": [ "transform-runtime" ] } 

And install the required npm packages:

 npm install babel-preset-es2015 babel-preset-stage-3 babel-plugin-transform-runtime --save-dev 

The important thing (which caused the error) is the transform-runtime plugin. It does not come with Laravel Mix, but you need it to make asynchronous / standby work.

ES8:

As you saw above, you can use various predefined steps in Babel. With them, you can use the features included in ES8 or later. For example, step-3 includes the async / await function.

They have an overview of the steps on their website.

+11
source

Source: https://habr.com/ru/post/1271253/


All Articles