-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
90 lines (82 loc) · 2.99 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const path = require("path");
//https://github.com/gitname/react-gh-pages
/*We are basically telling webpack to take index.js from entry. Then check for all file extensions in resolve.
After that apply all the rules in module.rules and produce the output and place it in main.js in the public folder.*/
module.exports={
/** "mode"
* the environment - development, production, none. tells webpack
* to use its built-in optimizations accordingly. default is production
*/
mode: "development",
/** "entry"
* the entry point
*/
entry: "./src/index.js",
output: {
/** "path"
* the folder path of the output file
*/
path: path.resolve(__dirname, "public"),
/** "filename"
* the name of the output file
*/
filename: "main.js"
},
/** "target"
* setting "node" as target app (server side), and setting it as "web" is
* for browser (client side). Default is "web"
*/
target: "web",
devServer: {
/** "port"
* port of dev server
*/
port: "9500",
/** "static"
* This property tells Webpack what static file it should serve
*/
static: ["./public"],
/** "open"
* opens the browser after server is successfully started
*/
open: true,
/** "hot"
* enabling and disabling HMR. takes "true", "false" and "only".
* "only" is used if enable Hot Module Replacement without page
* refresh as a fallback in case of build failures
*/
hot: true ,
/** "liveReload"
* disable live reload on the browser. "hot" must be set to false for this to work
*/
liveReload: true
},
resolve: {
/** "extensions"
* If multiple files share the same name but have different extensions, webpack will
* resolve the one with the extension listed first in the array and skip the rest.
* This is what enables users to leave off the extension when importing
*/
extensions: ['.js','.jsx','.json']
},
module:{
/** "rules"
* This says - "Hey webpack compiler, when you come across a path that resolves to a '.js or .jsx'
* file inside of a require()/import statement, use the babel-loader to transform it before you
* add it to the bundle. And in this process, kindly make sure to exclude node_modules folder from
* being searched"
*/
rules: [
{
test: /\.(js|jsx)$/, //kind of file extension this rule should look for and apply in test
exclude: /node_modules/, //folder to be excluded
use: 'babel-loader' //loader which we are going to use
},
{
test: /\.css$/i,
include: path.resolve(__dirname, 'src'),
use: ['style-loader', 'css-loader', 'postcss-loader'],
}
]
}
}