-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
47 lines (42 loc) · 1.15 KB
/
webpack.config.js
File metadata and controls
47 lines (42 loc) · 1.15 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
const fs = require( 'fs' );
const path = require( 'path' );
/**
* WordPress dependencies.
*/
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const { camelCaseDash } = require( '@wordpress/dependency-extraction-webpack-plugin/lib/util' );
const PACKAGES_DIR = path.resolve( __dirname, 'packages' );
/**
* Retrieves an array of plugin package names from the packages directory.
* Filters for directories that contain an index.js file.
*
* @type {string[]}
*/
const pluginPackages = fs
.readdirSync( PACKAGES_DIR )
.filter( ( packageName ) => {
const packagePath = path.join( PACKAGES_DIR, packageName );
const indexPath = path.join( packagePath, 'index.js' );
return (
fs.statSync( packagePath ).isDirectory() &&
fs.existsSync( indexPath )
);
} );
module.exports = {
...defaultConfig,
entry: {
...pluginPackages.reduce( ( memo, packageName ) => {
return {
...memo,
[ `${ packageName }/index` ]: {
import: `./packages/${ packageName }`,
library: {
name: [ 'pluginwp', camelCaseDash( packageName ) ],
type: 'window',
},
},
};
}, {} ),
...defaultConfig.entry(),
},
};