2

I am creating a vuejs plugin. I haven't published it to NPM yet, because I need to test it extensively, the problem I have is, if I push my code to github then NPM, I could simple install the plugin using

npm install foobar

Then I could use it in my app like this.

import foobar from 'foobar' and the usuall <foobar> .. </foobar>

This way, it works, I can actually test it, how do I test the app while I am developing instead of pushing to NPM, Github then updating my dependency every minute?

I know there is a simple way but I can't find out what is it

In the file heirarchy you can see below, I have tried importing the dist/foobar.js as

inside the index.html but it just won't work.

This is my apps structure.

my-plugin
  dist
    foobar.js
  node_modules
  src
    components
      foobar.vue
    index.html
    index.js

foobar.vue is the actual app whereas the index.js simply imports foobar and exports it as:

import foobar from './components/foobar.vue'
export {foobar}

The app has no errors or issue, it works. But to test if foobar is working, I have to push it to github and npm and then I have to install it to use it.

npm run serve lauches the app at localhost:8080 in development mode and shows me the contents of index.html but in this file if I require dist/foobar.js it won't work, for example <foobar></foobar> has no effect

v742210
  • 21
  • 2
  • Can you not test your plugin within its own project using for example, Jest (or whatever flavour of test runner you prefer)? Take a look at some other plugins and see how they run tests. For example, [vue-router](https://github.com/vuejs/vue-router) uses Jasmine – Phil May 06 '19 at 01:18
  • Possible duplicate of [how to specify local modules as npm package dependencies](https://stackoverflow.com/questions/15806241/how-to-specify-local-modules-as-npm-package-dependencies) – Phil May 06 '19 at 01:25
  • @Phil I am not trying to test the app as in unit testing, I just want to include the component I made into a file and simply test if it works. Also, I don't know unit testing for js so there is that, but still this is just to test the behavior rather than functional – v742210 May 06 '19 at 13:21
  • @Phil Also, this is not a duplicate to the question you linked, you didn't understand the question previously so it is not a duplicate of that question – v742210 May 06 '19 at 13:22
  • Have you looked at the linked post? It seems to fit what you want to do, that being include a local project dependency without publishing it – Phil May 06 '19 at 21:19

0 Answers0