Closed rivieiraa closed 7 years ago
Ask yourself a question: "Can I use RBT without jQuery?"
Won't manually assigning jQuery on window object work for you?
Bundling JS is a process in nodejs environment that I belive doesn't have window property. So assigning const $ in my file after importing jQuery and importing RBT after that does nothing.
Browserify does file bundling and module wrapping, it doesn't run your code, so it doesn't need to know whether any of your local/global objects exist at the time of bundling; that includes the browser environment variables. Browserify bundles the files that will be run in the browser, and in that environment, there is a window object, therefore doing jQuery import and assigning it on window will work.
You're right that doing a const $ = jQuery won't work. My bad, bad suggestion, but it's a separate one from the window assignment. Let me know when you tried.
You're absolutely right about browser environment. I've tried to import jQuery and made it availabe as window.$ / window.jQuery property, but I'm still getting the same error.
import jQuery from 'jquery'
window.jQuery = jQuery
import ResponsiveToolkit from 'responsive-toolkit'
I have an example of guy doing similar thing. He wants to refactor his angular code into a commonjs module by wrapping it with IIFE and doing module.exports
and getting similar ReferenceError on import. http://stackoverflow.com/questions/39590599/failed-to-pass-a-variable-in-an-iief
Sorry for my bad english.
What you're suggesting here is bundling jQuery along with the library, which is not a solution I can accept.
Technically we could create an additional named export that would return RBT as a function, which would allow you to require jQuery in your app and pass it to RBT to execute with. However, you cannot have a main export
module.exports
and a named oneexports foo
, so to support for use cases, we'd breaking things for people.Won't manually assigning jQuery on window object work for you?