@@ -6,18 +6,28 @@ import { createRules } from '../../../utils';
6
6
import { BreezrReactBabelOption } from '../../../types' ;
7
7
import { getPkgPath , shouldTransform } from './es5ImcompatibleVersions' ;
8
8
9
- const addEs5ImcompatibleVersions = ( config : Chain , babelConfig : any ) => {
10
- const extraBabelIncludes = [
11
- ( a : string ) => {
12
- if ( ! a . includes ( 'node_modules' ) ) {
9
+ const addEs5IncompatibleVersions = ( config : Chain , babelConfig : any , es5 : boolean , extraInclude ?: Webpack . RuleSetCondition ) => {
10
+ const extraBabelIncludes : Webpack . RuleSetCondition = [ ] ;
11
+
12
+ if ( es5 ) {
13
+ extraBabelIncludes . push ( ( path : string ) => {
14
+ if ( ! path . includes ( 'node_modules' ) ) {
13
15
return false ;
14
16
}
15
- const pkgPath = getPkgPath ( a ) ;
17
+ const pkgPath = getPkgPath ( path ) ;
16
18
return shouldTransform ( pkgPath ) ;
19
+ } )
20
+ }
21
+
22
+ if ( extraInclude ) {
23
+ if ( typeof extraInclude === 'string' && ! extraInclude . startsWith ( '/' ) ) {
24
+ extraBabelIncludes . push ( require . resolve ( extraInclude , { paths : [ process . cwd ( ) ] } ) ) ;
25
+ } else {
26
+ extraBabelIncludes . push ( extraInclude ) ;
17
27
}
18
- ] ;
28
+ }
19
29
20
- extraBabelIncludes . forEach ( ( include : Webpack . RuleSetConditionAbsolute , index : number ) => {
30
+ extraBabelIncludes . forEach ( ( include : Webpack . RuleSetCondition , index : number ) => {
21
31
const rule = `extraBabelInclude_${ index } ` ;
22
32
config . module
23
33
. rule ( rule )
@@ -61,12 +71,12 @@ export const jsx = (config: Chain, options: BreezrReactBabelOption) => {
61
71
test : / \. j s x ? $ /
62
72
} ) ;
63
73
64
- if ( include ) {
65
- rule
66
- . include
67
- . add ( include )
68
- . end ( ) ;
69
- }
74
+ // if (include) {
75
+ // rule
76
+ // .include
77
+ // .add(include)
78
+ // .end();
79
+ // }
70
80
71
81
let babelConfig = options . babelOption ? options . babelOption : {
72
82
presets : [
@@ -99,7 +109,5 @@ export const jsx = (config: Chain, options: BreezrReactBabelOption) => {
99
109
. loader ( require . resolve ( 'babel-loader' ) )
100
110
. options ( babelConfig ) ;
101
111
102
- if ( es5ImcompatibleVersions ) {
103
- addEs5ImcompatibleVersions ( config , babelConfig ) ;
104
- }
112
+ addEs5IncompatibleVersions ( config , babelConfig , ! ! es5ImcompatibleVersions , include ) ;
105
113
} ;
0 commit comments