-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
28 lines (24 loc) · 824 Bytes
/
Copy pathwebpack.config.js
File metadata and controls
28 lines (24 loc) · 824 Bytes
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
// webpack.config.js
const defaultConfig = require('@wordpress/scripts/config/webpack.config');
const path = require('path');
const glob = require('glob');
// Find all block folders
const blockFolders = glob.sync('./assets/src/blocks/*').filter(folder =>
require('fs').existsSync(path.join(folder, 'block.json')),
);
// Create entries for each block
const entries = blockFolders.reduce((acc, blockPath) => {
const blockName = path.basename(blockPath);
acc[`blocks/${blockName}/index`] = `./${path.relative('.', blockPath)}/index.js`;
return acc;
}, {});
// Add admin entry
entries['admin/index'] = './assets/src/admin/admin.js';
module.exports = {
...defaultConfig,
entry: entries,
output: {
path: path.resolve(process.cwd(), 'assets/build'),
filename: '[name].js',
},
};