-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
95 lines (94 loc) · 2.54 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
var HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
var path = require('path')
var webpack = require('webpack')
var isProduction = process.env.NODE_ENV === 'production';
var scssDev = ['style-loader', 'css-loader', 'sass-loader'];
var cssDev = ['style-loader', 'css-loader'];
var scssProd = ExtractTextPlugin.extract({
fallback: 'style-loader',
loader: ['css-loader', 'sass-loader'],
publicPath: '/dist'
});
var cssProd = ExtractTextPlugin.extract({
fallback: 'style-loader',
loader: ['css-loader'],
publicPath: '/dist'
});
var scssConfig = isProduction ? scssProd : scssDev;
var cssConfig = isProduction ? cssProd : cssDev;
module.exports = {
entry: {
app: './src/app.js',
contact: './src/contact.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
},
{
test: /\.css$/,
use: cssConfig
},
{
test: /\.scss$/,
use: scssConfig
},
{
test: /\.pug$/,
use: ['html-loader', 'pug-html-loader']
},
{
test: /\.(png|jpe?g|svg|gif|webp)$/,
use: [
'file-loader?name=images/[name].[ext]',
// 'file-loader?name=[hash:6].[ext]&publicPath=images/',
'image-webpack-loader?{optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}, mozjpeg: {quality: 65}}'
]
}
]
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 8080,
stats: 'errors-only',
hot: true,
open: true // 启动后自动打开浏览器窗口
},
plugins: [
new ExtractTextPlugin({
filename: (getPath) => {
return getPath('css/[name].css').replace('css/js', 'css');
},
disable: !isProduction,
allChunks: true
}),
new HtmlWebpackPlugin({
title: 'myApp',
// minify: {
// collapseWhitespace: true //生成被压缩的html文件
// },
hash: true,
filename: './index.html',
excludeChunks: ['contact'],
template: './src/index.html', // Load a custom template (ejs by default see the FAQ for details)
}),
new HtmlWebpackPlugin({
title: 'contact',
hash: true,
filename: 'contact.html',
chunks: ['contact'],
template: './src/contact.html'
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin()
]
}