-
Notifications
You must be signed in to change notification settings - Fork 15
/
webpack.config.js
executable file
·87 lines (79 loc) · 1.88 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
const webpack = require('webpack')
const path = require('path')
const DirectoryNamedWebpackPlugin = require('directory-named-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const minimize = !!process.env.MINIMIZE
const packageName = 'clappr-stats'
let configurations = []
const webpackConfig = (config) => {
return {
mode: config.mode || 'none',
devtool: config.devtool || 'source-maps',
entry: path.resolve(__dirname, 'src/clappr-stats.js'),
externals: {
'@clappr/core': 'Clappr'
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader'
}
],
},
resolve: {
plugins: [
new DirectoryNamedWebpackPlugin(true),
],
extensions: ['.js']
},
plugins: [
...(config.plugins || [])
],
optimization: config.optimization,
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: 'latest/',
filename: config.filename,
library: 'ClapprStats',
libraryTarget: 'umd',
},
devServer: {
contentBase: 'public/',
host: '0.0.0.0',
disableHostCheck: true,
hot: true
}
}
}
configurations.push(webpackConfig({
filename: `${packageName}.js`,
mode: 'development'
}))
if (minimize) {
console.log('NOTE: Enabled minifying bundle (uglify)')
const loaderOptions = new webpack.LoaderOptionsPlugin({ minimize, debug: !minimize })
const uglify = new UglifyJsPlugin({
uglifyOptions: {
warnings: false,
compress: {},
mangle: true,
sourceMap: true,
comments: false,
output: { comments: false }
},
})
configurations.push(webpackConfig({
filename: `${packageName}.min.js`,
plugins: [
loaderOptions,
],
optimization: {
minimizer: [
uglify,
],
},
mode: 'production'
}))
}
module.exports = configurations