1

I am using snipcart which looks at the static html document and looks for #snipcart element. You can put vue elements in there and the magic will be done on the snipcart.js side.

When using Gatsby, in order to edit the index.html file, you have to create a React file called html.js. In this file I can successfully add Snipcart and everything works. That is until I want to customize the cart and Snipcart uses vue for that. You have to add the vue items in between the #snipcart div.

snipcart-docs-customization

An example

<div hidden id="snipcart" data-api-key="<API_KEY>">
    <component-to-override>
        <div class="root">
          {{ vue_variable.itemText }}
        </div>
    </component-to-override>
</div>

The problem is, webpack will throw an error if I add vue. This makes sense. So Gatsby has a couple of nice middleware type API's gatsby-ssr and gatsby-browser that might help this.

Looking at these API's I am still unsure how to do this. I need this code added to the index.html as Gatsby is rendering the static pages, at least I feel that is best.

Because Snipcart looks in the #snipcart divs innerHTML for vue formatted components, this is difficult because webpack wants to convert the vue, I do not want it converted.

How can I go about this?

Some useful links I have entertained: Gatsby Lifecyle Gatsby-ssr api Gatsby-browser api Snipcart customizing components

Michael Bruce
  • 10,567
  • 2
  • 23
  • 31

0 Answers0