Skip to content

Commit

Permalink
Provide public path to js entry files (#2770)
Browse files Browse the repository at this point in the history
  • Loading branch information
samnajian authored Jul 17, 2024
1 parent e8faab1 commit 8b38839
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 0 additions & 4 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import { setNonce, setBaseURL } from 'api/request';
import wpcomApiMiddleware from 'state/data-layer/wpcom-api-middleware';
import localApiMiddleware from 'lib/local-api-middleware';

// Modify webpack pubilcPath at runtime based on location of WordPress Plugin.
// eslint-disable-next-line no-undef
__webpack_public_path__ = global.wcsPluginData.assetPath;

// We need to lazy load the moment locale files.
// First we try language code with region if it's different then fall back to language code only.
if ( window.i18nLocale && ! [ 'en-US', 'en' ].includes( window.i18nLocale.localeSlug ) ) {
Expand Down
3 changes: 3 additions & 0 deletions client/provide-public-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Modify webpack pubilcPath at runtime based on location of WordPress Plugin.
// eslint-disable-next-line no-undef
__webpack_public_path__ = global.wcsPluginData.assetPath;
10 changes: 8 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ module.exports = {
devtool: isDev ? 'inline-source-map' : false,
cache: true,
entry: {
'woocommerce-services': [ './client/main.js' ],
'woocommerce-services': [
'./client/provide-public-path.js',
'./client/main.js'
],
'woocommerce-services-banner': [ './client/banner.js' ],
'woocommerce-services-admin-pointers': [ './client/admin-pointers.js' ],
'woocommerce-services-new-order-taxjar': [ './client/new-order-taxjar.js' ],
'woocommerce-services-wcshipping-migration-admin-notice': [ './client/wcshipping-migration-admin-notice.js' ],
'woocommerce-services-wcshipping-migration-admin-notice': [
'./client/provide-public-path.js',
'./client/wcshipping-migration-admin-notice.js'
],
},
output: Object.assign(
{},
Expand Down
8 changes: 8 additions & 0 deletions woocommerce-services.php
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,14 @@ public function register_wcshipping_migration_modal() {
$plugin_version = self::get_wcs_version();
wp_register_style( 'wcst_wcshipping_migration_admin_notice', $this->wc_connect_base_url . 'woocommerce-services-wcshipping-migration-admin-notice-' . $plugin_version . '.css', array(), null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
wp_register_script( 'wcst_wcshipping_migration_admin_notice', $this->wc_connect_base_url . 'woocommerce-services-wcshipping-migration-admin-notice-' . $plugin_version . '.js', array(), null );
wp_localize_script(
'wcst_wcshipping_migration_admin_notice',
'wcsPluginData',
array(
'assetPath' => self::get_wc_connect_base_url(),
'adminPluginPath' => admin_url( 'plugins.php' ),
)
);
wp_enqueue_script( 'wcst_wcshipping_migration_admin_notice' );
wp_enqueue_style( 'wcst_wcshipping_migration_admin_notice' );
wp_enqueue_script( 'wc_connect_admin' );
Expand Down

0 comments on commit 8b38839

Please sign in to comment.