0

What is the correct way to import jQuery and fancybox into a Vue component so it gets bundled correctly. Does it need to be at the highest App level, or just at the component using fancybox?

Most of the solutions I've seen on here use ProvidPlugin and webpack. This project does not use webpack.

I run into 'no unused' or 'not defined' problems with this:

import $ from 'jQuery'
import fancybox from 'fancybox';

My implementation is the inline vanilla varity, i.e. just adding "data-fancybox" to a link.

I have no problem if I just call jQuery and fancybox from a CDN in the index.html, but I want to learn the right way so it's bundled in.

package.json

{
  "name": "inv-dash",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "test:unit": "vue-cli-service test:unit",
    "test:e2e": "vue-cli-service test:e2e",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "airtable": "^0.7.1",
    "axios": "^0.19.0",
    "core-js": "^3.3.2",
    "fslightbox-vue": "^1.0.2",
    "imagesloaded": "^4.1.4",
    "inuitcss": "^6.0.0",
    "masonry-layout": "^4.2.2",
    "material-icons": "^0.3.1",
    "to-title-case": "^1.0.0",
    "vue": "^2.6.10",
    "vue-agile": "^1.0.11",
    "vue-carousel": "^0.18.0",
    "vue-images-loaded": "^1.1.2",
    "vue-js-toggle-button": "^1.3.3",
    "vue-lazyload": "^1.3.3",
    "vue-masonry": "^0.11.8",
    "vue-masonry-css": "^1.0.3",
    "vue-nl2br": "^0.1.2",
    "vue-router": "^3.1.3",
    "vue-select": "^3.2.0",
    "vue-toasted": "^1.1.27",
    "vue-truncate-collapsed": "^2.1.0",
    "vueisotope": "^3.1.2",
    "vuex": "^3.1.1"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^4.0.0",
    "@vue/cli-plugin-e2e-cypress": "^4.0.0",
    "@vue/cli-plugin-eslint": "^4.0.0",
    "@vue/cli-plugin-router": "^4.0.0",
    "@vue/cli-plugin-unit-jest": "^4.0.0",
    "@vue/cli-plugin-vuex": "^4.0.0",
    "@vue/cli-service": "^4.0.0",
    "@vue/eslint-config-prettier": "^5.0.0",
    "@vue/test-utils": "1.0.0-beta.29",
    "babel-eslint": "^10.0.3",
    "eslint": "^5.16.0",
    "eslint-plugin-prettier": "^3.1.1",
    "eslint-plugin-vue": "^5.0.0",
    "lint-staged": "^9.4.2",
    "node-sass": "^4.12.0",
    "prettier": "^1.18.2",
    "sass-loader": "^8.0.0",
    "vue-template-compiler": "^2.6.10"
  },
  "gitHooks": {
    "pre-commit": "lint-staged"
  },
  "lint-staged": {
    "*.{js,vue}": [
      "prettier --write",
      "git add"
    ]
  }
}
7
  • 1
    Does this answer your question? How to use a jQuery plugin inside Vue Commented Jan 28, 2020 at 19:39
  • @ChrisG The project doesn't use webpack. Commented Jan 28, 2020 at 20:42
  • Ok, so how do the files get bundled? Commented Jan 28, 2020 at 21:48
  • @ChrisG It's weird, there is no webpack in the package.json file but there is in the yarn.lock file... so I'm not sure. I added the package.json to my question. Commented Jan 28, 2020 at 22:53
  • If you're using Vue CLI it uses webpack under the hood. Commented Jan 28, 2020 at 23:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.