Here is the solution:
.configureBabel(function(babelConfig) {
babelConfig.presets = ['es2015','stage-2']
babelConfig.plugins = ['transform-runtime']
})
Include all of this content in your file:
var Encore = require('@symfony/webpack-encore');
Encore
// Set the output path for compiled assets
.setOutputPath('public/build/')
// Define the public path for web server access
.setPublicPath('/build')
.cleanupOutputBeforeBuild()
//.createSharedEntry('assets', ['babel-polyfill'])
.enableSourceMaps(!Encore.isProduction())
// Uncomment to create hashed filenames
// .enableVersioning(Encore.isProduction())
// Define project assets
.addEntry('js/app', './assets/js/app.js')
.addEntry('vue', './assets/js/Vue/main.js')
.addStyleEntry('css/app', './assets/scss/style.scss')
.addStyleEntry('css/vue', './assets/scss/vue.scss')
// Enable Sass/SCSS files
.enableSassLoader()
.autoProvidejQuery()
.enableVueLoader()
.enableSassLoader(function(sassOptions) {}, {
resolveUrlLoader: false
})
.configureBabel(function(babelConfig) {
babelConfig.presets = ['es2015','stage-2']
babelConfig.plugins = ['transform-runtime']
})
;
module.exports = Encore.getWebpackConfig();
Don't forget to install the necessary packages:
npm install babel-preset-stage-2
npm install babel-preset-es2015 (or es2017)
npm install babel-plugin-transform-runtime