Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-elm

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-elm

Compile Elm with vite

  • 2.6.0-beta.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.3K
decreased by-50.89%
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-elm

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

Update vite.config.(js|ts)

import { defineConfig } from 'vite'
import elmPlugin from 'vite-plugin-elm'

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'

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'

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" ] []

Acknowledgement

License

MIT

Keywords

FAQs

Package last updated on 06 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc