forked from Automattic/newspack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
160 lines (151 loc) · 3.32 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
**** 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',
'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'
),
'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'
),
'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'
),
};
// 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,
};
// Fonts handling.
webpackConfig.module.rules.push( {
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
} );
module.exports = webpackConfig;