How to use jQuery in Nuxt.js

Posted 2 years ago by Ryan Dhungel

Category: Nuxt js jQuery

Viewed 45371 times

Estimated read time: 3 minutes

Are you struggling to use jQuery in your nuxt.js project? We all know that Bootstrap4  does require jQuery and popper.js. Withojut jQuery and popper.js, Bootstrap4 navigation dropdown, hamburger menu, carousel's etc dont work. But no worries, follow the steps I have shown below to start using Bootstrap4 and jQuery in your Nuxt.js project.


If you are interested to learn Nuxt JS to build your frontend along with Laravel API (backend), Check out my Udemy course Laravel with Nuxt JS - Build API driven SSR Vue JS Web Application. Use this link to enroll into this course for only $9.99


First way (easy)

Using CDN

Update the nuxt.config.js head section with the following code:


head: {
    meta: [
      { charset: "utf-8" },
      { name: "viewport", content: "width=device-width, initial-scale=1" },
      { hid: "description", name: "description", content: pkg.description }
    link: [
      { rel: "icon", type: "image/x-icon", href: "/favicon.ico" },
        rel: "stylesheet",

    script: [
        src: "",
        type: "text/javascript"
        type: "text/javascript"
        type: "text/javascript"


Second way:

Add jQuery as a plugin to Nuxt.js


Create a file called bootstrap.js inside plugins folder, which is in the root directory of your nuxt.js project. Paste the following code.

// /plugins/bootstrap.js
if (process.BROWSER_BUILD) {


Install Bootstrap, jQuery and Popper.js


npm install --save bootstrap jquery popper.js


Configure nuxt.config.js

  • On top of your nuxt.config.js file, require webpack.
  • load Bootstrap and jQuery from the node_modules folder 
  • Add them to vendor's array and configure jQuery as a webpack plugin
  • Then inside module.exports object add or modify the existing build option with the following code. 

// full code of nuxt.config.js

const webpack = require("webpack");

module.exports = {
  // load bootstrap and jquery
  css: ["~/node_modules/bootstrap/dist/css/bootstrap.css"],
  plugins: ["~plugins/bootstrap.js"],
  build: {
     * add external plugins
    vendor: ["jquery", "bootstrap"],
    plugins: [
      new webpack.ProvidePlugin({
        $: "jquery"
    ** Run ESLint on save
    extend(config, { isDev, isClient }) {
      if (isDev && isClient) {
          enforce: "pre",
          test: /\.(js|vue)$/,
          loader: "eslint-loader",
          exclude: /(node_modules)/


That's all. Now you can style your app the way you want using Bootstrap4 and jQuery.