-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
117 lines (108 loc) · 2.69 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
113
114
115
116
117
const webpack = require('webpack')
const OpenBrowserPlugin = require('open-browser-webpack-plugin')
const configSys = require('./build/config')
const UnminifiedWebpackPlugin = require('unminified-webpack-plugin')
const pack = require('./package.json')
const today = new Date().toISOString().substr(0, 10)
let config = {
entry: {
'vue-pagenav': './src/vue-pagenav.js'
},
output: {
path: __dirname + '/dist/', //输出文件目录
filename: '[name].bundle.js', //输出文件名
libraryTarget: 'var',
publicPath: '/'
},
watch: true,
externals: {
'react': 'React',
'react-dom': 'ReactDOM'
},
module: {
loaders: [{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel-loader'
}]
},
devtool: '#eval-source-map',
plugins: [
new webpack.HotModuleReplacementPlugin(),
new OpenBrowserPlugin({ url: 'http://localhost:' + configSys.port })
],
devServer: {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
},
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
watch: true,
port: configSys.port,
proxy: {
'*': {
target: 'http://localhost:' + configSys.devServerPort,
secure: false,
ws: false,
bypass: function (req, res, opt) {
if (
/(\.json|\.jpg|\.png|\.css)$/.test(req.path) ||
/\.bundle\.js/.test(req.path)
) {
console.log('bypass', req.path)
return req.path
}
}
}
}
},
}
if (process.env.NODE_ENV === 'production') {
config.plugins = [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': "'production'"
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
mangle: true,
compress: {
warnings: false, // Suppress uglification warnings
}
}),
new UnminifiedWebpackPlugin(),
new webpack.BannerPlugin(
`
/**
* ${pack.name}
* @version v${pack.version} - ${today}
* @link ${pack.homepage}
* @author ${pack.author.name} (${pack.author.email})
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
`
, { raw: true })
]
config.output = {
path: __dirname + '/dist/', //输出文件目录
filename: '[name].min.js', //输出文件名
libraryTarget: 'umd',
publicPath: '/',
library: 'zPagenav'
}
config.externals = {
react: {
root: 'Vue',
commonjs: 'vue',
commonjs2: 'vue',
amd: 'vue'
}
}
config.devtool = 'source-map'
}
module.exports = config