How to install jQuery into Nuxt.js?

I do not recommend adding jQuery to a Nuxt project.


But if you really want to, you can follow those steps:

  • install it with yarn add jquery
  • add those to your nuxt.config.js file
import webpack from 'webpack'

export default {
  // ...
  build: {
    plugins: [
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery'
      })
    ]
  },
}
  • be sure that you do have the following in your .eslintrc.js file
module.exports = {
  // ...
  env: {
    // ...
    commonjs: true,
    jquery: true
  },
}

Then, you can use it like this in a method or alike

$("h2").addClass("tasty-class")