-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
75 lines (72 loc) · 2.04 KB
/
Copy pathwebpack.config.js
File metadata and controls
75 lines (72 loc) · 2.04 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
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const path = require( 'path' );
const defaultSplitChunks = defaultConfig.optimization?.splitChunks ?? {};
const defaultCacheGroups = defaultSplitChunks.cacheGroups ?? {};
const plugins = ( defaultConfig.plugins ?? [] ).map( ( plugin ) => {
if ( plugin instanceof MiniCssExtractPlugin ) {
return new MiniCssExtractPlugin( {
...plugin.options,
chunkFilename: '[name].[contenthash:8].css',
ignoreOrder: true,
} );
}
return plugin;
} );
module.exports = {
...defaultConfig,
cache: {
type: 'filesystem',
buildDependencies: {
config: [ __filename ],
},
},
entry: {
index: path.resolve( process.cwd(), 'src/block/index.tsx' ),
frontend: path.resolve( process.cwd(), 'src/frontend/index.ts' ),
admin: path.resolve( process.cwd(), 'src/admin/index.tsx' ),
'admin-commands': path.resolve( process.cwd(), 'src/admin/commands.ts' ),
},
plugins,
output: {
...defaultConfig.output,
// Keep async asset URLs unique across plugin updates so browsers do not
// reuse stale lazy chunks with a newer entry bundle.
chunkFilename: '[name].[contenthash:8].js',
clean: true,
},
optimization: {
...defaultConfig.optimization,
splitChunks: {
...defaultSplitChunks,
cacheGroups: {
...defaultCacheGroups,
default: false,
defaultVendors: false,
mapRuntimeVendor: {
test: /[\\/]node_modules[\\/](maplibre-gl|lucide-react|@wordpress[\\/]icons)[\\/]/,
name: 'map-runtime-vendor',
chunks: ( chunk ) => chunk.name === 'map-runtime',
enforce: true,
priority: 40,
},
adminDataviews: {
test: /[\\/]node_modules[\\/]@wordpress[\\/]dataviews[\\/]/,
name: 'admin-dataviews',
chunks: 'async',
enforce: true,
priority: 30,
},
sharedVendor: {
test: /[\\/]node_modules[\\/]/,
name: 'shared-vendor',
chunks: 'async',
minChunks: 2,
priority: 10,
reuseExistingChunk: true,
},
},
},
},
performance: false,
};