-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.config.babel.js
117 lines (110 loc) · 2.37 KB
/
webpack.config.babel.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
import { join } from 'path';
import merge from 'webpack-merge';
// eslint-disable-next-line import/no-extraneous-dependencies
import TerserPlugin from 'terser-webpack-plugin';
import ESLintPlugin from 'eslint-webpack-plugin';
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';
import CopyPlugin from 'copy-webpack-plugin';
const include = join(__dirname, 'src');
const baseConfig = {
entry: './src/index',
output: {
filename: 'vezgo.js',
},
mode: 'production',
optimization: {
minimize: false,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
},
module: {
rules: [
{ test: /\.js$/, loader: 'babel-loader', include },
],
},
plugins: [
new CopyPlugin({
patterns: [
{
from: './src/index.d.ts',
to: 'vezgo.d.ts',
},
],
}),
],
};
const browserConfig = merge(baseConfig, {
output: {
library: {
name: 'Vezgo',
type: 'window',
},
},
plugins: [
new NodePolyfillPlugin(),
],
});
const browserMinifiedConfig = merge(browserConfig, {
devtool: 'source-map',
output: {
filename: 'vezgo.min.js',
},
optimization: {
minimize: true,
},
plugins: [
new CopyPlugin({
patterns: [
{
from: './src/index.d.ts',
to: 'vezgo.min.d.ts',
},
],
}),
],
});
const browserES5Config = merge(baseConfig, {
output: {
filename: 'vezgo.es5.js',
library: {
type: 'umd',
},
globalObject: 'this', // workaround webpack using 'self' by default
},
plugins: [
new NodePolyfillPlugin(),
new CopyPlugin({
patterns: [
{
from: './src/index.d.ts',
to: 'vezgo.es5.d.ts',
},
],
}),
],
});
const commonJsConfig = merge(baseConfig, {
output: {
path: join(__dirname, 'lib'),
library: {
type: 'umd',
},
},
plugins: [
// Have eslint here so it only run once instead of once for each build config
new ESLintPlugin(),
],
target: 'node',
});
module.exports = [
// Browser build to be included directly in a frontend page (exposed as `window.Vezgo`)
browserConfig, // dist/vezgo.js
browserMinifiedConfig, // dist/vezgo.min.js
// Browser build to be imported in a build system
browserES5Config, // dist/vezgo.es5.js
// Commonjs build for NodeJS
commonJsConfig, // lib/vezgo.js
];