Skip to content

Commit

Permalink
Optimize bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
vvasilev- committed Oct 30, 2018
1 parent 30bc1a9 commit ab9fdc4
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 18 deletions.
14 changes: 8 additions & 6 deletions bin/webpack.blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ module.exports = [
path: paths.gutenbergBuildPath,
},
externals: Object.assign( {}, wpPackages.externals, {
'@wordpress/components': 'wp.components',
'@wordpress/blocks': 'wp.blocks',
'@wordpress/editor': 'wp.editor',
'@wordpress/i18n': 'wp.i18n',
'react': [ 'cf', 'vendor', 'react' ],
'react-dom': [ 'cf', 'vendor', 'react-dom' ],
'@wordpress/components': [ 'wp', 'components' ],
'@wordpress/blocks': [ 'wp', 'blocks' ],
'@wordpress/editor': [ 'wp', 'editor' ],
'@wordpress/i18n': [ 'wp', 'i18n' ],
'@carbon-fields/core': 'cf.core',
'lodash': 'lodash'
} )
'lodash': [ 'lodash' ]
} )
} )
];
10 changes: 8 additions & 2 deletions bin/webpack.core.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies.
*/
const webpack = require( 'webpack' );
const merge = require( 'webpack-merge' );

/**
Expand Down Expand Up @@ -29,7 +30,7 @@ module.exports = [
path: paths.gutenbergBuildPath
},
externals: Object.assign( {}, wpPackages.externals, {
'lodash': 'lodash'
'lodash': [ 'lodash' ]
} )
} ),
merge( base, config, {
Expand All @@ -38,6 +39,11 @@ module.exports = [
},
externals: Object.assign( {}, wpPackages.proxyExternals, {
'lodash': [ 'cf', 'vendor', 'lodash' ]
} )
} ),
plugins: [
new webpack.ProvidePlugin( {
'wp.element': '@wordpress/element'
} )
]
} )
];
16 changes: 12 additions & 4 deletions bin/webpack.metaboxes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies.
*/
const webpack = require( 'webpack' );
const merge = require( 'webpack-merge' );

/**
Expand All @@ -15,8 +16,10 @@ const config = {
metaboxes: './packages/metaboxes/index.js'
},
externals: {
'@carbon-fields/core': 'cf.core',
'classnames': [ 'cf', 'vendor', 'classnames' ]
'react': [ 'cf', 'vendor', 'react' ],
'react-dom': [ 'cf', 'vendor', 'react-dom' ],
'classnames': [ 'cf', 'vendor', 'classnames' ],
'@carbon-fields/core': [ 'cf', 'core' ]
}
};

Expand All @@ -26,7 +29,7 @@ module.exports = [
path: paths.gutenbergBuildPath
},
externals: Object.assign( {}, wpPackages.externals, {
'lodash': 'lodash'
'lodash': [ 'lodash' ]
} )
} ),
merge( base, config, {
Expand All @@ -35,6 +38,11 @@ module.exports = [
},
externals: Object.assign( {}, wpPackages.proxyExternals, {
'lodash': [ 'cf', 'vendor', 'lodash' ]
} )
} ),
plugins: [
new webpack.ProvidePlugin( {
'wp.element': '@wordpress/element'
} )
]
} )
];
4 changes: 3 additions & 1 deletion bin/webpack.vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ module.exports = [
path: paths.gutenbergBuildPath
},
externals: Object.assign( {}, wpPackages.externals, {
'lodash': 'lodash'
'lodash': 'lodash',
'react': 'React',
'react-dom': 'ReactDOM'
} )
} ),
merge( base, config, {
Expand Down
8 changes: 6 additions & 2 deletions packages/vendor/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/**
* External dependencies.
*/
import React from 'react';
import ReactDOM from 'react-dom';
import * as compose from '@wordpress/compose';
import * as element from '@wordpress/element';
import * as hooks from '@wordpress/hooks';
import * as i18n from '@wordpress/i18n';
import * as data from '@wordpress/data';
import * as classnames from 'classnames';
import * as _ from 'lodash';

