@@ -4,15 +4,36 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
4
4
const currDir = process . cwd ( ) ;
5
5
6
6
module . exports = ( config ) => {
7
- const { mode } = config ;
7
+ const { mode, typescript } = config ;
8
+
9
+ let babelLoader = {
10
+ test : / \. ( t s | j s ) x ? $ / ,
11
+ loader : require . resolve ( 'babel-loader' ) ,
12
+ exclude : / n o d e _ m o d u l e s / ,
13
+ options : {
14
+ presets : [ "@babel/preset-env" , "@babel/preset-react" ] ,
15
+ }
16
+ } ;
17
+
18
+ let tsLoader = {
19
+ test : / \. t s x ? $ / ,
20
+ use : 'ts-loader' ,
21
+ exclude : / n o d e _ m o d u l e s / ,
22
+ } ;
23
+
24
+ let entryFile = typescript ? 'index.tsx' : 'index.js'
8
25
9
26
return {
10
27
mode : mode ,
11
- entry : path . resolve ( currDir , 'src' , 'index.js' ) ,
28
+ entry : path . resolve ( currDir , 'src' , entryFile ) ,
12
29
output : {
13
30
path : path . resolve ( currDir , 'dist' ) ,
14
31
filename : 'bundle.js'
15
32
} ,
33
+ devtool : 'source-map' ,
34
+ resolve : {
35
+ extensions : [ '.tsx' , '.ts' , '.js' , '.jsx' ] ,
36
+ } ,
16
37
devServer : {
17
38
contentBase : path . resolve ( currDir , 'src' ) ,
18
39
} ,
@@ -24,14 +45,7 @@ module.exports = (config) => {
24
45
] ,
25
46
module : {
26
47
rules : [
27
- {
28
- test : / \. ( t s | j s ) x ? $ / ,
29
- loader : require . resolve ( 'babel-loader' ) ,
30
- exclude : / n o d e _ m o d u l e s / ,
31
- options : {
32
- presets : [ "@babel/preset-env" , "@babel/preset-react" ] ,
33
- }
34
- } ,
48
+ typescript ? tsLoader : babelLoader ,
35
49
]
36
50
}
37
51
}
0 commit comments