This repository has been archived by the owner on Oct 10, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5738f69
commit 7f1a247
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* 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 = [ | ||
'components', | ||
'edit-post', | ||
'element', | ||
'plugins', | ||
'editor', | ||
'blocks', | ||
'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 the WordPress version after enqueuing it. | ||
'react-dom': 'ReactDOM', | ||
} | ||
); | ||
|
||
module.exports = externals; |