-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
74 lines (68 loc) · 1.85 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
const path = require('path');
const webpack = require('webpack');
const { merge } = require('webpack-merge');
const copyWebpackPlugin = require('copy-webpack-plugin');
const autoprefixer = require('autoprefixer');
const BUILD_DIR = path.resolve(__dirname, 'dist');
const APP_DIR = path.resolve(__dirname, 'src');
const isProd = (process.env.NODE_ENV === 'production');
const base = {
entry: path.join(APP_DIR, 'js', 'index.jsx'),
output: {
path: BUILD_DIR,
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.scss$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'postcss-loader' },
{ loader: 'sass-loader' },
],
},
{
test: /\.jsx?$/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
},
include: APP_DIR,
},
{
test: /\.(jpg|png|svg)$/,
loader: 'file-loader',
},
],
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
new copyWebpackPlugin({
patterns: [
{
from: 'src/html/index.html',
to: 'index.html',
force: true,
}
]
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: isProd ? JSON.stringify('production') : JSON.stringify('development'),
},
}),
],
};
const dev = {
devtool: 'source-map',
};
const prod = {
optimization: {
minimize: true,
}
};
module.exports = isProd ? merge(base, prod) : merge(base, dev);