-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.build.config.js
77 lines (71 loc) · 2.3 KB
/
webpack.build.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
var path=require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var config = {
//打包入口文件
entry: {
/* basic_demo:'./src/basic_demo.js',
ajax_demo:'./src/ajax_demo.js',
refs_demo:'./src/refs_demo.js',*/
index:'./src/js/react-router_demo.js',
},
/*
* path:输出到根目录
* filename:输出的文件名
* */
output: {
path: 'dist/',
publicPath:'/',
filename: 'js/[name].js',
chunkFilename: "js/[id].chunk.js"
},
module: {
loaders: [
{
test: /\.js|jsx$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
},
{ test: /\.css$/, loader: ExtractTextPlugin.extract("style", "css") },
{ test: /\.html$/, loader: "html" },
{ test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192&name=./img/[hash].[ext]' }
]
},
plugins:[
new webpack.ProvidePlugin({ //加载jq
$: 'jquery'
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new ExtractTextPlugin("css/[name].css"), //单独使用style标签加载css并设置其路径
new webpack.optimize.UglifyJsPlugin({ //压缩代码
compress: {
warnings: false
},
except: ['$super', '$', 'exports', 'require'] //排除关键字
}),
new HtmlWebpackPlugin({ //根据模板插入css/js等生成最终HTML
/*favicon:'./src/img/favicon.ico', //favicon路径*/
filename:'view/index.html', //生成的html存放路径,相对于 path
template:'./src/view/index.html', //html模板路径
inject:true, //允许插件修改哪些内容,包括head与body
hash:true, //为静态资源生成hash值
minify:{ //压缩HTML文件
removeComments:true, //移除HTML中的注释
collapseWhitespace:true //删除空白符与换行符
}
})
],
resolve:{
alias:{
}
}
}
module.exports = config;