forked from jwplayer/jwplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
150 lines (141 loc) · 4.08 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
'use strict';
/* eslint-env node */
/* eslint no-process-env: 0 */
const webpack = require('webpack');
const env = process.env;
const packageInfo = require('./package.json');
const flashVersion = 18;
function getBuildVersion(build) {
// Build Version: {major.minor.revision}
let metadata = '';
if (env.BUILD_NUMBER) {
const branch = env.GIT_BRANCH;
metadata = 'opensource';
if (branch) {
metadata += '_' + branch.replace(/^origin\//, '').replace(/[^0-9A-Za-z-]/g, '-');
}
metadata += '.' + env.BUILD_NUMBER;
} else {
const now = new Date();
now.setTime(now.getTime() - now.getTimezoneOffset() * 60000);
metadata = 'local.' + now.toISOString().replace(/[.\-:T]/g, '-').replace(/Z|\.\d/g, '');
}
return `${build.version}+${metadata}`;
}
const compileConstants = {
__SELF_HOSTED__: true,
__REPO__: `''`,
__DEBUG__: false,
__BUILD_VERSION__: `'${getBuildVersion(packageInfo)}'`,
__FLASH_VERSION__: flashVersion
};
const uglifyJsOptions = {
screwIE8: true,
stats: true,
mangle: {
toplevel: true,
eval: true,
except: ['export', 'require']
},
sourceMap: true
};
const multiConfig = [
{
name: 'debug',
output: {
path: `${__dirname}/bin-debug/`,
filename: '[name].js',
chunkFilename:'[name].js',
sourceMapFilename : '[name].[hash].map',
library: 'jwplayer',
libraryExport: 'default',
libraryTarget: 'window',
pathinfo: true,
umdNamedDefine: true
},
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin(Object.assign({}, compileConstants, {
__DEBUG__: true
}))
]
},
{
name: 'release',
output: {
path: `${__dirname}/bin-release/`,
filename: '[name].js',
chunkFilename: '[name].js',
library: 'jwplayer',
libraryExport: 'default',
libraryTarget: 'window',
umdNamedDefine: true
},
watch: false,
plugins: [
new webpack.DefinePlugin(compileConstants),
new webpack.optimize.UglifyJsPlugin(uglifyJsOptions)
]
}
].map(configuration =>
Object.assign({}, configuration, {
entry: {
jwplayer: './src/js/jwplayer.js'
},
stats: {
timings: true
},
resolve: {
modules: [
'src/js/',
'src',
'node_modules'
]
},
module: {
rules: [
{
test: /\.less$/,
use: [
'simple-style-loader',
'css-loader',
'postcss-loader',
{
loader: 'less-loader',
options: {
compress: true,
strictMath: true,
noIeCompat: true
}
}
]
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
babelrc: false,
presets: [
['es2015']
],
plugins: [
'transform-object-assign'
]
}
},
{
test: /\.svg$/,
loader: 'svg-inline-loader'
}
]
}
})
).filter(item => !!item);
module.exports = (envArgs) => {
if (!envArgs) {
return multiConfig;
}
const enabledConfig = Object.keys(envArgs).find(envName => envArgs[envName]);
return multiConfig.find(c => c.name === enabledConfig) || multiConfig;
};