-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
59 lines (53 loc) · 1.74 KB
/
webpack.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
const { basename, dirname, resolve } = require( 'path' );
const defaultConfig = require( './node_modules/@wordpress/scripts/config/webpack.config' );
const CopyWebpackPlugin = require( 'copy-webpack-plugin' ); // eslint-disable-line import/no-extraneous-dependencies -- Part of @wordpress/scripts.
module.exports = {
// https://github.com/WordPress/gutenberg/blob/master/packages/scripts/config/webpack.config.js
...defaultConfig,
externals: {
jquery: 'jQuery',
},
// https://webpack.js.org/configuration/entry-context/#context
context: resolve( __dirname, 'js/src' ),
// https://webpack.js.org/configuration/entry-context/#entry
entry: {
blocks: './blocks.ts',
'rest-likes': './index.js',
},
// https://webpack.js.org/configuration/output/
output: {
...defaultConfig.output,
uniqueName: '@wearerequired/rest-likes',
path: resolve( __dirname, 'js/dist' ),
filename: '[name].js',
},
plugins: [
...defaultConfig.plugins,
new CopyWebpackPlugin( {
patterns: [
{
// Copy block.json to build folder with name of block as filename
from: 'blocks/**/block.json',
to( { absoluteFilename } ) {
// Get the block folder name
const blockName = basename( dirname( absoluteFilename ) );
// Output with original extension (.json)
return `./${ blockName }-block[ext]`;
},
noErrorOnMissing: true,
},
{
// Copy index.php to build folder with name of block as filename
from: 'blocks/**/index.php',
to( { absoluteFilename } ) {
// Get the block folder name
const blockName = basename( dirname( absoluteFilename ) );
// Output with original extension (.php)
return `./${ blockName }-block-render[ext]`;
},
noErrorOnMissing: true,
},
],
} ),
],
};