Importing npm dependencies with Webpack and Shopify #29
-
Hello! I'm trying to remake my shopify project from standard alpine to your async-alpine methods, but I'm having some trouble importing swiper at least... I'm using a webpack (shopify theme lab) and I saw your webpack implementation (https://stackblitz.com/edit/async-alpine-webpack), but for shopify we can use this path for files. How we just can import Swiper in this way, that it loads only on view? we already install it via npm but don't want it to load imediatly In general the question is how do we import additional packages into alpineJS's asynchronous script files? Maybe you already have a solution for this problem, please help :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi @UnleashedMySelf! The problem you're asking isn't really related to Async Alpine as it just loads the files rather than handling anything like imports. You're going to need to use Webpack in order to bundle imports from npm, so you can't just import the file directly using The easiest way of doing that is using Alternatively what I do on the Shopify sites I work on is to set up my bundler to process the component files separately from the main bundle and output them to the |
Beta Was this translation helpful? Give feedback.
-
I've put together a GitHub Gist that combined with Async Alpine 2 makes use with Shopify and bundling much easier. This example uses Laravel Mix (based on Webpack but with alternative syntax) but should be possible to adapt to other bundlers with at least some of the key functionality. With the code here you can just drop a JS component file into https://gist.github.com/Accudio/35e17148732e7c26400a2d70e4dbf3b0 |
Beta Was this translation helpful? Give feedback.
Hi @UnleashedMySelf!
The problem you're asking isn't really related to Async Alpine as it just loads the files rather than handling anything like imports.
You're going to need to use Webpack in order to bundle imports from npm, so you can't just import the file directly using
ax-load-src
, you'll need to run it through Webpack first.The easiest way of doing that is using
AsyncAlpine.data
and Webpacks dynamicimport()
which I think should work on Shopify still, without usingasset_url
.Alternatively what I do on the Shopify sites I work on is to set up my bundler to process the component files separately from the main bundle and output them to the
assets
directory. This however would invol…