-
Notifications
You must be signed in to change notification settings - Fork 11
/
webpack.config.js
117 lines (109 loc) · 2.74 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
const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-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_MODULES = path.resolve(__dirname, 'node_modules');
const ENV = process.env.NODE_ENV || 'development';
const isProd = ENV === 'production';
console.log(`Building for ${ENV}`);
let plugins = [
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify(ENV) },
}),
new HtmlWebpackPlugin({
template: './src/redux/index.html',
filename: './index.html',
excludeChunks: [],
}),
new MiniCssExtractPlugin({
filename: isProd ? 'assets/css/[name].[hash].css' : 'assets/css/[name].css',
chunkFilename: isProd ? 'assets/css/[id].[hash].css' : 'assets/css/[id].css',
}),
new CopyWebpackPlugin([{ from: 'src/assets/images', to: 'images' }])
];
if (isProd) {
plugins.push(
new CleanWebpackPlugin(['dist']),
new OptimizeCssAssetsPlugin({
cssProcessorOptions: {
discardComments: {
removeAll: true
}
}
})
)
} else {
plugins.push(
new webpack.HotModuleReplacementPlugin()
)
}
const config = {
mode: !isProd ? 'development' : 'production',
watch: !isProd,
devtool: !isProd ? 'source-map' : false,
entry: {
'redux-lenses-streaming-example': './src/redux/index.js',
},
output: {
filename: isProd ? "js/[name].[chunkhash].js" : "js/[name].[hash].js",
path: path.resolve(__dirname, 'dist'),
publicPath: '',
},
module: {
rules: [
{
test: /\.jsx?$/,
include: [
path.resolve(__dirname, 'src'),
],
loader: 'babel-loader',
},
{
test: /\.s[ac]ss$/,
use: [{
loader: isProd ? MiniCssExtractPlugin.loader : "style-loader"
},
{
loader: "css-loader",
},
{
loader: "sass-loader",
options: {
includePaths: ["src"]
}
}]
},
{
test: /\.css$/,
use: [{
loader: isProd ? MiniCssExtractPlugin.loader : "style-loader"
},
{
loader: "css-loader"
}]
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.sass', '.scss'],
modules: [
'node_modules',
],
},
plugins,
devServer: {
host: "localhost",
port: 8000,
contentBase: path.resolve(__dirname, "dist"),
historyApiFallback: true,
hot: !isProd,
inline: true,
https: false,
noInfo: false,
progress: true
}
};
module.exports = config;