1
+ const { join } = require ( "path" ) ;
2
+ const HtmlWebpackPlugin = require ( "html-webpack-plugin" ) ;
3
+ const HtmlWebpackTemplate = require ( "html-webpack-template" ) ;
4
+ var webpack = require ( 'webpack' ) ;
5
+
6
+ // package.json contains the version number of the dependencies
7
+ // that we want to make external. Parsing the package.json
8
+ // makes it automatic to keep the package version in sync with
9
+ // the CDN URL used in the HtmlWebpackPlugin
10
+ const packageJson = require ( join ( __dirname , 'package.json' ) ) ;
11
+
12
+ // This is the object webpack looks at for configuration.
13
+ // Webpack doesn't care about any other javascript in the file.
14
+ // Because this is javascript, you can write functions to help build up the configuration.
15
+ module . exports = {
16
+
17
+ // Tells webpack what kind of source maps to produce.
18
+ // There are a lot of options, but I chose the standalone file option.
19
+ devtool : "source-map" ,
20
+
21
+ // Tells webpack where start walking the dependencies to build a bundle.
22
+ entry : {
23
+ app : [
24
+ join ( __dirname , "src/index.tsx" )
25
+ ]
26
+ } ,
27
+
28
+ // When importing a module whose path matches one of the following, just
29
+ // assume a corresponding global variable exists and use that instead.
30
+ // This is important because it allows us to avoid bundling all of our
31
+ // dependencies, which allows browsers to cache standard libraries like React once.
32
+ externals : {
33
+ "react" : "React" ,
34
+ "react-dom" : "ReactDOM"
35
+ } ,
36
+
37
+ // When the env is "development", this tells webpack to provide debuggable information in the source maps and turns off some optimizations.
38
+ mode : process . env . NODE_ENV ,
39
+
40
+ // Tells webpack how to run file transformation pipeline of webpack.
41
+ // Awesome-typescript-loader will run on all typescript files.
42
+ // Source-map-loader will run on the JS files.
43
+ module : {
44
+ rules : [
45
+ // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
46
+ { test : / \. t s x ? $ / , loaders : [ "awesome-typescript-loader" ] } ,
47
+
48
+ // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
49
+ { enforce : "pre" , test : / \. j s ? $ / , loader : "source-map-loader" } ,
50
+
51
+ { test : / \. c s s $ / , use : [ 'style-loader' , 'css-loader' ] } ,
52
+ ]
53
+ } ,
54
+
55
+ // Tells webpack not to touch __dirname and __filename.
56
+ // If you run the bundle in node.js it falls back to these values of node.js.
57
+ // https://github.com/webpack/webpack/issues/2010
58
+ node : {
59
+ __dirname : false ,
60
+ __filename : false
61
+ } ,
62
+
63
+ // Tells webpack where to output the bundled javascript
64
+ output : {
65
+ filename : "index.js" ,
66
+ path : join ( __dirname , "dist" )
67
+ } ,
68
+
69
+ // Tells the HTML webpack plug-in to use a template and emit dist/index.html
70
+ plugins : [
71
+ new HtmlWebpackPlugin ( {
72
+ title : "react-splitter demo" ,
73
+ inject : false ,
74
+ template : HtmlWebpackTemplate ,
75
+ appMountId : "app" ,
76
+ scripts : [
77
+ `https://unpkg.com/react@${ packageJson . dependencies [ 'react' ] } /umd/react.production.min.js` ,
78
+ `https://unpkg.com/react-dom@${ packageJson . dependencies [ 'react-dom' ] } /umd/react-dom.production.min.js` ,
79
+ 'index.js'
80
+ ]
81
+ } )
82
+ ] ,
83
+
84
+ // Tells webpack what file extesions it should look at.
85
+ resolve : {
86
+ extensions : [ ".ts" , ".tsx" , ".js" , ".json" ]
87
+ }
88
+ } ;
0 commit comments