-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathwebpack.config.js
More file actions
109 lines (99 loc) · 5.18 KB
/
webpack.config.js
File metadata and controls
109 lines (99 loc) · 5.18 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
**** 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' ) ) ||
fs.existsSync( path.join( __dirname, 'src', 'wizards', wizard, 'index.tsx' ) )
);
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,
fs.existsSync( path.join( __dirname, 'src', 'wizards', wizard, 'index.tsx' ) ) ? 'index.tsx' : 'index.js'
);
} );
const entry = {
'reader-activation': path.join( __dirname, 'src', 'reader-activation', 'index.js' ),
'reader-auth': path.join( __dirname, 'src', 'reader-activation-auth', 'index.js' ),
'newsletters-signup': path.join( __dirname, 'src', 'reader-activation-newsletters', 'index.js' ),
'reader-registration-block': path.join( __dirname, 'src', 'blocks', 'reader-registration', 'view.js' ),
'correction-box-block': path.join( __dirname, 'src', 'blocks', 'correction-box', 'index.js' ),
'correction-item-block': path.join( __dirname, 'src', 'blocks', 'correction-item', 'index.js' ),
'content-gate-countdown-block': path.join( __dirname, 'src', 'blocks', 'content-gate', 'countdown', 'view.js' ),
'overlay-menu-block': path.join( __dirname, 'src', 'blocks', 'overlay-menu', 'view.js' ),
'content-gate-countdown-box-block': path.join( __dirname, 'src', 'blocks', 'content-gate', 'countdown-box', 'index.js' ),
'contribution-meter-block': path.join( __dirname, 'src', 'blocks', 'contribution-meter', 'index.js' ),
'avatar-block': path.join( __dirname, 'src', 'blocks', 'avatar', 'index.js' ),
'my-account-button-block': path.join( __dirname, 'src', 'blocks', 'my-account-button', 'index.js' ),
'my-account': path.join( __dirname, 'src', 'my-account', 'index.js' ),
'my-account-v0': path.join( __dirname, 'src', 'my-account', 'v0', 'index.js' ),
'my-account-v1': path.join( __dirname, 'src', 'my-account', 'v1', 'index.js' ),
'account-frontend': path.join( __dirname, 'src', 'my-account', 'v1', 'frontend.js' ),
admin: path.join( __dirname, 'src', 'admin', 'index.js' ),
'content-gate': path.join( __dirname, 'src', 'content-gate', 'gate.js' ),
'content-gate-metering': path.join( __dirname, 'src', 'content-gate', 'metering.js' ),
'indesign-export': path.join( __dirname, 'src', 'indesign-export', 'index.js' ),
// Newspack wizard assets.
...wizardsScriptFiles,
blocks: path.join( __dirname, 'src', 'blocks', 'index.js' ),
'content-gate-editor': path.join( __dirname, 'src', 'content-gate', 'editor', 'editor.js' ),
'content-gate-editor-memberships': path.join( __dirname, 'src', 'content-gate', 'editor', 'memberships.js' ),
'content-gate-editor-metering': path.join( __dirname, 'src', 'content-gate', 'editor', 'metering-settings.js' ),
'content-gate-block-patterns': path.join( __dirname, 'src', 'content-gate', 'editor', 'block-patterns.js' ),
'content-gate-block-visibility': path.join( __dirname, 'src', 'content-gate', 'editor', 'block-visibility.tsx' ),
'content-gate-post-settings': path.join( __dirname, 'src', 'content-gate', 'editor', 'post-settings.js' ),
'content-banner': path.join( __dirname, 'src', 'content-gate', 'content-banner.js' ),
wizards: path.join( __dirname, 'src', 'wizards', 'index.tsx' ),
'newspack-ui': path.join( __dirname, 'src', 'newspack-ui', 'index.js' ),
bylines: path.join( __dirname, 'src', 'bylines', 'index.js' ),
'nicename-change': path.join( __dirname, 'src', 'nicename-change', 'index.js' ),
'collections-admin': path.join( __dirname, 'src', 'collections', 'admin', 'index.js' ),
'collections-frontend': path.join( __dirname, 'src', 'collections', 'frontend', 'index.js' ),
'group-subscription-admin': path.join( __dirname, 'src', 'group-subscription', 'admin.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,
} );
webpackConfig.output.chunkFilename = '[name].[contenthash].js';
// Overwrite default optimisation.
webpackConfig.optimization.splitChunks.cacheGroups.commons = {
name: 'commons',
chunks: 'initial',
minChunks: 2,
};
// Fonts handling.
webpackConfig.module.rules.push( {
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
} );
module.exports = webpackConfig;