@@ -40,6 +40,7 @@ If you prefer to create a ${chalk.yellow('.eslintrc.js')} file by yourself, here
40
40
41
41
${ chalk . yellow ( `// .eslintrc.js
42
42
module.exports = {
43
+ root: true,
43
44
parser: '@babel/eslint-parser',
44
45
extends: ['eslint:recommended'],
45
46
}
@@ -51,13 +52,37 @@ Install ${chalk.yellow('@babel/eslint-parser')} to prevent potential parsing iss
51
52
const babelConfig = babelLoaderUtil . getLoaders ( webpackConfig ) [ 0 ] . options ;
52
53
// cacheDirectory is a custom loader option, not a Babel option
53
54
delete babelConfig [ 'cacheDirectory' ] ;
55
+
56
+ ( babelConfig [ 'presets' ] || [ ] ) . forEach ( preset => {
57
+ if ( ! Array . isArray ( preset ) ) {
58
+ return ;
59
+ }
60
+
61
+ if ( typeof preset [ 0 ] === 'string' && preset [ 0 ] . includes ( '@babel' ) && preset [ 0 ] . includes ( 'preset-env' ) ) {
62
+ // The goal is to replace the preset string with a require.resolve() call, executed at runtime.
63
+ // Since we output the Babel config as JSON, we need to replace it with a placeholder.
64
+ preset [ 0 ] = '__PATH_TO_BABEL_PRESET_ENV__' ;
65
+
66
+ // The option "targets" is not necessary
67
+ delete preset [ 1 ] [ 'targets' ] ;
68
+
69
+ // If needed, specify the core-js version to use
70
+ if ( preset [ 1 ] [ 'corejs' ] === null ) {
71
+ preset [ 1 ] [ 'corejs' ] = packageHelper . getPackageVersion ( 'core-js' ) ;
72
+ }
73
+ }
74
+ } ) ;
75
+
54
76
message += `
55
77
56
78
You will also need to specify your Babel config in a separate file. The current
57
79
configuration Encore has been adding for your is:
58
80
59
81
${ chalk . yellow ( `// babel.config.js
60
- module.exports = ${ JSON . stringify ( babelConfig , null , 4 ) }
82
+ module.exports = ${
83
+ JSON . stringify ( babelConfig , null , 4 )
84
+ . replace ( '"__PATH_TO_BABEL_PRESET_ENV__"' , 'require.resolve("@babel/preset-env")' )
85
+ }
61
86
` ) } `;
62
87
63
88
if ( webpackConfig . babelConfigurationCallback ) {
0 commit comments