-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
90 lines (81 loc) · 2.22 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
88
89
90
// Require the path module from Node.js
const path = require("path");
// Base configuration
const baseConfig = {
// The entry point of the package
entry: "./src/index.ts",
// Configuration for module resolution
resolve: {
// Configure fallbacks for Node.js built-in modules
fallback: {
// Fallback for the buffer module, using the buffer module
buffer: require.resolve("buffer/"),
fs: false,
path: false,
},
// Extensions that are used to resolve modules
extensions: [".ts", ".js"],
},
// Configuration for source maps
devtool: "source-map",
// The mode to use for the webpack build
mode: "development",
};
// Base configuration
const baseConfigUmd = {
...baseConfig,
// Configuration for the output file
output: {
// The filename of the output file will be specified in each config
// The path to the output directory, __dirname is the directory of the current module
path: path.resolve(__dirname, "."),
// The type of the exported library
libraryTarget: "window", // for UMD we use window
// The name of the library as it should be exposed in the global scope
library: "aaveAptos",
// The global object in which the library will be assigned to
globalObject: "this",
},
// Configuration for modules
module: {
// Array of rules that are used to find and load modules
rules: [
{
// Regular expression that matches the file extensions that this rule applies to
test: /\.ts$/,
// The loader that should be used for the files that match the test regular expression
loader: "ts-loader",
// A condition that must not be met to use this rule
exclude: /node_modules/,
options: {
configFile: "tsconfig.commonjs.json",
},
},
],
},
};
// Export the webpack configuration object
module.exports = [
// UMD minified
{
...baseConfigUmd,
output: {
...baseConfigUmd.output,
filename: "bundle.min.js",
},
optimization: {
minimize: true,
},
},
// UMD - non-minified
{
...baseConfigUmd,
output: {
...baseConfigUmd.output,
filename: "bundle.js",
},
optimization: {
minimize: false,
},
},
];