-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
69 lines (63 loc) · 1.85 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
67
68
69
/**
**** WARNING: No ES6 modules here. Not transpiled! ****
*/
/* eslint-disable import/no-nodejs-modules, @typescript-eslint/no-var-requires */
/**
* External dependencies
*/
const fs = require( 'fs' );
const getBaseWebpackConfig = require( 'newspack-scripts/config/getWebpackConfig' );
const path = require( 'path' );
const IgnoreEmitPlugin = require( 'ignore-emit-webpack-plugin' );
/**
* Internal variables
*/
const editor = path.join( __dirname, 'src', 'js', 'editor' );
const frontEndDir = path.join( __dirname, 'src', 'js', 'front-end' );
const frontEnd = fs
.readdirSync( frontEndDir )
.filter( asset => /.(j|t)sx?$/.test( asset ) )
.reduce(
( acc, filename ) => ( {
...acc,
[ filename.replace( /\.[^/.]+$/, '' ) ]: path.join(
__dirname,
'src',
'js',
'front-end',
filename
),
} ),
{}
);
const blocks = fs
.readdirSync( path.join( __dirname, 'includes', 'blocks' ) )
.reduce( ( acc, asset ) => {
if ( fs.lstatSync( path.join( __dirname, 'includes', 'blocks', asset ) ).isDirectory() ) {
fs.readdirSync( path.join( __dirname, 'includes', 'blocks', asset ) )
.filter( file => /\.(j|t)sx?$/.test( file ) )
.forEach( file => {
const name = file.replace( /\.[^/.]+$/, '' );
acc[ `${ asset }-${ name }` ] = path.join( __dirname, 'includes', 'blocks', asset, file );
} );
}
return acc;
}, {} );
const webpackConfig = getBaseWebpackConfig(
{ WP: true },
{
entry: { editor, ...frontEnd, ...blocks },
'output-path': path.join( __dirname, 'dist' ),
}
);
const style = path.join( __dirname, 'src', 'scss', 'style.scss' );
const styleConfig = getBaseWebpackConfig(
{ WP: false },
{
entry: { style },
'output-path': __dirname,
}
);
// Don't emit useless JS module files from the style config.
styleConfig.plugins.push( new IgnoreEmitPlugin( /\.js$/ ) );
module.exports = [ webpackConfig, styleConfig ];