-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
104 lines (101 loc) · 2.51 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
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const fs = require('fs');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const PATHS = {
style: './src/scss/style.scss',
bundle: './src/app.js'
}
const PAGES_DIR = './src/pug/pages/'
const PAGES = fs.readdirSync(PAGES_DIR).filter(fileName => fileName.endsWith('.pug'))
module.exports = {
mode: 'development',
entry: {
...PATHS
},
devtool: 'inline-source-map',
devServer: {
index: 'index.html',
contentBase: path.join(__dirname, 'dist'),
hot: true,
writeToDisk: true,
open: 'chrome',
compress: true,
port: 9000
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: 'js/[name][hash].[ext]'
},
module: {
rules: [
{
test: /\.pug$/,
loader: 'pug-loader',
options: {pretty: true},
exclude: '/node_modules/',
},
{
test: /\.css$/i,
use: [
'style-loader',
],
exclude: '/node_modules/',
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
{
loader: 'file-loader',
options: {outputPath: 'css/', name: '[name].css'}
},
'sass-loader'
]
},
{
test: /\.(woff(2)?|ttf|eot|svg|otf)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
},
}]
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'images/'
}
}]
}
]
},
plugins: [
new CleanWebpackPlugin(),
new CleanWebpackPlugin({cleanStaleWebpackAssets: false}),
...PAGES.map(page => new HtmlWebpackPlugin({
template: `${PAGES_DIR}/${page}`,
filename: `./${page.replace(/\.pug/, '.html')}`
})),
new CopyWebpackPlugin({
patterns: [
{
from: 'src/assets/fonts',
to: 'fonts'
},
{
from: 'src/assets/images',
to: 'images'
},
],
})
]
};