Hi! I've been trying to build a project using AsyncAlpine + Vite for the last two days with no luck. I'm writing because I have no idea how to accomplish this.
This is my folder structure:
- ./
- main.js
- index.html
- assets
This is my vite.config.js:
//import {VitePWA} from 'vite-plugin-pwa';
import {defineConfig} from 'vite';
import {compression} from 'vite-plugin-compression2';
import {splitVendorChunkPlugin} from 'vite';
import compress from 'compression';
import {VitePluginFonts} from 'vite-plugin-fonts';
import VitePluginBrowserSync from 'vite-plugin-browser-sync';
import PathEnv from 'vite-plugin-patch-env';
import mockData from 'vite-plugin-mock-data';
import VitePluginHtmlEnv from 'vite-plugin-html-env';
// Icons
import Icons from 'unplugin-icons/vite';
import IconsResolver from 'unplugin-icons/resolver';
import AutoImport from 'unplugin-auto-import/vite';
export default defineConfig({
root: './',
base: './',
build: {
emptyOutDir: true
},
publicDir: 'public',
css: {
preprocessorOptions: {
scss: {
includePaths: ['./assets/css']
}
}
},
plugins: [
splitVendorChunkPlugin(),
VitePluginFonts({
google: {
families: ['Josefin Sans']
}
}),
VitePluginHtmlEnv({
compiler: true
}),
mockData({
mockAssetsDir: './mockAssets'
}),
PathEnv(),
compression(),
AutoImport({
resolvers: [
IconsResolver({
prefix: false,
extension: 'raw',
enabledCollections: ['carbon', 'mdi']
})
]
}),
Icons({
autoInstall: true,
compiler: 'raw',
scale: 1.2, // Scale of icons against 1em
defaultStyle: '', // Style apply to icons
defaultClass: '' // Class names apply to icons
}),
VitePluginBrowserSync({
bs: {
reloadDelay: 500,
notify: false,
ghostMode: false
}
}) /*,
VitePWA({
registerType: 'autoUpdate',
devOptions: {
enabled: true
}
})*/
]
});
This is my main.js:
import './assets/css/main.scss';
import AsyncAlpine from 'async-alpine';
import Alpine from 'alpinejs';
import focus from '@alpinejs/focus';
import persist from '@alpinejs/persist';
import moment from '@victoryoalli/alpinejs-moment';
import timeout from '@victoryoalli/alpinejs-timeout';
import * as HashRouter from '@techexp/hash-router';
import {util} from 'prettier';
document.addEventListener('alpine:initialized', () => {
console.log('Alpine Inited');
});
//window.Alpine = Alpine;
// Start Async Alpine
AsyncAlpine.init(Alpine)
.data('homeModule', () => import('./assets/js/components/Home/home.js'))
.data('toastModule', () => import('./assets/js/components/Toast/toast.js'))
.data('shopInfo', () => import('./assets/js/components/ShopInfo/shopInfo.js'))
.data('orderHeader', () => import('./assets/js/components/Operations/OrderHeader/orderHeader.js'))
.data('orderTabs', () => import('./assets/js/components/Operations/OrderTabs/orderTabs.js'))
.data('operationModule', () => import('./assets/js/components/Operations/operation.js'))
.data('orderList', () => import('./assets/js/components/Operations/OrderList/order.js'))
.data('orderGroup', () => import('./assets/js/components/Operations/OrderGroup/orderGroup.js'))
.start();
// Start Alpine
Alpine.plugin(focus);
Alpine.plugin(persist);
Alpine.plugin(timeout);
Alpine.plugin(moment);
Alpine.start();
This is my index.html:
<!DOCTYPE html>
<html lang="en" data-theme="fika" class="overflow-y-hidden">
<head>
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin/>
<link rel="preload" as="style" onload="this.rel='stylesheet'" href="https://fonts.googleapis.com/css2?family=Josefin Sans&display=swap"/>
<meta charset="UTF-8"/>
<link rel="icon" type="image/x-icon" href="./assets/favicon.67af206a.ico"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="pragma" content="no-cache"/>
<title>FikaCore</title>
<script type="module" crossorigin src="./assets/index.f178bb58.js"></script>
<link rel="modulepreload" crossorigin href="./assets/vendor.88f6f930.js"/>
<link rel="stylesheet" href="./assets/index.62293656.css"/>
</head>
<body>
<div id="app" x-data>
<div id="homeModule" ax-load x-data="homeModule()" x-html="view" x-ignore></div>
</div>
</body>
<script>console.log('===== En modo DESARRROLLO =====');</script>
</html>
When I run vite build && vite preview
I got:
And I think this problem is related to the dist structure:
Since every module is in assets/js/components
the dist index.html couldn't find the module because it's not the same folder structure as dev mode. Any thoughts?
Regards