Webpack make jQuery globally available during development -


i'm writing react app live inside of webpage contains jquery. means need global access jquery during development, not want include bundle on build ( since jquery exist on page deployed ).

i'm having difficulty getting jquery global ( aka accessible anywhere via $ or window.jquery) work. need jquery@1.7.2. here i've done far:

npm install jquery@1.7.2 

then, in webpack.dev.config.js:

plugins: [   new webpack.provideplugin({     $: "jquery",     jquery: "jquery",     "window.jquery": "jquery"   }) ] 

...however, when run dev server (webpack-dev-server) , try use jquery in module, get:

error '$' not defined 

any ideas? main goals are:

  1. should present during development build, not bundled production

  2. should globally accessible component via window object

  3. not have explicitly imported each module ( assume it's global )

after spending time on this, here observations:

  • installing jquery@1.7.2, throws following warning: npm warn deprecated jquery@1.7.2: versions of jquery npm package older 1.9.0 patched versions don't work in web browsers. please upgrade >=1.11.0..

  • trying build bundles using version of jquery fails. don't know how did it, me fails. using webpack@1.13.3

  • i checked source code of jquery downloaded npm install jquery@1.7.2. modified original source. original source code still exists though under jquery/tmp/jquery.js

conclusion

your best bet work doing this, @ point before rest of code:

import 'jquery/tmp/jquery'.

this way file executed, jquery registered window, intended, , can use $ in rest of code.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -