-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
37 lines (32 loc) · 975 Bytes
/
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
import { sync as globSync } from 'glob';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const entryFiles = globSync('./assets/js/**/*.js');
console.log(entryFiles);
const makeRelativePath = (absolutePath) => {
const relativePath = path.relative(process.cwd(), absolutePath);
return './' + relativePath.replace(/\\/g, '/');
};
export default {
mode: 'production',
entry: entryFiles.reduce((acc, filePath) => {
const entryKey = path.basename(filePath, '.js');
const formattedPath = makeRelativePath(path.resolve(process.cwd(), filePath));
acc[entryKey] = formattedPath;
return acc;
}, {}),
output: {
filename: '[name].bundle.js', // Use [name] to output individual files per entry
path: path.resolve(__dirname, 'dist'),
},
devServer: {
static: {
directory: path.join(__dirname, '/'),
},
port: 8080,
hot: true,
open: true,
},
};