Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
63 lines (56 loc) · 1.55 KB
/
Copy pathwebpack.config.js
File metadata and controls
63 lines (56 loc) · 1.55 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
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const path = require( 'path' );
const extraEntry = {
index: path.resolve( process.cwd(), 'src', 'index.js' ),
'blocks/terminal/index': path.resolve(
process.cwd(),
'src/blocks/terminal/index.js'
),
'blocks/terminal/view': path.resolve(
process.cwd(),
'src/blocks/terminal/view.js'
),
'blocks/ide/index': path.resolve( process.cwd(), 'src/blocks/ide/index.js' ),
'blocks/ide/view': path.resolve( process.cwd(), 'src/blocks/ide/view.js' ),
'blocks/diagram/index': path.resolve(
process.cwd(),
'src/blocks/diagram/index.js'
),
'blocks/diagram/view': path.resolve(
process.cwd(),
'src/blocks/diagram/view.js'
),
};
function withEntries( config ) {
let entry = extraEntry;
if ( typeof config.entry === 'function' ) {
entry = { ...config.entry(), ...extraEntry };
} else if ( config.entry && typeof config.entry === 'object' ) {
entry = { ...config.entry, ...extraEntry };
}
const plugins = [ ...( config.plugins || [] ) ];
try {
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
plugins.push(
new CopyWebpackPlugin( {
patterns: [
{
from: '**/block.json',
context: path.resolve( process.cwd(), 'src/blocks' ),
to: 'blocks/[path][name][ext]',
},
],
} )
);
} catch ( e ) {
// copy-webpack-plugin ships with @wordpress/scripts; ignore if missing.
}
return {
...config,
entry,
plugins,
};
}
module.exports = Array.isArray( defaultConfig )
? defaultConfig.map( withEntries )
: withEntries( defaultConfig );