-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
112 lines (96 loc) · 2.42 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
/*jshint esversion: 6 */
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const webpack = require('webpack');
const glob = require('glob');
const PurifyCSSPlugin = require('purifycss-webpack');
const isProd = process.env.NODE_ENV === 'production';
const cssDev = ['style-loader', 'css-loader', 'sass-loader'];
cssProde = ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader',
options: {
url: false,
minimize: true,
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
],
publicPath: './dist',
});
const cssConfig = isProd ? cssProde : cssDev;
const path = require("path");
module.exports = {
entry: './src/js/app.js',
output: {
path: path.resolve(__dirname, "dist"),
filename: 'js/app.bundle.js',
},
module: {
rules: [{
test: /\.scss$/,
use: cssConfig
},
{
test: /\.(gif|png|jpe?g|svg|)$/i,
use: [
// 'file-loader',
// 'file-loader?name=img/[name].[ext]',
// to short
'file-loader?name=[name].[ext]&outputPath=./img/&publicPath=./img',
// to make img title same name
// 'file-loader?name[hash:6][name][ext]&outputPath=/img/',
// make img title lenth
'image-webpack-loader',
]
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
use: [
'file-loader?name=[name].[ext]&outputPath=./fonts/&publicPath=/fonts/',
]
}
]
},
devServer: {
contentBase: path.join(__dirname, "dist"),
compress: true,
hot: true,
stats: "errors-only", // to see error in terminal
open: true
// to open new tab evry run
},
plugins: [
new HtmlWebpackPlugin({
title: 'custom title',
minify: {
collapseWhitespace: true
},
hash: true,
template: './src/index.html',
}),
new HtmlWebpackPlugin({
title: 'about',
hash: true,
filename: 'about.html',
template: './src/about.html',
}),
new ExtractTextPlugin({
filename: './css/app.[hash:7].css',
disable: !isProd,
allChunks: true,
}),
new webpack.HotModuleReplacementPlugin(),
new PurifyCSSPlugin({
paths: glob.sync(path.join(__dirname, 'src/*.html')),
minimize: true
})
]
};