Alpine: Log a warning if Alpine starts but no components are found on the page

Created on 5 May 2020  Â·  5Comments  Â·  Source: alpinejs/alpine

One for @calebporzio

Does it make sense to console.warn a message if Alpine.start runs but there are no components on the page.

Something like "No Alpine.js component(s) found on the page, are you missing the 'x-data' attribute?"?

Relevant issues which are obvious user errors in hindsight but would have likely benefitted from a warning:

Candidates for this warning, if (rootEls.length === 0) console.warn():

enhancement

All 5 comments

Wouldn’t that create a lot of noise? I’m using alpine for a few components on a larger site. Not all pages rely on Alpine.

Wouldn’t that create a lot of noise? I’m using alpine for a few components on a larger site. Not all pages rely on Alpine.

Any reason your pages load Alpine.js if they're not using it? Bundling your JS to a single file?

Any reason your pages load Alpine.js if they're not using it? Bundling your JS to a single file?

For me, I just include Alpine in the shared <head /> snippet that all my pages use. Some of the page templates use Alpine, some don't, but I really don't want to specify whether to load Alpine or not for each page that I create – for me, the main advantage of Alpine is that I can just drop in x-data in my templates where ever I want, without the additional complexity of loading a script, initializing a Vue instance etc.

Yeah that makes sense, I think it's safe to close this issue then.

Any reason your pages load Alpine.js if they're not using it? Bundling your JS to a single file?

I use the CDN.

Was this page helpful?
0 / 5 - 0 ratings