-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
80 lines (80 loc) · 3.14 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
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack =require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
entry: './start.js',
devtool: 'inline-source-map',
output: {
filename: 'js/[chunkhash].js',
path: path.resolve(__dirname,'dist'),
// publicPath: 'dist/',
// sourceMapFilename: '[name].map'
},
plugins: [
new CleanWebpackPlugin(['dist']), // 清理文件
new HtmlWebpackPlugin({ // 模板文件
template: "./src/index.html",
filename: "index.html",
minify: { // 压缩html代码
removeComments: true, // 移除HTML中的注释
collapseWhitespace: true // 删除空白符与换行符
}
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false, // 最紧凑的输出
comments: false, // 删除所有注释
compress: {
warnings: false, // 在UglifyJs删除没有用到的代码时不输出警告
drop_console: true, // 删除所有的 'console'语句
collapse_vars: true, // 内嵌定义了但是只用到一次的变量
reduce_vars: true, // 提取出出现多次但是没有定义成变量去引用的静态值
},
}),
new ExtractTextPlugin({ // 独立打包css文件
filename: (getPath) =>{
return getPath('css/[chunkhash].css').replace('css/js','css');
},
allChunks: true
}),
new CopyWebpackPlugin([ // 拷贝资源文件
// { from: __dirname+'/src/audio/', to: 'audio/', toType:'dir'},
// { from: __dirname+'/Readme.md',to: 'Readme.md'}
]),
],
module: {
loaders: [
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.(png|jpg|jpeg|gif)$/,
loader: 'url-loader?limit=8192&name=img/[hash:8].[ext]'
},
{
test: /\.css$/, // 独立打包css文件
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use:[
{
loader:'css-loader',
options:{
minimize: true, // 启用压缩
}
}
]
})
},
{ // 独立打包字体文件
test: /\.(woff|woff2|otf|eot|svg|ttf)$/i,
loader: 'file-loader?name=./font/[name].[ext]'
}
]
},
devServer: {
contentBase: './src'
}
};