Skip to content

Commit

Permalink
Add lodash as a vendor dependency
Browse files Browse the repository at this point in the history
The @wordpress/wp-url package now requires lodash as a dependency. The lodash package is not available in WP 4.9 so we will have to register it ourselves.
  • Loading branch information
pierlon committed Mar 20, 2020
1 parent c1f9d59 commit c2fbf09
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 6 deletions.
14 changes: 14 additions & 0 deletions includes/amp-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,20 @@ function amp_register_default_scripts( $wp_scripts ) {
}
}

$vendor_scripts = [
'lodash' => [
'dependencies' => [],
'version' => '4.17.15',
],
];
foreach ( $vendor_scripts as $handle => $handle_data ) {
if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
$path = amp_get_asset_url( sprintf( 'js/vendor/%s.js', $handle ) );

$wp_scripts->add( $handle, $path, $handle_data['dependencies'], $handle_data['version'], 1 );
}
}

// AMP Runtime.
$handle = 'amp-runtime';
$wp_scripts->add(
Expand Down
129 changes: 123 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"babel-plugin-inline-react-svg": "1.1.1",
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
"browserslist": "4.10.0",
"copy-webpack-plugin": "5.1.1",
"core-js": "3.6.4",
"cross-env": "7.0.2",
"css-loader": "3.4.2",
Expand Down
7 changes: 7 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
const path = require( 'path' );
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const OptimizeCSSAssetsPlugin = require( 'optimize-css-assets-webpack-plugin' );
const RtlCssPlugin = require( 'rtlcss-webpack-plugin' );
Expand Down Expand Up @@ -198,6 +199,12 @@ const wpPolyfills = {
}
},
} ),
new CopyWebpackPlugin( [
{
from: 'node_modules/lodash/lodash.js',
to: './vendor/lodash.js',
},
] ),
new WebpackBar( {
name: 'WordPress Polyfills',
color: '#21a0d0',
Expand Down

0 comments on commit c2fbf09

Please sign in to comment.