npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-elm-safe-asset-names

v2.8.0-beta.1-safe-asset-names.6

Published

Compile Elm with vite

Downloads

3

Readme

vite-plugin-elm-safe-asset-names

npm GitHub Workflow Status

A plugin enables you to compile an Elm application/document/element on your Vite project. Hot module replacement works roughly in development.

import { Elm } from './MyApplication.elm'

Elm.MyApplication.init()

Setup

npm i -D vite-plugin-elm-safe-asset-names

Update vite.config.(js|ts)

import { defineConfig } from 'vite'
import elmPlugin from 'vite-plugin-elm-safe-asset-names'

export default defineConfig({
  plugins: [elmPlugin()]
})

Then you can import .elm file like:

import { Elm } from './Hello.elm'

then

// Mount "Hello" Browser.{element,document} on #root
Elm.Hello.init({
  node: document.getElementById('root'),
  flags: "Initial Message"
})

See /example dir to play with an actual Vite project. And this working website may help you to learn how to use.

Plugin Options

debug (Default: process.env.NODE_ENV !== 'production')

By giving a boolean, can control debug mode of Elm (means toggle Elm Debugger)

image

import { defineConfig } from 'vite'
import elmPlugin from 'vite-plugin-elm-safe-asset-names'

export default defineConfig({
  plugins: [elmPlugin({ debug: false })]
})

When it's false, disables debug mode in both development and production. Conversely, enables debug mode even in production by true. When production build gets debug mode, Elm's compile optimization doesn't happen.

optimize (Default: !debug && process.env.NODE_ENV === 'production')

By giving a boolean, can control build optimization, useful to use Debug elm functions

import { defineConfig } from 'vite'
import elmPlugin from 'vite-plugin-elm-safe-asset-names'

export default defineConfig({
  plugins: [elmPlugin({ debug: false, optimize: false })]
})

When true, optimize build and forbid usage of Debug elm functions. When specify optimize attribute, had to tell if need to debug or not. It's not why you want to make debug traces you want to see all actions.

Static Assets Handling

This plugin supports importing assets by giving a particular tag [VITE_PLUGIN_ELM_ASSET:<path to asset>] to leverage Vite's asset handling. When Elm code has a string, this plugin replaces it with an imported asset. That string should be just a string without any concatenation.

Html.img [ Html.Attributes.src "[VITE_PLUGIN_ELM_ASSET:/assets/logo.jpg]" ] []

Helper package

By using a Elm package elm-vite-plugin-helper, you can shorten such the tagging:

elm install hmsk/elm-vite-plugin-helper
import VitePluginHelper

Html.img [ Html.Attributes.src <| VitePluginHelper.asset "/assets/logo.png?inline" ] []

Combine multiple main files (Experimental from 2.7.0-beta.1)

By passing importing path via with URL-ish parameter(s), the plugin compiles multiple main files in a single compilation process. That generates a single Elm export which has multiple properties for each given main files. This way reduces bundle size comparing to a total size of importing each file separately since common modules/Elm core codes are not repeated.

// `Elm.App` and `Elm.Another`, both can work as like importing individually.
import { Elm } from './App.elm?with=./Another.elm'

Elm.App.init({
  node: document.getElementById('rootForApp'),
})
Elm.Another.init({
  node: document.getElementById('rootForAnother'),
})

For 3+ main files:

import { Elm } from './App.elm?with=./Another.elm&./YetAnother.elm'

Acknowledgement

License

MIT