forked from zxhnext/web-performance-monitoring
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
66 lines (61 loc) · 1.82 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
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const fileVersion = new Date().getTime()
const isDev = process.env.NODE_ENV === 'development'
const devServer = {
port: 8000,
host: '0.0.0.0',
overlay: {
errors: true
},
headers: { 'Access-Control-Allow-Origin': '*' },
historyApiFallback: { // dev时设置index.html路径,否则history模式下刷新页面路由会请求后段路由
index: '/index.html'
},
// proxy: {
// '/api': 'http://127.0.0.1:3000'
// },
hot: true
}
let config = {
entry: {
monitorjs: ['./src/index.js']
},
mode: 'development',
output: {
path: path.resolve(__dirname, 'dist'), //打包后的文件存放的地方
filename: '[name].min.js', //打包后输出文件的文件名
publicPath: "",
chunkFilename: "[name].min.js",
library: "monitorjs", //类库名称
libraryTarget: "umd", //指定输出格式
umdNamedDefine: true //会对UMD的构建过程中的AMD模块进行命名,否则就使用匿名的define
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
]
},
plugins: [
new CleanWebpackPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: isDev ? '"development"' : '"production"'
},
fileVersion:fileVersion //文件版本
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "./test/index.html")
})
]
}
if (isDev) {
config.devServer = devServer
}
module.exports = config