-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbud.config.js
104 lines (92 loc) · 3.15 KB
/
bud.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
/**
* Build configuration for bud.js
*
* @package Demo_Plugin
* @param {import('@roots/bud').Bud} bud
*/
export default async bud => {
/**
* Configuring the output settings of the webpack compilation.
* The 'chunkLoadingGlobal' option customizes the global variable used for managing webpack's chunk loading.
* Setting this to a unique value ('cookiex-cmp') ensures that multiple plugins can operate without
* interfering with each other's chunk loading mechanisms, thereby avoiding runtime conflicts.
*/
bud.config(
{
output: {
chunkLoadingGlobal: 'cookiex-cmp',
path: bud.path('@dist'),
},
}
)
/**
* Sets the base directory for the source files of the project.
* This configuration helps bud.js to resolve the relative paths for entry points and other assets
* by defining 'resources' as the directory where source files are located.
*/
bud.setPath( `@src`, `resources` )
/**
* Defines the entry points for the application.
* Entry points are relative to the '@src' path. Multiple entry points allow for separate bundles
* for different parts of the application, such as front-end and admin sections. Each entry
* comprises JavaScript and Sass files that will be compiled into CSS.
*/
bud.entry(
{
"cookiex-cmp-admin": ['/admin/js/entrypoint.tsx', '/admin/scss/app.scss']
}
)
/**
* Provides an automatic mapping of global variables (like jQuery) to imported modules.
* This configuration ensures that whenever '$' or 'jQuery' are referenced, they are automatically
* resolved to the jQuery module, simplifying the management of common dependencies and avoiding
* the need to import them in every file where they are used.
*/
bud.provide(
{
jquery: ['$', 'jQuery'],
}
)
/**
* Automates the copying of static assets from a specified source folder to a distribution folder.
* The 'from' path is defined as the 'static' directory under the '@src' path, and the 'to' path is
* the 'static' directory under the '@dist' path. 'noErrorOnMissing' set to true prevents the build
* from failing if the source directory is missing, providing robustness in asset handling.
*/
bud.assets(
{
from: bud.path( '@src/static' ),
to: bud.path( '@dist/static' ),
noErrorOnMissing: true,
}
)
/**
* Enables the splitting of code into different chunks based on various criteria to optimize loading times.
* Splitting common dependencies into separate chunks can improve cacheability and reduce the amount of
* code downloaded on initial page loads.
*/
bud.splitChunks()
/**
* Enables minification of the output files when the build is run in production mode.
* Minification reduces the size of the output files, which decreases loading time and improves performance.
*/
bud.minimize( bud.isProduction )
/**
* Compatibility for shadcn components and alias ootb
*/
bud.alias(
{
'@': bud.path( '@src' ),
}
)
bud.eslint
.setFailOnError( bud.isProduction )
.setFailOnWarning( false )
.setFix( true )
bud.use(['@roots/bud-typescript', '@roots/bud-react'])
bud.react.refresh.enable()
bud.assets({
from: bud.path('resources/admin/index.html'),
to: bud.path('@dist/index.html'),
});
}