forked from jwplayer/jwplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
155 lines (147 loc) · 4.42 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
150
151
152
153
154
155
/* jshint node: true */
var webpack = require('webpack');
var env = process.env;
var _ = require('lodash');
var argv = require('minimist')(process.argv.slice(2));
var packageInfo = require('./package.json');
var flashVersion = 11.2;
function getBuildVersion(packageInfo) {
// Build Version: {major.minor.revision}
var metadata = '';
if (env.BUILD_NUMBER) {
var branch = env.GIT_BRANCH;
metadata = 'opensource';
if (branch) {
metadata += '_' + branch.replace(/^origin\//, '').replace(/[^0-9A-Za-z-]/g, '-');
}
metadata += '.' + env.BUILD_NUMBER;
} else {
var now = new Date();
now.setTime(now.getTime()-now.getTimezoneOffset()*60000);
metadata = 'local.' + now.toISOString().replace(/[\.\-:T]/g, '-').replace(/Z|\.\d/g, '');
}
return packageInfo.version +'+'+ metadata;
}
var compileConstants =
{
__SELF_HOSTED__: true,
__REPO__ : '\'\'',
__DEBUG__ : false,
__BUILD_VERSION__: '\'' + getBuildVersion(packageInfo) + '\'',
__FLASH_VERSION__: flashVersion
};
var uglifyJsOptions = {
screwIE8: true,
stats: true,
compress: {
warnings: false
},
mangle: {
toplevel: true,
eval: true,
except: ['export', 'require']
}
};
var multiConfig = _.compact(_.map([
{
name: 'debug',
output: {
path: 'bin-debug/',
filename: '[name].js',
chunkFilename:'[name].js',
sourceMapFilename : '[name].[hash].map',
library: 'jwplayer',
libraryTarget: 'umd',
pathinfo: true
},
debug: true,
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin(_.defaults({
__DEBUG__ : true
}, compileConstants))
]
},
{
name: 'release',
output: {
path: 'bin-release/',
filename: '[name].js',
chunkFilename: '[name].js',
sourceMapFilename : '[name].[hash].map',
library: 'jwplayer',
libraryTarget: 'umd'
},
watch: false,
progress: false,
plugins: [
new webpack.DefinePlugin(compileConstants),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin(uglifyJsOptions)
]
}
], function(configuration) {
// Use `webpack --only {CONFIG_NAME}` to filter out multiple configurations
// ex: `webpack --only debug` will only return and build the debug config
if (argv.only) {
if (configuration.name !== argv.only) {
return;
}
}
return _.defaultsDeep(configuration, {
entry: {
// the array notation is required due to bug in webpack :
// https://github.com/webpack/webpack/issues/300
jwplayer: ['./src/js/jwplayer.js']
},
output: {
// This would allow loading of modules from our CDN
//crossOriginLoading: 'anonymous'
},
umdNamedDefine: true,
stats: {
timings: true
},
devtool: 'cheap-source-map',
resolve: {
modulesDirectories: [
'src/js/',
'src',
'node_modules'
]
},
module: {
loaders: [
{
test: /\.less$/,
loaders: [
'simple-style-loader',
'css',
'autoprefixer?browsers=' + encodeURIComponent('> 1%'),
'less?compress'
]
},
{
test: /\.html$/,
loader: 'handlebars-loader'
},
{
test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader?name=[name].[ext]'
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader?name=[name].[ext]'
}
]
}
});
}));
// When only returning one config, return the object.
// This provides flat webpack output can be opened in the analyze tool.
// Example: `webpack --only debug -j > output.json`
// and open output.json at http://webpack.github.io/analyse/
if (multiConfig.length === 1) {
multiConfig = multiConfig[0];
}
module.exports = multiConfig;