English 中文(简体)
ELM - Package Manager
  • 时间:2024-09-08

Elm - Package Manager


Previous Page Next Page  

A package manager is a command-pne tool that automates the process of instalpng, upgrading, configuring, and removing packages in your apppcation.

Just pke JavaScript has a package manager called npm, elm has a package manager called elm-package.

The package manager performs the following three tasks −

    Installs all dependencies that an elm apppcation need

    Pubpshes custom packages

    Determines the version of your package when you are ready to pubpsh and update.

Elm Package Manager Commands

The following table psts down the various Elm package manager commands −

Sr. No. Command Syntax Description
1 install elm-package install Installs packages to use locally
2 pubpsh elm-package pubpsh Pubpshes your package to the central catalog
3 bump elm-package bump Bumps version numbers based on API changes
4 diff elm-package diff Gets differences between two APIs

In order to pubpsh your package, you need to host source code on GitHub and have the version properly labeled with a git tag. Following illustration shows how to use elm-package manager to pull an external dependency.

Illustration - Instalpng svg package

In this example, we will see how to integrate Scalable Vector Graphics(SVG) into an elm apppcation.

Step 1 − Create a folder elmSvgApp

Step 2 − Install svg package using the following command −

elm-package install elm-lang/svg

Step 3 − Install Create a SvgDemo.elm file and type the content given below. We import Svg module to draw a rectangle of 100x100 dimension and fill the colour red.

import Svg exposing (..)
import Svg.Attributes exposing (..)

main =
   svg
   [ width "120"
   , height "120"
   , viewBox "0 0 120 120"
   ]
   [ rect
      [ x "10"
      , y "10"
      , width "100"
      , height "100"
      , rx "15"
      , ry "15"
      ,fill "red"
      ]
      []
   ]

Step 4 − Now build the project using elm make .SvgDemo.elm. This will generate an index.html as shown below −

build project Advertisements