forked from diggsweden/InclusionToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
100 lines (89 loc) · 2.06 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
91
92
93
94
95
96
97
98
99
100
// SPDX-FileCopyrightText: 2023 Digg - Agency for Digital Government
//
// SPDX-License-Identifier: MIT
import path from "path";
import { fileURLToPath } from "url";
import Dotenv from "dotenv-webpack";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import { LicenseWebpackPlugin } from "license-webpack-plugin";
import webpack from 'webpack';
// Convert the module URL to a directory path
const directoryPath = path.dirname(fileURLToPath(import.meta.url));
const config = {
// Development mode for better debugging
mode: "production",
// Entry point of the library
entry: "./src/index.js",
// Output configuration
output: {
path: path.resolve(directoryPath, "dist"),
filename: "InclusionToolbox.js",
library: {
name: "InclusionToolbox",
type: "umd", // Supports CommonJS, AMD and as a browser global
},
globalObject: "this", // Ensures compatibility with both browser and Node.js
},
// Enable source maps
// devtool: "source-map",
module: {
rules: [
{
test: /\.js?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"], // Transpile modern JavaScript
},
},
},
{
test: /\.css$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
modules: {
auto: true,
},
},
},
],
},
{
test: /\.ttf$/,
use: [
{
loader: "url-loader",
options: {
limit: Infinity,
},
},
],
},
],
},
resolve: {
extensions: [".js"],
alias: {
"@embed": path.resolve(directoryPath, "src/embed"),
"@service": path.resolve(directoryPath, "src/service"),
"@util": path.resolve(directoryPath, "src/util"),
},
},
// Optimization settings
optimization: {
usedExports: true, // Enable tree shaking
},
plugins: [
new Dotenv(),
new CleanWebpackPlugin(),
new LicenseWebpackPlugin({}),
new webpack.BannerPlugin({
banner: "Copyright (c) 2023 Digg - Agency for Digital Government. See LICENSE file for details.",
}),
],
};
export default config;