symfony / webpack-encore

A simple but powerful API for processing & compiling assets built around Webpack
https://symfony.com/doc/current/frontend.html
MIT License
2.23k stars 198 forks source link

Disable @babel/preset-env #569

Closed lpeliberty closed 5 years ago

lpeliberty commented 5 years ago

Hello, i'm having trouble with my project : I'm using Limenius ReactBundle for SSR with a React app. To do this, i installed v8js on my server, but according to this issue#29, it seems that i need to disable babel-polyfill for server-side JS code. If i understand well, now @babel/preset-env include @babel/polyfill, and as it seems, @babel/preset-env is auto loaded with webpack-encore (i'm on v0.27.0) isn't it ? If i'm right, is there a solution to disable @babel/preset-env in webpack-encore plz ?

Here is my webpack.config.js

const Encore = require('@symfony/webpack-encore');

Encore
  .setOutputPath("web/build/front/")
  .setPublicPath('/build/front')
  .addEntry("server-bundle", "./path/to/src/index.js")
  .enableReactPreset()
  // .configureBabel(babelConfig => {
  //   babelConfig.presets.push('airbnb');
  //   babelConfig.plugins.push('@babel/plugin-proposal-class-properties');
  //   babelConfig.plugins.push('transform-react-remove-prop-types');
  // })
  .cleanupOutputBeforeBuild()
  .disableSingleRuntimeChunk();

myApp = Encore.getWebpackConfig();
myApp.name = 'myApp';

module.exports = [myApp];
Lyrkan commented 5 years ago

Hi @lpeliberty,

@babel/polyfill is not included in @babel/preset-env so you shouldn't have any polyfill unless you add it manually to your project (or rather core-js since @babel/polyfill is deprecated) and enable the feature using the useBuiltIns/core-js options.

From what I'm understanding of the issue you linked, the error is triggered by importing @babel/polyfill in a way that isn't supported by the ReactBundle.

If you are not doing that, you are probably facing a different problem.

Anyway, if you want to check that, you can disable @babel/preset-env by removing it from the babelConfig.presets array in your Encore.configureBabel() call, or through a custom .babelrc/.babelrc.js file.

lpeliberty commented 5 years ago

Ok thx for infos ! I tried without @babel/preset-env and i still have my error...