From 5eb853181515d1648a9c899a18059a2116f1b9fa Mon Sep 17 00:00:00 2001 From: Ben Lowery Date: Wed, 17 Oct 2018 14:08:27 -0400 Subject: [PATCH] Dynamically load jQuery on the desktop --- babel.config.js | 4 +--- client/lib/load-script/index.js | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/babel.config.js b/babel.config.js index 33cdabb2bd3251..f1baaa45f3e108 100644 --- a/babel.config.js +++ b/babel.config.js @@ -3,8 +3,6 @@ const _ = require( 'lodash' ); const path = require( 'path' ); const isCalypsoClient = process.env.CALYPSO_CLIENT === 'true'; -const isCalypsoServer = process.env.CALYPSO_SERVER === 'true'; -const isCalypso = isCalypsoClient || isCalypsoServer; const modules = isCalypsoClient ? false : 'commonjs'; // only calypso should keep es6 modules const codeSplit = require( './server/config' ).isEnabled( 'code-splitting' ); @@ -32,7 +30,7 @@ const config = { [ '@babel/plugin-proposal-class-properties', { loose: true } ], [ '@babel/plugin-transform-classes', { loose: false } ], [ '@babel/plugin-transform-template-literals', { loose: true } ], - isCalypso && [ + [ path.join( __dirname, 'server', diff --git a/client/lib/load-script/index.js b/client/lib/load-script/index.js index 0a3da920e39de5..428532a027015d 100644 --- a/client/lib/load-script/index.js +++ b/client/lib/load-script/index.js @@ -48,7 +48,11 @@ export function loadjQueryDependentScript( url, callback ) { // It needs to be loaded using require and npm package. if ( config.isEnabled( 'desktop' ) ) { debug( `Attaching jQuery from node_modules to window for "${ url }"` ); - window.$ = window.jQuery = require( 'jquery' ); + asyncRequire( 'jquery', $ => { + window.$ = window.jQuery = $; + loadScript( url, callback ); + } ); + return; } if ( window.jQuery ) {