forked from radiantmediaplayer/rmp-vast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.production.config.js
95 lines (93 loc) · 2.28 KB
/
webpack.production.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
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const StylelintPlugin = require('stylelint-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const webpack = require('webpack');
const PACKAGE = require('./package.json');
const fs = require('fs');
const { minify } = require('terser');
const terserOptions = {
ecma: 5,
compress: {
defaults: true,
pure_funcs: ['console.log', 'console.dir', 'console.warn']
},
module: false,
mangle: true,
safari10: true
};
module.exports = {
entry: {
'rmp-vast': ['whatwg-fetch', 'promise-polyfill/src/polyfill', './src/js/index.js'],
'rmp-vast.min': ['whatwg-fetch', 'promise-polyfill/src/polyfill', './src/js/index.js']
},
output: {
library: {
name: 'RmpVast',
type: 'window',
export: 'default'
},
filename: '[name].js',
path: path.resolve(__dirname, './dist'),
publicPath: ''
},
mode: 'production',
devtool: 'source-map',
module: {
rules: [
{
test: /\.less$/i,
use: [
// compiles Less to CSS to JavaScript
'style-loader',
// this is for IE11 support
{ loader: 'css-loader', options: { url: false } },
'less-loader'
],
},
{
test: /omid-session-client-v1\.js/,
type: 'asset/source',
},
{
test: /\.js$/,
exclude: [
/node_modules/,
/externals/
],
use: {
loader: 'babel-loader'
}
},
]
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions,
include: /\.min\.js$/,
})
],
},
plugins: [
new CleanWebpackPlugin(),
new StylelintPlugin({
files: './src/less/**/*.less'
}),
new webpack.DefinePlugin({
RMP_VAST_VERSION: JSON.stringify(PACKAGE.version)
}),
{
apply: (compiler) => {
compiler.hooks.afterEmit.tap('AfterEmitPlugin', async () => {
const result = await minify(
fs.readFileSync('./externals/omid/omid-session-client-v1.js', 'utf8'),
terserOptions
);
fs.writeFileSync('./externals/omid/omid-session-client-v1.min.js', result.code, 'utf8');
});
}
}
]
};