forked from AirenSoft/OvenPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·172 lines (161 loc) · 5.47 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const webpack = require('webpack');
const path = require('path');
const env = process.env;
const packageInfo = require('./package.json');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const GitRevisionPlugin = require('git-revision-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
const banner = packageInfo.name + ' | ' +
'(c) ' + new Date().getFullYear() + ' ' + packageInfo.author + ' | MIT license (' +
packageInfo.license + ') | Github : ' +
packageInfo.homepage;
const getBuildVersion = function (build) {
let gitRevisionPlugin = new GitRevisionPlugin();
let status = "";
const generate = function(){
let date = new Date();
const pad = function(n){ // always returns a string
return (n < 10 ? '0' : '') + n;
};
return date.getFullYear() +
pad(date.getMonth() + 1) +
pad(date.getDate()) +
pad(date.getHours())
};
if(env.npm_lifecycle_event && env.npm_lifecycle_event =="watch"){
status = "localbuild";
}else{
status = "rev."+gitRevisionPlugin.version();
}
return `${build.version}-${generate()}-${status}`;
}
const defaultConfig = {
node: {
fs: 'empty'
},
entry: {
'ovenplayer': './src/js/ovenplayer.js',
'ovenplayer.sdk' : './src/js/ovenplayer.sdk.js',
},
resolve: {
modules: [
path.resolve(__dirname, "src/js"),
path.resolve("./node_modules")
]
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
babelrc: false,
plugins: [
"transform-es3-member-expression-literals",
"transform-es3-property-literals",
"transform-object-assign"
],
presets: [
//babel-preset-env is a Babel preset meant to automatically set up babel plugins and include the necessary babel polyfills based on a set of target environments checked against a feature compatibility table.
['env',{
"targets": {"ie": 8},
"debug": true,
"useBuiltIns" : true // polyfill
} ]
]
}
},
{
test: /\.less$/,
use: [
'style-loader',
'css-loader',
{
loader: 'less-loader',
options: {
compress: true,
strictMath: true,
noIeCompat: true
}
}
]
},
{
test: /\.(ttf|eot|svg|gif)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [{
loader: 'url-loader'
}]
},
{
test: /\.(swf)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: path.resolve(__dirname, 'dist/production/ovenplayer')
}
}]
}
]
}
};
const extendConfig = function (){
console.log(env.npm_lifecycle_event );
if(env.npm_lifecycle_event ==="watch"){
Object.assign(defaultConfig, {
mode: 'development',
devtool: 'inline-source-map',
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist/development/ovenplayer')
},
plugins: [
new GitRevisionPlugin(),
new webpack.DefinePlugin({
__VERSION__: `'${getBuildVersion(packageInfo)}'`
}),
new webpack.BannerPlugin(banner),
new BundleAnalyzerPlugin({
analyzerMode: 'disabled'
})
]
});
}else{
Object.assign(defaultConfig, {
mode: 'production',
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
output: {
comments: false
}
},
extractComments: true // /(?:^!|@(?:license|preserve))/i
})
]
},
devtool: false,
output: {
filename: `[name].js`,
hashDigestLength: 7,
chunkFilename: `ovenplayer-[chunkhash].js`,
path: path.resolve(__dirname, 'dist/production/ovenplayer')
},
plugins: [
new GitRevisionPlugin(),
new webpack.DefinePlugin({
__VERSION__: `'${getBuildVersion(packageInfo)}'`
}),
new webpack.BannerPlugin(banner),
new BundleAnalyzerPlugin({
analyzerMode: 'static'
})
]
});
}
return defaultConfig;
}
module.exports = extendConfig();