I use spago to build src/Main.purs to output/Main/index.js.
I am trying to use Vite for the bundling tool and have successfully loaded output/Main/index.js in src/main.ts.
Vite can import image files, but I am having trouble using this from PureScript.
The approach I have tried is to first import the image file using regular JavaScript and then make it referenceable from the purs file using PureScript's FFI. However, this approach did not work with the following error message:
[plugin:vite:import-analysis] Failed to resolve import "./typescript.svg" from "output/Constants/foreign.js". Does the file exist?
Is there any good solution?
/
├ public/
│ └ vite.svg
├ output/
├ src/
│ ├ Constant.js
│ ├ Constant.purs
│ ├ Main.purs
│ ├ main.ts
│ ├ style.css
│ ├ typescript.svg
│ └ vite-env.d.ts
├ index.html
├ package.json
├ spago.yaml
└ tsconfig.json
src/main.ts:
import './style.css'
import { main } from "../output/Main";
main();
src/Constants.purs:
module Constants
( typescriptlogo
, vitelogo
) where
foreign import typescriptlogo :: String
foreign import vitelogo :: String
src/Constants.js:
import typescriptlogo from './typescript.svg'
import vitelogo from '/vite.svg'
export { typescriptlogo, vitelogo }
src/Main.purs:
module Main where
import Prelude
import Constants (vitelogo)
import Effect (Effect)
import Effect.Console (log)
import Halogen (liftEffect)
import Halogen as H
import Halogen.Aff as HA
import Halogen.HTML as HH
import Halogen.HTML.Properties as HP
import Halogen.VDom.Driver (runUI)
type State = Unit
component :: forall query input output m. H.Component query input output m
component =
H.mkComponent
{ initialState
, render
, eval
}
where
initialState :: input -> State
initialState _ = unit
render :: forall w i. State -> HH.HTML w i
render _ =
HH.div []
[ HH.a
[ HP.href "https://vitejs.dev"
]
[ HH.img [ HP.src vitelogo ] ]
]
eval = H.mkEval H.defaultEval
main :: Effect Unit
main = HA.runHalogenAff do
body <- HA.awaitBody
_io <- runUI component unit body
liftEffect $ log $ "Application Start"