Jqeury as $ in latest quasar version



  • In prior Quasar versions, we modified webpack.base.conf.js and added:

    new webpack.ProvidePlugin({
       $: "jquery",
       jQuery: "jquery"
    })
    

    …and all was well.

    In the latest Quasar version, if we add jQuery as a plugin and export as $, node modules that use jQuery as $ error with either ‘$ is not defined’ or ‘$ is not a function’. We also tried setting window.$ and that did not seem to work either.

    Has anyone had any success getting node_modules using jQuery as $ working with the latest quasar (cli as SPA)? Maybe this needs to be done somewhere other than a plugin, but if so where/how?



  • @genyded try this

    new (require('webpack')).ProvidePlugin({
                    $: "jquery",
                    jQuery: "jquery"
      })
    


  • It not the syntax… there is no webpack config file anymore. Everything is done via quasar.conf.js and plugins and there are no clear instructions for how do do domething like this using those.



  • Not sure if this is the best way, but it works. Create a Quasar plugin (jquery.js or whatever) and put:

    import jQuery from 'jquery'
    
    window.$ = window.jQuery = jQuery;
    
    export default () => {}
    

    Add it to quasar.conf.js:

    ...
    plugins: [
      'axios',
      'jquery'
    ],
    ...
    

    Then anything that references jQuery as $ or jQuery should work anywhere.