-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
115 lines (99 loc) · 3.03 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
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const dirStyles = path.join(__dirname, 'src/styles');
const dirApp = path.join(__dirname, 'src/app');
const dirStatic = path.join(__dirname, 'static');
const dirNode = 'node_modules';
const pages = ['index', '404'];
const mapPages = pages.map((file) => {
return new HtmlWebpackPlugin({
filename: `${file}.html`,
template: path.join(__dirname, `src/views/pages/${file}.pug`),
});
});
module.exports = {
entry: [
path.join(dirApp, 'index.js'),
path.join(dirStyles, 'index.scss'),
path.join(__dirname, 'src/pwa.js'),
path.join(__dirname, 'src/sw.js'),
],
resolve: {
modules: [dirStyles, dirApp, dirStatic, dirNode],
},
plugins: [
...mapPages,
new CopyWebpackPlugin({
patterns: [
{ from: path.resolve(__dirname, 'static'), to: 'static' },
{ from: path.resolve(__dirname, 'src/site.webmanifest'), to: '' },
{ from: path.resolve(__dirname, 'src/pwa.js'), to: '' },
{ from: path.resolve(__dirname, 'src/sw.js'), to: '' },
],
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
],
module: {
rules: [
// HTML
{
test: /\.pug$/,
use: ['pug-loader'],
},
// CSS
{
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '',
},
},
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
},
{
loader: 'sass-loader',
},
],
},
// JS
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
// Images
{
test: /\.(jpe?g|png|gif|svg|fnt|webp)$/,
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
// outputPath: 'images/',
},
},
// Fonts
{
test: /\.(woff(2)?|ttf|eot)$/,
type: 'asset/resource',
generator: {
filename: '[name][ext]',
},
},
],
},
// optimization: {
// minimize: true,
// minimizer: [new TerserPlugin()],
// },
};