-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
76 lines (74 loc) · 1.92 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const fs = require('fs');
const HtmlBeautifyPlugin = require('html-beautify-webpack-plugin');
const generateHtmlPlugins = templateDir => {
const templateFiles = fs.readdirSync(path.resolve(__dirname, templateDir));
return templateFiles.map(item => {
return new HtmlWebpackPlugin({
favicon: './src/img/favicon.ico',
filename: item,
template: path.resolve(__dirname, `${templateDir}/${item}`),
});
});
};
module.exports = {
context: __dirname,
entry: './src/js/index.js',
output: {
path: path.join(__dirname, 'dist'),
publicPath: '',
filename: 'js/bundle.js',
},
module: {
rules: [
{
test: /\.(png|jpg|gif|svg|ico)$/,
loader: 'file-loader',
options: {
name: 'img/[name].[ext]',
},
},
{
test: /\.(html)$/,
use: {
loader: 'html-loader',
options: {
interpolate: true,
},
},
},
{
test: /\.(sc|sa|c)ss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
},
],
},
plugins: [
new BrowserSyncPlugin({
host: 'localhost',
port: 4000,
server: { baseDir: ['dist'] },
files: ['**/*.html'],
notify: false,
ghostMode: false,
open: false,
}),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({ filename: 'css/style.css' }),
]
.concat(generateHtmlPlugins('./src/templates/views'))
.concat([
new HtmlBeautifyPlugin({
config: {
html: {
indent_size: 2,
max_preserve_newlines: 1,
},
},
}),
]),
};