-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
59 lines (53 loc) · 1.52 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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
const path = require('path');
const isDev = process.env.NODE_ENV === 'development';
module.exports = {
entry: ['react-hot-loader/patch', './src/js/main.js'],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'js/[name]-[hash:8].js',
},
module: {
rules: [
{ test: /\.(js|jsx)$/, exclude: /node_modules/, use: ['babel-loader'] },
{ test: /\.txt$/, use: 'raw-loader' },
{
test: /\.css$/,
exclude: /node_modules/,
use: [
isDev
? 'style-loader'
: {
loader: MiniCssExtractPlugin.loader,
options: { publicPath: '../' },
},
{ loader: 'css-loader', options: { importLoaders: 1 } },
{ loader: 'postcss-loader' },
],
},
],
},
resolve: {
extensions: ['*', '.js', '.jsx'],
alias: {
'react-dom': '@hot-loader/react-dom',
},
},
plugins: [
new HtmlWebpackPlugin({ template: './src/index.ejs' }),
new webpack.HotModuleReplacementPlugin(),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: isDev ? '[name].css' : 'css/[name]-[hash:8].css',
}),
],
devServer: {
contentBase: './dist',
hot: true,
inline: true,
},
devtool: isDev ? 'eval-source-map' : 'source-map',
};