-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexternals.js
52 lines (49 loc) · 1.32 KB
/
externals.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
/**
* Utility methods for use when generating build configuration objects.
*/
const { join } = require( 'path' );
/**
* Given a string, returns a new string with dash separators converted to
* camel-case equivalent. This is not as aggressive as `_.camelCase`, which
* which would also upper-case letters following numbers.
*
* @param {string} string Input dash-delimited string.
*
* @return {string} Camel-cased string.
*/
const camelCaseDash = string => string.replace( /-([a-z])/g, ( match, letter ) => letter.toUpperCase() );
/**
* Define externals to load components through the wp global.
*/
const externals = [
'api-fetch',
'url',
'components',
'edit-post',
'element',
'plugins',
'editor',
'block-editor',
'blocks',
'hooks',
'utils',
'date',
'data',
'i18n',
].reduce(
( externals, name ) => ( {
...externals,
[ `@wordpress/${ name }` ]: `wp.${ camelCaseDash( name ) }`,
} ),
{
wp: 'wp',
ga: 'ga', // Old Google Analytics.
gtag: 'gtag', // New Google Analytics.
react: 'React', // React itself is there in Gutenberg.
jquery: 'jQuery', // import $ from 'jquery'; // Use jQuery from WP after enqueuing it.
'react-dom': 'ReactDOM',
lodash: 'lodash', // Lodash is there in Gutenberg.
cgbGlobal: 'cgbGlobal', // import globals from 'cgbGlobal'; // Localized data.
}
);
module.exports = externals;