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:
should present during development build, not bundled production
should globally accessible component via window object
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
jqueryfails. don't know how did it, me fails. usingwebpack@1.13.3i checked source code of
jquerydownloadednpm install jquery@1.7.2. modified original source. original source code still exists though underjquery/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
Post a Comment