File tree Expand file tree Collapse file tree
packages/cgb-scripts/config Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * Utility methods for use when generating build configuration objects.
3+ */
4+ const { join } = require ( 'path' ) ;
5+
6+ /**
7+ * Given a string, returns a new string with dash separators converted to
8+ * camel-case equivalent. This is not as aggressive as `_.camelCase`, which
9+ * which would also upper-case letters following numbers.
10+ *
11+ * @param {string } string Input dash-delimited string.
12+ *
13+ * @return {string } Camel-cased string.
14+ */
15+ const camelCaseDash = string => string . replace ( / - ( [ a - z ] ) / g, ( match , letter ) => letter . toUpperCase ( ) ) ;
16+
17+ /**
18+ * Define externals to load components through the wp global.
19+ */
20+ const externals = [
21+ 'components' ,
22+ 'edit-post' ,
23+ 'element' ,
24+ 'plugins' ,
25+ 'editor' ,
26+ 'blocks' ,
27+ 'utils' ,
28+ 'date' ,
29+ 'data' ,
30+ 'i18n' ,
31+ ] . reduce (
32+ ( externals , name ) => ( {
33+ ...externals ,
34+ [ `@wordpress/${ name } ` ] : `wp.${ camelCaseDash ( name ) } ` ,
35+ } ) ,
36+ {
37+ wp : 'wp' ,
38+ ga : 'ga' , // Old Google Analytics.
39+ gtag : 'gtag' , // New Google Analytics.
40+ react : 'React' , // React itself is there in Gutenberg.
41+ jquery : 'jQuery' , // import $ from 'jquery' // Use the WordPress version after enqueuing it.
42+ 'react-dom' : 'ReactDOM' ,
43+ }
44+ ) ;
45+
46+ module . exports = externals ;
You can’t perform that action at this time.
0 commit comments