This repository was archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
112 lines (102 loc) · 2.69 KB
/
Copy pathwebpack.config.js
File metadata and controls
112 lines (102 loc) · 2.69 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
// Set from https://www.npmjs.com/package/@wordpress/scripts
// Add package.json with the @wordpress/scripts dependency.
// Add a root file called webpack.config.js
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );
const CopyPlugin = require( 'copy-webpack-plugin' );
// Utilities.
const path = require( 'path' );
const { globSync } = require( 'glob' );
// Import the helper to find and generate the entry points in the src directory
const {
fromProjectRoot,
getWebpackEntryPoints,
getWordPressSrcDirectory,
} = require( '@wordpress/scripts/utils' );
/**
* Processes individual block stylesheets for a specific block namespace. These
* are not imported into the primary stylesheets and are enqueued separately.
*
* @since 1.0.0
* @param {string} folder
* @return {Object.<string, string>}
*/
const blockStylesheets = ( folder ) => {
return globSync( `./resources/scss/${ folder }/**/*.scss` ).reduce(
( files, filepath ) => {
const relativePath = path.relative(
'./resources/scss/${ folder }',
filepath
);
const namespace = path.dirname( relativePath );
const name = path.parse( filepath ).name;
files[ `css/${ folder }/${ namespace }/${ name }` ] = path.resolve(
process.cwd(),
`resources/scss/${ folder }/${ namespace }`,
`${ name }.scss`
);
return files;
},
{}
);
};
// Add any new entry points by extending the webpack config.
module.exports = {
...defaultConfig,
...{
entry: {
...getWebpackEntryPoints(),
...blockStylesheets( 'blocks' ),
...blockStylesheets( 'plugins' ),
'js/editor': path.resolve(
process.cwd(),
'resources/js',
'editor.js'
),
'js/screen': path.resolve(
process.cwd(),
'resources/js',
'screen.js'
),
'css/admin/editor': path.resolve(
process.cwd(),
'resources/scss',
'editor.scss'
),
'css/screen': path.resolve(
process.cwd(),
'resources/scss',
'screen.scss'
),
},
plugins: [
// Include WP's plugin config.
...defaultConfig.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,
} ),
// Copies any assets that don't need to be processed to
// the output folder.
new CopyPlugin( {
patterns: [
{
from: './resources/fonts',
to: './fonts',
},
{
from: './resources/images',
to: './images',
},
{
from: './resources/videos',
to: './videos',
},
],
} ),
],
},
};