-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.config.js
83 lines (73 loc) · 2 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
var webpack = require('webpack')
var path = require('path')
const ENV = process.env.npm_lifecycle_event
const HtmlWebpackPlugin = require('html-webpack-plugin')
const pkg = require('./package.json')
var filename
var publicPath
switch(ENV){
case 'dev':
filename = 'scripts/danmaku-player.js'
publicPath = '../dist/'
break;
case 'pro':
filename = 'scripts/danmaku-player.min.js'
publicPath = `//unpkg.com/danmaku-player@${pkg.version}/dist/`
break;
case 'site':
filename = 'scripts/danmaku-player.min.js'
publicPath = `//unpkg.com/danmaku-player@${pkg.version}/dist/`
break;
}
module.exports = {
entry: './src/index.js',
output: {
path: __dirname+'/dist/'
,filename
,library: 'danmaku-player'
,libraryTarget: 'umd'
,publicPath
}
,devtool: ENV==='dev'?'source-map':''
,module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
loader: 'babel-loader'
},
{
test: /[\\|\/]_[\S]*\.(css|less)$/,
use: [
'to-string-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: ()=>[require('autoprefixer')]
}},
'less-loader'
]
}
,{
test: /\.(png|jpg|jpeg|gif|webp)$/,
use: [
'url-loader?limit=0'
]
}
]
},
plugins: [
new webpack.BannerPlugin(" "+require('./package.json').name+" v"+require('./package.json').version+"\r\n By https://github.com/dwqdaiwenqi \r\n Github: https://github.com/dwqdaiwenqi/danmaku-player\r\n MIT Licensed.")
,new webpack.DefinePlugin({
__DEV__: JSON.stringify(process.env.npm_lifecycle_event)
,__VERSION__: JSON.stringify(require('./package.json').version)
})
,new HtmlWebpackPlugin({
template: './src/example/index.html',
filename: '../example/index.html',
inject: 'head',
__DEV__: JSON.stringify(process.env.npm_lifecycle_event)
})
]
}