Skip to content

Commit

Permalink
Dynamically load jQuery on the desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
blowery committed Oct 17, 2018
1 parent c70d533 commit 5eb8531
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 1 addition & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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',
Expand Down
6 changes: 5 additions & 1 deletion client/lib/load-script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit 5eb8531

Please sign in to comment.