Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
162 lines (160 loc) · 4.5 KB
/
Copy pathwebpack.config.js
File metadata and controls
162 lines (160 loc) · 4.5 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
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
161
162
/* global __dirname, module */
const webpack = require( 'webpack' ); // to access built-in plugins
const path = require( 'path' );
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const CssMinimizerPlugin = require( 'css-minimizer-webpack-plugin' );
const TerserPlugin = require( 'terser-webpack-plugin' );
module.exports = {
mode: 'production', //development | production
watch: false,
entry: {
admin: [
'./src/admin/index.js',
'./src/admin/sass/accessibility-checker-admin.scss',
],
editorApp: [
'./src/editorApp/index.js',
],
sidebar: [
'./src/sidebar/index.js',
'./src/sidebar/sass/sidebar.scss',
],
issueModal: [
'./src/issueModal/index.js',
'./src/issueModal/sass/issue-modal.scss',
],
frontendHighlighterApp: [
'./src/frontendHighlighterApp/index.js',
'./src/frontendHighlighterApp/sass/app.scss',
],
pageScanner: [
'./src/pageScanner/index.js',
],
emailOptIn: [
'./src/emailOptIn/index.js',
'./src/emailOptIn/sass/email-opt-in.scss',
],
frontendFixes: [
'./src/frontendFixes/index.js',
],
srOnlyFormat: [
'./src/srOnlyFormat/index.js',
'./src/srOnlyFormat/sass/sr-only-format.scss',
],
simplifiedSummaryBlock: [
'./src/simplifiedSummaryBlock/index.js',
'./src/simplifiedSummaryBlock/sass/simplified-summary-block.scss',
],
sharedComponents: {
import: './src/sharedComponents/index.js',
library: {
name: 'edacSharedComponents',
type: 'window',
},
},
},
optimization: {
splitChunks: {
cacheGroups: {
specificScript: {
test: /[\\/]src[\\/]frontendFixes[\\/]/,
name: 'frontendFixes',
chunks: 'all',
},
},
},
minimizer: [
new TerserPlugin( {
parallel: true,
terserOptions: {
mangle: {
reserved: [ '__', '_n', '_x', '_nx' ], // Prevent webpack from using these translation function names and mangling them in the source.
},
keep_fnames: /(__|_n|_x|_nx)$/,
format: {
// Keep `translators:` comments in the built bundles.
comments: /translators:/i,
},
},
} ),
new CssMinimizerPlugin(),
],
},
output: {
filename: '[name].bundle.js',
path: path.resolve( __dirname, 'build' ),
chunkFilename: 'chunks/[name].[chunkhash].js', // Store split bundles in 'chunks' directory
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [ 'babel-loader' ],
},
{
test: /\.(s(a|c)ss)$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
// test for just css files so that they are extracted from css in js.
{
test: /\.css$/i,
use: [ MiniCssExtractPlugin.loader, 'css-loader' ],
},
// SVG loader: import as React component
{
test: /\.svg$/,
issuer: /\.[jt]sx?$/,
use: [ '@svgr/webpack' ],
},
// loader for images (required if css references image files)
{
test: /\.(png|jpg|gif)$/,
type: 'asset/resource',
generator: {
filename: './img/[name][ext]',
},
},
],
},
plugins: [
new webpack.ProgressPlugin(),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin( {
filename: './css/[name].css',
} ),
],
externals: {
// Exclude WordPress core scripts and styles from the build.
'@wordpress/i18n': [ 'wp', 'i18n' ],
'@wordpress/blocks': [ 'wp', 'blocks' ],
'@wordpress/plugins': [ 'wp', 'plugins' ],
'@wordpress/editor': [ 'wp', 'editor' ],
'@wordpress/edit-post': [ 'wp', 'editPost' ],
'@wordpress/element': [ 'wp', 'element' ],
'@wordpress/data': [ 'wp', 'data' ],
'@wordpress/api-fetch': [ 'wp', 'apiFetch' ],
'@wordpress/components': [ 'wp', 'components' ],
'@wordpress/block-editor': [ 'wp', 'blockEditor' ],
'@wordpress/rich-text': [ 'wp', 'richText' ],
'@wordpress/html-entities': [ 'wp', 'htmlEntities' ],
'@wordpress/code-editor': [ 'wp', 'codeEditor' ],
'@wordpress/a11y': [ 'wp', 'a11y' ],
// React ships with WordPress. The automatic JSX runtime configured in
// .babelrc compiles JSX to `react/jsx-runtime` imports, which would
// otherwise put a second copy of React in the bundle (and a copy that
// predates the React 19 that WordPress loads).
//
// Every JSX entry must therefore run on a screen where the
// react-jsx-runtime handle is already loaded. Core's wp-components,
// wp-block-editor and wp-edit-post all depend on it, which covers the
// admin and editor entries here; wp-element alone does not.
react: [ 'React' ],
'react/jsx-runtime': [ 'ReactJSXRuntime' ],
},
};