Code Monkey home page Code Monkey logo

snowpack-plugin-elm's Introduction

Snowpack Elm Plugin

This plugin adds support for the Elm language to any Snowpack project. With it, you can import *.elm files and have them compile to JavaScript modules.

Usage

Plugin options

Default values:

{
  "verbose": false,
  // When to enable Elm's time-traveling debugger
  "debugger": "dev", // One of "never", "dev" (only on `snowpack dev`) or "always"
  "optimize": "build", // One of "never", "build" (only on `snowpack build`) or "always"
}

Note: The Elm debugger needs information that is stripped away when using optimize, so a setting like { "debugger": "always", "optimize": "build" } would fail and is rejected by the plugin.
If you want to e.g. have a build with an enabled debugger, you need to use { "debugger": "always", "optimize": "never" }.

Add the plugin to a Snowpack project

Install snowpack-plugin-elm, for instance with npm install --save-dev snowpack-plugin-elm.

Then add the plugin to your Snowpack config, e.g. snowpack.config.json

{
  "plugins": ["snowpack-plugin-elm"]
}

or with plugin options

{
  "plugins": [["snowpack-plugin-elm", { "verbose": false }]]
}

Or play with the included example first

cd example
npm install
npx snowpack dev
# and then change src/Sandbox1.elm

Development

To use it on another project

As described in this Snowpack guide:

  1. Clone this repo and cd into it.

  2. Run npm link to expose the plugin globally (in regard to your development machine).

  3. Create a new, example Snowpack project in a different location for testing

  4. In your example Snowpack project, run npm install && npm link snowpack-plugin-elm.

    • Be aware that npm install will remove your linked plugin, so on any install, you will need to redo the npm link snowpack-plugin-elm.
    • (The alternative would be to use npm install --save-dev <folder_to_this_repo>, which would create the "symlink-like" entry in your example Snowpack project’s package.json)
  5. In your example Snowpack project, add snowpack-plugin-elm to the snowpack.config.json along with any plugin options you’d like to test.

Tests

Execute npm test to start the integration tests.

Notes

After I got it running, I would like to merge the changes into https://github.com/klazuka/elm-hot so the esm builds could be used in multiple tools (e.g. webpack, parcel2, vite), and then use elm-hot inside this plugin.

Maybe it will make sense to have different hmr.js files that elm-hot can insert as necessary (configurable with flags).

TODO

  • In ./example/
    • npx snowpack dev renders Sandbox1.elm
    • Add HMR for changes to Sandbox1.elm
    • Add HMR for changes to Indirect.elm (needs Snowpack >= 2.14.0)
    • Fix npx snowpack build (tries to build Indirect.elm which does not export a main)
  • Convert ./example to a playwright test
  • Add tests
    • For a Browser.sandbox (see ./example/)
    • For a Browser.element (with ports)
    • For a Browser.document
    • For a Browser.application (with URL change)
  • Run tests in parallel from temp folders on random ports
  • Enhance tests
  • Ask for feedback

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.