-
Notifications
You must be signed in to change notification settings - Fork 59
/
webpack.config.js
83 lines (80 loc) · 2.16 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
import path from 'path';
import webpack from 'webpack';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import pkg from './package.json' with { type: 'json' };
import babelConfig from './babel.config.js';
const { dependencies } = pkg;
function configure(filename, opts = {}) {
const isNode = opts.target.includes('node');
return (env) => ({
entry: `./src/index${isNode ? '' : '-browser'}.ts`,
mode: 'production',
devtool: 'source-map',
module: {
rules: [
{
test: /\.(js|ts)$/,
include: path.resolve(import.meta.dirname, 'src'),
loader: 'babel-loader',
options: { ...babelConfig, browserslistEnv: opts.target.split(':')[1] },
},
],
},
optimization: {
minimize: !isNode,
},
resolve: {
extensions: ['.ts', '.js'],
extensionAlias: { '.js': ['.ts', '.js'] },
fallback: isNode
? {}
: {
buffer: path.resolve(import.meta.dirname, 'node_modules/buffer/index.js'),
child_process: false,
os: false,
path: false,
'fs/promises': false,
url: false,
},
},
plugins: [
...(isNode
? []
: [
new webpack.ProvidePlugin({
process: 'process',
Buffer: ['buffer', 'Buffer'],
}),
]),
...(env.REPORT
? [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: `${filename}.html`,
openAnalyzer: false,
}),
]
: []),
],
output: {
path: path.resolve(import.meta.dirname, 'dist'),
filename,
library: {
name: 'Aeternity',
type: 'umd',
},
},
externals: Object.fromEntries(
Object.keys(dependencies).map((dependency) => [dependency, dependency]),
),
...opts,
});
}
export default [
configure('aepp-sdk.cjs', { target: 'browserslist:node' }),
configure('aepp-sdk.browser.cjs', { target: 'browserslist:browser' }),
configure('aepp-sdk.browser-script.cjs', {
target: 'browserslist:browser',
externals: undefined,
}),
];