-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
73 lines (65 loc) · 1.88 KB
/
webpack.config.js
File metadata and controls
73 lines (65 loc) · 1.88 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
/**
* Webpack Configuration for Multi-Block Plugin.
*
* @package
*/
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
const defaultConfig = require('@wordpress/scripts/config/webpack.config');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
// Find all block entry points.
const glob = require('glob');
const blockEntries = {};
const blockDirs = glob.sync('./src/blocks/*/index.js');
blockDirs.forEach((blockPath) => {
const blockName = path.basename(path.dirname(blockPath));
blockEntries[`blocks/${blockName}/index`] = path.resolve(
process.cwd(),
blockPath
);
});
// Find all JS files in src/js directory.
const jsEntries = {};
const jsDirs = glob.sync('./src/js/**/*.js');
jsDirs.forEach((jsPath) => {
const relativePath = path.relative('./src/js', jsPath);
const entryName = relativePath.replace(/\.js$/, '');
jsEntries[`js/${entryName}`] = path.resolve(process.cwd(), jsPath);
});
module.exports = {
...defaultConfig,
entry: {
index: path.resolve(process.cwd(), 'src', 'index.js'),
...blockEntries,
...jsEntries,
},
output: {
filename: '[name].js',
path: path.resolve(process.cwd(), 'build'),
},
resolve: {
...defaultConfig.resolve,
alias: {
...(defaultConfig.resolve?.alias || {}),
'@': path.resolve(process.cwd(), 'src'),
'@blocks': path.resolve(process.cwd(), 'src', 'blocks'),
'@components': path.resolve(process.cwd(), 'src', 'components'),
'@hooks': path.resolve(process.cwd(), 'src', 'hooks'),
'@utils': path.resolve(process.cwd(), 'src', 'utils'),
},
},
plugins: [
...defaultConfig.plugins,
new CopyWebpackPlugin({
patterns: [
{
from: 'src/blocks/*/render.php',
to: ({ context, absoluteFilename }) => {
const blockName = path.basename(path.dirname(absoluteFilename));
return `blocks/${blockName}/render.php`;
},
},
],
}),
],
};