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