-
Notifications
You must be signed in to change notification settings - Fork 141
/
webpack.config.integrations.js
108 lines (101 loc) · 2.34 KB
/
webpack.config.integrations.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
var path = require('path');
var fs = require('fs-extra');
var CompressionPlugin = require('compression-webpack-plugin');
var TerserPlugin = require('terser-webpack-plugin');
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
var files = fs.readdirSync('./integrations');
var isProd = process.env.NODE_ENV === 'production';
var entries = {};
files.forEach(function(file) {
var filePath = './integrations/' + file + '/lib/index.js';
if (!fs.existsSync(filePath)) {
filePath = './integrations/' + file + '/lib/index.ts';
if (!fs.existsSync(filePath)) {
return;
}
}
entries[file] = filePath;
});
var plugins = [
new CompressionPlugin({
cache: true,
deleteOriginalAssets: false
})
];
if (process.env.ANALYZE) {
plugins.push(new BundleAnalyzerPlugin());
}
module.exports = {
entry: entries,
mode: process.env.NODE_ENV || 'development',
devtool: 'source-map',
output: {
filename: '[name]/latest/[name].js',
chunkFilename: 'vendor/[name].[contenthash].js',
path: path.resolve(__dirname, 'build/integrations'),
library: '[name]Integration',
libraryTarget: 'window'
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
ie: '11'
}
}
]
]
}
}
}
]
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
domify: '/node_modules/domify/index.js',
'@segment/analytics.js-integration':
'/node_modules/@segment/analytics.js-integration'
}
},
devServer: {
contentBase: path.resolve(__dirname, 'build')
},
optimization: {
moduleIds: 'hashed',
minimize: isProd,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
ecma: '2015',
mangle: true,
compress: true,
output: {
comments: false
}
}
})
],
splitChunks: {
cacheGroups: {
commons: {
name: 'commons',
chunks: 'all',
minChunks: 2
}
}
}
},
plugins: plugins
};