-
Notifications
You must be signed in to change notification settings - Fork 49
/
webpack.config.js
95 lines (87 loc) · 2.6 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
**** WARNING: No ES6 modules here. Not transpiled! ****
*/
/* eslint-disable import/no-nodejs-modules */
/* eslint-disable @typescript-eslint/no-var-requires */
/**
* External dependencies
*/
const fs = require( 'fs' );
const getBaseWebpackConfig = require( 'newspack-scripts/config/getWebpackConfig' );
const path = require( 'path' );
const wizardsDir = path.join( __dirname, 'src', 'wizards' );
// Get files for wizards scripts.
const wizardsScripts = fs
.readdirSync( wizardsDir )
.filter( ( wizard ) =>
fs.existsSync( path.join( __dirname, 'src', 'wizards', wizard, 'index.js' ) )
);
const wizardsScriptFiles = {
'plugins-screen': path.join( __dirname, 'src', 'plugins-screen', 'plugins-screen.js' ),
};
wizardsScripts.forEach( function( wizard ) {
let wizardFileName = wizard;
if ( wizard === 'advertising' ) {
// "advertising.js" might be blocked by ad-blocking extensions.
wizardFileName = 'billboard';
}
wizardsScriptFiles[ wizardFileName ] = path.join(
__dirname,
'src',
'wizards',
wizard,
'index.js'
);
} );
const entry = {
'reader-activation': path.join( __dirname, 'src', 'reader-activation', 'index.js' ),
'reader-auth': path.join( __dirname, 'src', 'reader-activation', 'auth.js' ),
'reader-registration-block': path.join(
__dirname,
'src',
'blocks',
'reader-registration',
'view.js'
),
'my-account': path.join( __dirname, 'includes', 'reader-revenue', 'my-account', 'index.js' ),
admin: path.join( __dirname, 'src', 'admin', 'index.js' ),
'memberships-gate': path.join( __dirname, 'src', 'memberships-gate', 'gate.js' ),
'memberships-gate-metering': path.join( __dirname, 'src', 'memberships-gate', 'metering.js' ),
// Newspack wizard assets.
...wizardsScriptFiles,
blocks: path.join( __dirname, 'src', 'blocks', 'index.js' ),
'memberships-gate-editor': path.join( __dirname, 'src', 'memberships-gate', 'editor.js' ),
'memberships-gate-block-patterns': path.join(
__dirname,
'src',
'memberships-gate',
'block-patterns.js'
),
};
// Get files for other scripts.
const otherScripts = fs
.readdirSync( path.join( __dirname, 'src', 'other-scripts' ) )
.filter( script =>
fs.existsSync( path.join( __dirname, 'src', 'other-scripts', script, 'index.js' ) )
);
otherScripts.forEach( function ( script ) {
entry[ `other-scripts/${ script }` ] = path.join(
__dirname,
'src',
'other-scripts',
script,
'index.js'
);
} );
const webpackConfig = getBaseWebpackConfig(
{
entry,
}
);
// Overwrite default optimisation.
webpackConfig.optimization.splitChunks.cacheGroups.commons = {
name: 'commons',
chunks: 'initial',
minChunks: 2,
};
module.exports = webpackConfig;