-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
43 lines (39 loc) · 1.1 KB
/
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
38
39
40
41
42
43
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const path = require( 'path' );
// eslint-disable-next-line import/no-extraneous-dependencies
const glob = require( 'glob' );
const fs = require( 'fs' );
/**
* Generates an object of file entries based on the provided paths.
*
* @param {string[]} paths - An array of file paths.
* @return {Object} - An object containing file entries.
*/
const fileEntries = ( paths ) => {
const entries = {};
paths.forEach( function ( dirPath ) {
const name = dirPath
.split( '/' )
.filter( ( value ) => value !== '.' && value !== 'src' )
.join( '/' );
if ( ! name.startsWith( '_' ) ) {
const indexFile = [ 'index.tsx', 'index.ts', 'index.js' ]
.map( ( fileName ) => path.join( dirPath, fileName ) )
.find( ( filePath ) => fs.existsSync( filePath ) );
if ( indexFile ) {
entries[ `${ name }/index` ] = path.resolve(
process.cwd(),
indexFile
);
}
}
} );
return entries;
};
module.exports = {
...defaultConfig,
entry: {
...defaultConfig.entry(),
...fileEntries( glob.sync( './src/*' ) ),
},
};