flipbook-vue icon indicating copy to clipboard operation
flipbook-vue copied to clipboard

Failing importing vue2 version

Open rafalm-cyber opened this issue 2 years ago • 5 comments

Here is reproduction: https://stackblitz.com/edit/nuxt-starter-playground-gckgi7?file=plugins%2Fflipbook.js

import Flipbook from 'flipbook-vue/vue2' gives this error:

image

rafalm-cyber avatar Jan 18 '23 18:01 rafalm-cyber

I have to import it like this: import Flipbook from 'flipbook-vue/dist/vue2/flipbook.mjs' now it works :)

rafalm-cyber avatar Jan 19 '23 08:01 rafalm-cyber

not it works Did it work or not?

I tried it myself, import Flipbook from 'flipbook-vue/dist/vue2/flipbook.mjs' failed to import dependencies of Flipbook. import Flipbook from 'flipbook-vue/dist/vue2/flipbook.cjs' succeeds.

Anyway, I'll have to investigate how to play nice with Nuxt.

ts1 avatar Jan 19 '23 10:01 ts1

@ts1 did you find out how to make it work with Nuxt.js ?

AndreiD avatar Jan 21 '23 10:01 AndreiD

Hello.

For Nuxt 2, easiest way is to register it as a plugin component.

Under plugins/components/vue-flipbook.ts, register it as a global Vue component:

import Vue from 'vue'
import Flipbook from 'flipbook-vue/dist/vue2/flipbook.cjs'

Vue.component('Flipbook', Flipbook)

Then in nuxt.config.ts,

  plugins: [
    ...
    { src: '~/plugins/components/vue-flipbook' },
  ],

If you are using TypeScript (Nuxt 2 class component), register a module type so it won't return tslint errors:

declare module 'flipbook-vue/dist/vue2/flipbook.cjs'

Then should work in your vue files:

<template>
  <v-container class="home__container mx-auto">
    <Flipbook
      class="flipbook"
      :pages="[
        null,
        '/book/3.png',
        '/book/1.png',
        '/book/2.png',
        '/book/4.png',
      ]"
    ></Flipbook>
  </v-container>
</template>

<script lang="ts">
import { Component, Vue } from 'nuxt-property-decorator'

@Component({
  layout: 'empty',
  head() {
    return {
      title: 'Home',
    }
  },
})
export default class Index extends Vue {}
</script>

<style scoped>
.flipbook {
  width: 90vw;
  height: 90vh;
}
.home__container {
  max-width: 1440px;
}
</style>

kabaluyot avatar Jan 22 '23 02:01 kabaluyot

@AndreiD Not really. It looks like the offender is babel-loader. It is in Nuxt 2 and not in vue-cli, which successfully builds in examples/vue2module.

ts1 avatar Jan 24 '23 12:01 ts1