-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
156 lines (152 loc) · 4.58 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const devMode = process.env.NODE_ENV !== 'production';
const pathsToClean = [
'build',
];
module.exports = {
// Don't attempt to continue if there are any errors.
bail: true,
mode: process.env.NODE_ENV || 'development',
context: __dirname,
devtool: 'cheap-module-source-map',
entry: {
corejs: 'core-js/stable',
main: path.resolve(__dirname, 'src/js/index.js'),
},
output: {
path: path.resolve(__dirname, 'build'),
filename: 'js/[name].js?[hash:8]',
publicPath: '/',
},
resolve: {
extensions: ['.js', '.jsx', '.scss', '.css'],
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'eslint-loader',
},
// ** ADDING/UPDATING LOADERS **
// The "file" loader handles all assets unless explicitly excluded.
// The `exclude` list *must* be updated with every change to loader extensions.
// When adding a new loader, you must add its `test`
// as a new entry in the `exclude` list for "file" loader.
// "file" loader makes sure those assets get served by WebpackDevServer.
// When you `import` an asset, you get its (virtual) filename.
// In production, they would get copied to the `build` folder.
{
exclude: [
/\.html$/,
/\.(js|jsx)$/,
/\.css$/,
/\.(scss|sass)$/,
/\.json$/,
/\.bmp$/,
/\.gif$/,
/\.jpe?g$/,
/\.png$/,
],
loader: require.resolve('file-loader'),
options: {
name: '[path][name].[ext]?[hash]',
},
},
// "url" loader works like "file" loader except that it embeds assets
// smaller than specified limit in bytes as data URLs to avoid requests.
// A missing `test` is equivalent to a match.
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: '[path][name].[ext]?[hash]',
},
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: require.resolve('babel-loader'),
},
{
test: /\.(sa|sc|c)ss$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
sourceMap: true,
},
},
'postcss-loader',
{
loader: require.resolve('sass-loader'),
options: {
sourceMap: true,
},
},
],
},
],
},
devServer: {
// WebpackDevServer is noisy by default so we emit custom message instead
// by listening to the compiler events with `compiler.plugin` calls above.
contentBase: path.join(__dirname, 'build'),
compress: true,
port: 9000,
// quiet: true,
// Reportedly, this avoids CPU overload on some systems.
// https://github.com/facebookincubator/create-react-app/issues/293
watchOptions: {
ignored: /node_modules/,
},
// Enable HTTPS if the HTTPS environment variable is set to 'true'
// https: protocol === 'https',
historyApiFallback: true,
hot: true,
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
favicon: './src/favicon.ico',
}),
new webpack.HotModuleReplacementPlugin(),
new CopyWebpackPlugin([{
from: 'src/assets/**/*',
to: 'build/assets/**/*',
}]),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: devMode ? '[name].css' : '[name].[hash].css',
chunkFilename: devMode ? '[id].css' : '[id].[hash].css',
}),
new CleanWebpackPlugin({
dry: false,
verbose: true,
cleanOnceBeforeBuildPatterns: pathsToClean,
}),
],
optimization: {
minimizer: [
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
map: {
inline: false, // set to false if you want CSS source maps
annotation: true,
},
},
}),
],
},
};