This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
124 lines (118 loc) · 2.71 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
119
120
121
122
123
124
// Webpack configuration
const merge = require('webpack-merge');
const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
// Common
//
// This configuration is used for both the development and production
// builds.
const commonConfig = {
entry: './src/main.jsx',
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].bundle.js',
},
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.(ttf|eot|woff|woff2|svg)$/,
exclude: /images/,
use: [{
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
},
}],
},
{
test: /\.(jpg|png|svg)$/,
exclude: /fonts/,
use: [{
loader: 'file-loader',
options: {
name: 'images/[hash].[ext]',
},
}],
},
],
},
plugins: [
new CleanWebpackPlugin(['build'], {
root: path.resolve(__dirname, '../'),
}),
new HtmlWebpackPlugin({
template: './src/index.html',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
}),
],
stats: {
colors: true,
},
};
// Development
//
// This configuration is used only when bundling the development files.
const developmentConfig = {
devtool: 'cheap-eval-source-map',
module: {
rules: [
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader']
},
],
},
devServer: {
contentBase: path.join(__dirname, 'build'),
compress: true,
port: 9000,
},
};
// Production
//
// This configuration is used only when bundling the final production ready
// files.
const productionConfig = {
devtool: 'source-map',
module: {
rules: [
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
use: [
'css-loader',
'postcss-loader',
'sass-loader',
],
}),
},
],
},
plugins: [
new ExtractTextPlugin('styles.css'),
new UglifyJsPlugin({
sourceMap: true,
parallel: true,
}),
],
};
// Export configuration based on the set environment.
if (process.env.NODE_ENV === 'development') {
module.exports = merge(commonConfig, developmentConfig);
} else {
module.exports = merge(commonConfig, productionConfig);
}