-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·118 lines (114 loc) · 2.67 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const NODE_ENV = process.env.NODE_ENV || 'development';
console.log('NODE_ENV', NODE_ENV);
const className = NODE_ENV === 'production' ? '[local]--[hash:base64:5]' : '[path][name]__[local]--[hash:base64:5]';
const MinCss = {
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../',
},
};
module.exports = {
entry: [
'@babel/polyfill',
path.resolve(__dirname, 'client', 'app.jsx'),
],
output: {
path: path.resolve(__dirname, 'public'),
filename: 'js/bundle.js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.local.css$/,
use: [
MinCss,
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: className,
},
},
'postcss-loader',
],
},
{
test: /\.css$/,
exclude: /\.local.css$/,
use: [
MinCss,
'css-loader',
'postcss-loader',
],
},
{
test: /\.(jpg|png|svg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'img/',
},
},
],
},
{
test: /\.(ttf|eot|woff)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
},
},
],
},
],
},
optimization: {
minimizer: [
new UglifyJSPlugin({
uglifyOptions: {
beautify: false,
ecma: 5,
compress: {
drop_console: true,
},
comments: false,
mangle: false,
},
}),
new OptimizeCSSAssetsPlugin({}),
],
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/[name].css',
}),
new CopyWebpackPlugin([
// {from: 'client/icons', to: 'icons'},
// {from: 'client/manifest.json'},
// {from: 'client/sw.js'},
// {from: 'client/index.html'},
{ from: 'static/reset.css', to: 'css' }
]),
],
resolve: {
extensions: ['*', '.js', '.jsx'],
modules: [path.resolve(__dirname, 'client'), 'node_modules'],
},
mode: NODE_ENV,
watch: NODE_ENV === 'development',
};