-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.es5.config.js
More file actions
93 lines (85 loc) · 2.6 KB
/
webpack.es5.config.js
File metadata and controls
93 lines (85 loc) · 2.6 KB
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
const path = require("path");
const fs = require("fs");
// Define paths
const DIST_DIR = "dist/donate-frontend";
const BROWSER_DIR = path.join(DIST_DIR, "browser");
const BROWSER_ES5_DIR = path.join(DIST_DIR, "browser-es5");
// Function to recursively find all JS files in a directory
function findJsFiles(dir, fileList = []) {
const files = fs.readdirSync(dir);
files.forEach((file) => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
findJsFiles(filePath, fileList);
} else if (file.endsWith(".js")) {
fileList.push(filePath);
}
});
return fileList;
}
// Find all JS files in the browser directory
const entryFiles = findJsFiles(BROWSER_DIR);
// Create entry object for webpack
const entries = {};
entryFiles.forEach((file) => {
// Get the relative path from the browser directory
const relativePath = path.relative(BROWSER_DIR, file);
// Use the relative path (without .js extension) as the entry name
const entryName = relativePath.replace(/\.js$/, "");
// Add './' prefix to file paths to ensure proper resolution
entries[entryName] = "./" + file;
});
module.exports = {
mode: "production",
entry: entries,
experiments: {
outputModule: false, // Ensure we don't output ES modules
},
output: {
path: path.resolve(__dirname, BROWSER_ES5_DIR),
filename: "[name].js",
// Ensure paths match the original structure
publicPath: "/d-es5/",
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules[\\/]core-js/, // Only exclude core-js as it uses ES modules
use: {
loader: "babel-loader",
options: {
presets: [
[
"@babel/preset-env",
{
targets: {
chrome: "71",
safari: "12.1",
},
useBuiltIns: "usage",
corejs: 3,
modules: false, // Keep modules as ES6, let webpack handle bundling
forceAllTransforms: true, // Force all transforms for maximum compatibility
},
],
],
},
},
},
],
},
optimization: {
// Minimize the output for production
minimize: true,
// Don't split chunks to keep it simple for legacy browsers
splitChunks: false,
// Disable scope hoisting for better ES5 compatibility
concatenateModules: false,
},
// Ensure proper source maps for debugging
devtool: "source-map",
// Target browsers that support ES5
target: ["web", "es5"],
};