Using AlpineJS I have the folowing HTML and JS:
<form x-data="inquiry()" x-on:submit.prevent="submit" method="post">
</form>
<script>
function inquiry() {
return {
data: { name: "" },
submit() {
// Do something
}
}
}
</script>
I moved the JS inquiry
function to a JS file and used Parcel for building.
So the index.js file used as an entry point for Parcel is:
import './index.less'
import inquiry from './inquiry.js'
import alpine from 'alpinejs';
window.alpine = alpine;
alpine.start();
console.log("Hello");
I am importing the bundle in my HTML page using:
<script src="~/index.js" type="text/javascript" defer></script>
When I run my code and try to access inquiry
function I get the error:
Alpine Expression Error: Can't find variable: inquiry
However I can see "Hello" in the console as result of console.log("Hello")
What am I missing?