-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
75 lines (65 loc) · 2.07 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const packagejson = require('./package.json');
const dependencies = Object.keys(packagejson.dependencies);
module.exports = {
mode: 'development',
target: 'web',
entry: {
// 'app' is the entry point into our react app located in src/.index.js
app: './src/index.js',
// 'vendor' is the name of the bundle that contains all of our 3rd party code
// this is a list of modules that are listed in our package.json file
vendor: dependencies
},
output: {
// we are going to output everythign into the 'dist' directory,
path: path.resolve(__dirname, 'dist'),
// each of the entry point will be produced using placeholder for the name of the
// entry point. We should see 'app.js' and 'vendor~.js' in 'dist
filename: '[name].js',
// the path to resources relative to the html file. Our index.html will
// be at the root of dist
publicPath: '/'
},
// setting up babel-loader to compile our js/jsx files
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/react'],
plugins: ['@babel/plugin-syntax-jsx'],
cacheDirectory: true,
},
}
}
]
},
// tell webpack to split our vendors bundle into chunks
optimization: {
splitChunks: {
chunks: 'all'
}
},
plugins: [
// Here we are taking the template found in 'src/index.html' and injecting our bundles
// into the body secion of the file
new HtmlWebpackPlugin({
template: path.join(__dirname, '/src/index.html'),
filename: 'index.html',
inject: 'body'
})
],
// the dev server settings
devServer: {
// the path of the static resources
contentBase: path.join(__dirname, '/'),
historyApiFallback: true
},
// for debugging the compiled code
devtool: 'source-map'
};