-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
116 lines (111 loc) · 3.39 KB
/
webpack.common.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
/* eslint-disable import/no-extraneous-dependencies */
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const postCssFlexbugFixes = require('postcss-flexbugs-fixes');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const cssNano = require('cssnano');
const CopyWebpackPlugin = require('copy-webpack-plugin');
/* eslint-enable import/no-extraneous-dependencies */
module.exports = {
entry: ['@babel/polyfill', path.join(__dirname, 'src/index.js')],
output: {
path: path.join(__dirname, 'public'),
filename: '[chunkhash].min.js',
publicPath: '/',
},
optimization: {
minimizer: [
new TerserJSPlugin({}),
new OptimizeCssAssetsPlugin({ assetNameRegExp: /\.css$/g, cssProcessor: cssNano, cssProcessorOptions: { discardComments: { removeAll: true }}, canPrint: true })
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src/index.html'),
favicon: path.join(__dirname, 'src/favicon.ico'),
inject: 'body',
minify: {
caseSensitive: true,
collapseInlineTagWhitespace: true,
collapseWhitespace: true,
minifyJS: true,
keepClosingSlash: true,
collapseBooleanAttributes: true,
removeComments: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
trimCustomFragments: true,
useShortDoctype: true,
},
}),
new MiniCssExtractPlugin({ filename: '[chunkhash].min.css' }),
new OptimizeCssAssetsPlugin({ assetNameRegExp: /\.css$/g, cssProcessor: cssNano, cssProcessorOptions: { discardComments: { removeAll: true } }, canPrint: true }),
new CopyWebpackPlugin([
{ from: path.join(__dirname, '/src/assets/images/'), to: 'images/' },
{ from: path.join(__dirname, '/src/assets/fonts/'), to: 'fonts/' },
]),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: { minimize: true },
},
],
},
{
include: [/\.(ttf|woff|woff2|eot|svg)$/],
loader: require.resolve('file-loader'),
options: {
name: 'fonts/[name].[ext]',
},
},
{
test: /\.s?css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: process.env.NODE_ENV === 'development',
},
},
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
plugins: () => [
postCssFlexbugFixes,
],
},
},
{
loader: 'sass-loader',
},
],
},
],
},
};