Expand All @@ -20,10 +22,12 @@ if ( ! window.lodash ) {
*/
window.cf = window.cf || {};
window.cf.vendor = [
[ 'react', React ],
[ 'react-dom', ReactDOM ],
[ '@wordpress/compose', compose ],
[ '@wordpress/element', element ],
[ '@wordpress/hooks', hooks ],
[ '@wordpress/i18n', i18n ],
[ '@wordpress/data', data ],
[ 'classnames', classnames ],
[ 'lodash', _ ]
].reduce( ( vendors, [ key, implementation ] ) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/vendor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
"dependencies": {
"@babel/runtime": "^7.0.0",
"@wordpress/compose": "^2.0.2",
"@wordpress/data": "^2.1.2",
"@wordpress/data": "^3.0.0",
"@wordpress/element": "^2.1.1",
"@wordpress/hooks": "^2.0.2",
"@wordpress/i18n": "^3.0.1",
"classnames": "^2.2.6",
"lodash": "^4.17.11",
"react": "^16.5.2",
Expand Down
26 changes: 25 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,21 @@
lodash "^4.17.10"
redux "^4.0.0"

"@wordpress/data@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@wordpress/data/-/data-3.0.0.tgz#2e33ec8dc7baad7f030963f38774d7daf4b06d37"
integrity sha512-aOEZJHW9K+6ZjxkK7Hzq5jOU1l4ph4yhj9s2l3cHMgHQg8fh2sIdxNqKpADd0+qXxFInIWOgNcgH7A0+BUsbog==
dependencies:
"@babel/runtime" "^7.0.0"
"@wordpress/compose" "^2.1.0"
"@wordpress/element" "^2.1.5"
"@wordpress/is-shallow-equal" "^1.1.4"
"@wordpress/redux-routine" "^3.0.3"
equivalent-key-map "^0.2.2"
is-promise "^2.1.0"
lodash "^4.17.10"
redux "^4.0.0"

"@wordpress/date@^2.0.3":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@wordpress/date/-/date-2.0.3.tgz#1ca46d26af2cc953db0cf2e85286954473483f69"
Expand Down Expand Up @@ -1443,6 +1458,15 @@
is-promise "^2.1.0"
rungen "^0.3.2"

"@wordpress/redux-routine@^3.0.3":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@wordpress/redux-routine/-/redux-routine-3.0.3.tgz#882c8a8f350ea50a2ca027a103375a46f1bee5a0"
integrity sha512-wT8GoG0qtwxq8J5g0uYxZYoNcnhQloFvMTkDQsaWWAvaO1wsTaamYbusHc6q7PS+EsS2TioQkZsxTtei6YwBBg==
dependencies:
"@babel/runtime" "^7.0.0"
is-promise "^2.1.0"
rungen "^0.3.2"

"@wordpress/shortcode@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@wordpress/shortcode/-/shortcode-2.0.2.tgz#a297758ae624bf11e82194cfce4ca3a62f6d4da7"
Expand Down Expand Up @@ -3011,7 +3035,7 @@ enhanced-resolve@^4.1.0:
memory-fs "^0.4.0"
tapable "^1.0.0"

equivalent-key-map@^0.2.0, equivalent-key-map@^0.2.1:
equivalent-key-map@^0.2.0, equivalent-key-map@^0.2.1, equivalent-key-map@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/equivalent-key-map/-/equivalent-key-map-0.2.2.tgz#be4d57049bb8d46a81d6e256c1628465620c2a13"
integrity sha512-xvHeyCDbZzkpN4VHQj/n+j2lOwL0VWszG30X4cOrc9Y7Tuo2qCdZK/0AMod23Z5dCtNUbaju6p0rwOhHUk05ew==
Expand Down

0 comments on commit ab9fdc4

Please sign in to comment.