-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
105 lines (96 loc) · 2.45 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
/* eslint-env node */
const env = process.env.NODE_ENV;
const path = require( 'path' );
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
const HtmlWebpackPlugin = require( 'html-webpack-plugin' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const OptimizeCSSAssetsPlugin = require( 'optimize-css-assets-webpack-plugin' );
const TerserJSPlugin = require( 'terser-webpack-plugin' );
module.exports = {
mode: env || 'development',
// devtool: 'cheap-eval-source-map',
entry: './src/index.js',
module: {
rules: [
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
use: 'url-loader',
},
{
test: /\.css$/,
exclude: /src/,
include: /node_modules/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: { hmr: false },
},
{ loader: 'css-loader' },
{ loader: 'postcss-loader' },
],
},
{
test: /\.css$/,
exclude: /node_modules/,
include: /src/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: process.env.NODE_ENV === 'development',
},
},
{ loader: 'css-loader', options: { modules: true, importLoaders: 1, localIdentName: '[name]__[local]___[hash:base64:5]' } },
{ loader: 'postcss-loader' },
],
},
{
test: /\.js$/,
include: /src/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
{
// check source files, not modified by other loaders
enforce: 'pre',
test: /\.js$/,
include: /src/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
// cache: true,
fix: true,
},
},
],
},
resolve: {
modules: [
path.resolve( __dirname, 'src' ),
'node_modules',
],
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin( {
filename: '[name].[chunkhash:8].css',
} ),
new HtmlWebpackPlugin( {
filename: 'index.html',
template: 'src/index.html',
} ),
],
optimization: {
minimizer: [
new TerserJSPlugin( {} ),
new OptimizeCSSAssetsPlugin( {} ),
],
},
output: {
path: path.resolve( __dirname, 'dist' ),
filename: '[name].[chunkhash:8].js',
},
};