forked from Automattic/newspack-blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
66 lines (56 loc) · 1.78 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
**** WARNING: No ES6 modules here. Not transpiled! ****
*/
/* eslint-disable import/no-nodejs-modules */
/**
* External dependencies
*/
const fs = require( 'fs' );
const getBaseWebpackConfig = require( '@automattic/calypso-build/webpack.config.js' );
const path = require( 'path' );
/**
* Internal dependencies
*/
// const { workerCount } = require( './webpack.common' ); // todo: shard...
/**
* Internal variables
*/
const editorSetup = path.join( __dirname, 'src', 'setup', 'editor' );
const viewSetup = path.join( __dirname, 'src', 'setup', 'view' );
function blockScripts( type, inputDir, blocks ) {
return blocks
.map( block => path.join( inputDir, 'blocks', block, `${ type }.js` ) )
.filter( fs.existsSync );
}
const blocksDir = path.join( __dirname, 'src', 'blocks' );
const blocks = fs
.readdirSync( blocksDir )
.filter( block => fs.existsSync( path.join( __dirname, 'src', 'blocks', block, 'editor.js' ) ) );
// Helps split up each block into its own folder view script
const viewBlocksScripts = blocks.reduce( ( viewBlocks, block ) => {
const viewScriptPath = path.join( __dirname, 'src', 'blocks', block, 'view.js' );
if ( fs.existsSync( viewScriptPath ) ) {
viewBlocks[ block + '/view' ] = [ viewSetup, ...[ viewScriptPath ] ];
}
return viewBlocks;
}, {} );
// Combines all the different blocks into one editor.js script
const editorScript = [
editorSetup,
...blockScripts( 'editor', path.join( __dirname, 'src' ), blocks ),
];
const blockStylesScript = [
path.join( __dirname, 'src', 'block-styles', 'view' ),
];
const webpackConfig = getBaseWebpackConfig(
{ WP: true },
{
entry: {
editor: editorScript,
block_styles: blockStylesScript,
...viewBlocksScripts,
},
'output-path': path.join( __dirname, 'dist' ),
}
);
module.exports = webpackConfig;