
Security News
Node.js TSC Votes to Stop Distributing Corepack
Corepack will be phased out from future Node.js releases following a TSC vote.
Wanna load Elm as ES Modules in your browser? Say no more. With this package you can easily do just that.
npx elm-esm make src/Main.elm --output=myElmModule.js
Then use your favorite way of loading it as a new ES module
<script type="module">
import { Elm } from './myElmModule.js';
Elm.Main.init({ node: document.body })
</script>
It's even possible to use your favorite ES6 features like dynamic-import
or modulepreload
now.
// this is great for lazy loading an Elm app
import('./myElmModule.js').then(({ Elm }) => {
Elm.Main.init({ node: document.body })
});
<!-- preload our Elm module for faster startup when you need it -->
<link rel="modulepreload" href="./myElmModule.js">
It's like it's 2020 already 🥳🎉
elm-esm
accepts all the options that elm
accepts. Run elm-esm --help
for an
overview.
npx elm-esm make src/Main.elm --output=myElmModule.js
# Or globally installed
npm i -g elm-esm
elm-esm make src/Main.elm --output=myElmModule.js
elm-esm
accepts one extra option called --compiler=path/to/elm
. By default it looks
for an Elm compiler in the following order.
--compiler=path/to/elm
flag, if presentnode_modules/.bin
$PATH
Plugin authors or other tooling may want to use the transform as a standalone function. Here's how:
# install the package to your dependencies
npm i -D elm-esm
The module exports a named function called toESModule
. It takes one argument,
which is the compiled Elm code as a string. It returns the ESModule transformed code
as a string.
const { toESModule } = require('elm-esm');
const transformedElmOutputAsESModule = toESModule(compiledElmOutput);
It's just a few simple Regex transforms on the compiler output, designed to work under different circumstances. It only operates on necessary lines of code that are related to exporting. Some code that isn't needed is commented out, and one line to export in ES6 style is added.
Probably, yes. All modern Browsers support ES6 modules now. Check out the compatibility table.
I haven't 100% figured that out, but it should be pretty easy. elm-esm
is designed to be a wrapper around elm
.
Most bundler plugins for Elm allow passing an option with a path to the Elm executable.
Just pass the path to elm-esm
instead.
On the other hand why bundle when you can load the module in the browser directly?
If you're looking to bundle your app, then you probably don't need this elm-esm
.
Please open an issue if you run into problems here!
Don't use this for elm-test. elm-esm
is meant for use in the browser. NodeJS
still only has experimental support for ESM sigh.
But if you're looking to launch a Platform.worker
Elm program in
Deno, then elm-esm
can generate the necessary ES module for you.
It's only tested for Elm 0.19.1, but it may work with 0.19.0 too. Please open an issue if you run into problems here!
Nothing happens. Having an inline script with type=module
doesn't make sense
with exports since I don't think you can import it anywhere else.
FAQs
Turn Elm compiler output into modern ES Modules
The npm package elm-esm receives a total of 3,360 weekly downloads. As such, elm-esm popularity was classified as popular.
We found that elm-esm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.
Research
Security News
Research uncovers Black Basta's plans to exploit package registries for ransomware delivery alongside evidence of similar attacks already targeting open source ecosystems.
Security News
Oxlint's beta release introduces 500+ built-in linting rules while delivering twice the speed of previous versions, with future support planned for custom plugins and improved IDE integration.