-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
76 lines (73 loc) · 2.04 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const config = {
/*
Entry point, file where you app renders to your DOM(ReactDOM.render)
add more [key]: [value] as many entry points you have,
key= name of your app
value= path of your entry point
*/
entry: {
app: path.join(__dirname, 'src/index.js')
},
/*
Output,
path= place to put your final files
filename= name of your app file
*/
output: {
path: path.join(__dirname, '/dist/'),
filename: 'app.min.js'
},
/*
Plugins, webpack has hundred of plugins to automate some tasks
Check this out https://webpack.js.org/plugins/
*/
plugins: [
// Remove dist folder before create a new one
new CleanWebpackPlugin(['dist']),
// Easily create HTML files to serve your bundles, to configurate https://github.com/jantimon/html-webpack-plugin#options
new HtmlWebpackPlugin({
title: 'Coso'
})
],
module: {
/*
Rules declare witch loader it should use when a file match with test value,
test= regex to match
exclude= path where webpack will not watch
loader= what webpack should use with that file
query= extra configuration
*/
rules: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['env', 'react'],
plugins: ['react-hot-loader/babel']
}
}, {
test: /\.css$/,
loader: 'style-loader!css-loader'
}, {
test: /\.(jpg|png|gif|svg)$/,
use: {
loader: 'url-loader'
}
}]
}
};
module.exports = (env, argv) => {
if (argv.mode === 'development') {
// if dev mode add a http server with desired content, more configuration https://webpack.js.org/configuration/dev-server/
config.devServer = {
contentBase: './dist',
hot: true
};
config.plugins.push(new webpack.HotModuleReplacementPlugin())
}
return config;
};