-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.base.js
96 lines (94 loc) · 2.87 KB
/
webpack.config.base.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
var webpack = require("webpack");
var path = require('path');
var HtmlwebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
entry: {
index: './src/main.js',
vendors: ['vue', 'vue-router', 'vue-resource', 'vuex', 'fastclick'],
},
output: {
path: path.join(__dirname, './build'),
filename: 'js/[name].[chunkhash:8].js',
chunkFilename: 'js/[name].[chunkhash:16].js'
},
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
headers: {
'Access-Control-Allow-Origin': '*'
},
//只要配置dev server map这个参数就可以了
proxy: {
'/api/*': {
target: 'localhost:8080',
secure: false
}
}
},
resolve: {
extensions: ['', '.js', '.vue'],
alias: {
components: path.join(__dirname, './src/components')
}
},
//babel重要的loader在这里
module: {
loaders: [
// 解析.vue文件
{
test: /\.vue$/,
loader: 'vue'
},
// 转化ES6的语法
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
},
//html模板编译?
{
test: /\.(html|tpl)$/,
loader: 'html-loader'
},
{
test: /\.(png|jpg|gif)$/,
loader: 'url-loader',
query: {
limit: 8192,
name: './images/[name].[ext]?[hash:8]'
}
}
]
},
// 转化成es5的语法
babel: {
presets: ['es2015', 'stage-0'],
plugins: ['transform-runtime', ['component', [{
'libraryName': 'mint-ui',
'style': true
}]]]
},
// babel: {
// presets: ['es2015'],
// plugins: ['transform-runtime']
// },
plugins: [
new HtmlwebpackPlugin({
title: 'My first react app',
template: './index.html',
filename: 'index.html',
chunks: ['index', 'vendors'],
inject: true
}),
// new webpack.HotModuleReplacementPlugin({
// multiStep: true
// }),
new webpack.optimize.CommonsChunkPlugin('vendors', 'js/vendors.js'),
new webpack.optimize.OccurenceOrderPlugin(), //为组件分配ID,通过这个插件webpack可以分析和优先考虑使用最多的模块,并为它们分配最小的ID
new webpack.NoErrorsPlugin(), //报错但不退出webpack进程
new webpack.BannerPlugin('vue')
]
}