Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically load jQuery on the desktop #27908

Merged
merged 1 commit into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 && [
[
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might have some adverse impact on the sdk? tests seem ok... looks like no one had written a test for code that uses asyncRequire before. @dmsnell @ockham any thoughts on this?

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