-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
76 lines (68 loc) · 1.79 KB
/
webpack.config.js
File metadata and controls
76 lines (68 loc) · 1.79 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
/**
* WordPress dependencies
*/
const [
defaultScriptConfig,
defaultModuleConfig,
] = require( '@wordpress/scripts/config/webpack.config' );
/**
* External dependencies
*/
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );
const path = require( 'path' );
/**
* Define your script entrypoints here.
*
* Each entrypoint will be built into its own enqueuable asset.
*
* Blocks are handled separately via the `--package-manifest` flag in @wordpress/scripts
*/
const scriptEntries = {
admin: path.resolve( process.cwd(), 'src/admin/index.ts' ),
editor: path.resolve( process.cwd(), 'src/editor/index.ts' ),
frontend: path.resolve( process.cwd(), 'src/frontend/index.ts' ),
// CSS assets can also be generated.
'global-styles': path.resolve(
process.cwd(),
'src/global-styles/index.scss'
),
};
/**
* Define your Script Module entrypoints here.
*
* Each entrypoint will be built into its own enqueuable asset.
*
* Blocks are handled separately via the `--package-manifest` flag in @wordpress/scripts
*/
const scriptModuleEntries = {
// Example:
'example-module': path.resolve(
process.cwd(),
'src/example-module/index.ts'
),
};
const scriptConfig = {
...defaultScriptConfig,
entry: {
// WordPress stores them in a function.
...defaultScriptConfig.entry(),
...scriptEntries,
},
plugins: [
// Include WP's plugin config.
...defaultScriptConfig.plugins,
// Removes the empty `.js` files generated by webpack but
// sets it after WP has generated its `*.asset.php` file.
new RemoveEmptyScriptsPlugin( {
stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS,
} ),
],
};
const moduleConfig = {
...defaultModuleConfig,
entry: {
...defaultModuleConfig.entry,
...scriptModuleEntries,
},
};
module.exports = [ scriptConfig, moduleConfig ];