From ad53d3bff20be9ae2ff623ce762a7cf8b8fea7b7 Mon Sep 17 00:00:00 2001 From: hmsk Date: Fri, 30 Oct 2020 23:18:51 -0700 Subject: [PATCH] Use elm-esm instead of manually wrapping IIFE --- package-lock.json | 18 ++++++++++++++++++ package.json | 1 + src/index.ts | 4 +++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 3d48df2a..c045ca75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -886,6 +886,24 @@ "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=", "dev": true }, + "elm-esm": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/elm-esm/-/elm-esm-1.1.1.tgz", + "integrity": "sha512-1nlnslSW4zReHvGCPZ+ToBnyXyMtYi1tNg4EKouw/1VFIk+JLYBgTOD2QwQLh/VpLLRs+GHjRCwR5796LXjzsg==", + "requires": { + "which": "^2.0.2" + }, + "dependencies": { + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "requires": { + "isexe": "^2.0.0" + } + } + } + }, "emojis-list": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-3.0.0.tgz", diff --git a/package.json b/package.json index dae96129..62a17d74 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ }, "homepage": "https://github.com/hmsk/vite-plugin-elm", "dependencies": { + "elm-esm": "1.1.1", "node-elm-compiler": "5.0.5" }, "devDependencies": { diff --git a/src/index.ts b/src/index.ts index cba58cb5..92d0085f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,8 @@ import { Plugin, Transform } from 'vite' //@ts-ignore import compiler from 'node-elm-compiler' +//@ts-ignore +import { toESModule } from 'elm-esm' const transform = (): Transform => { return { @@ -8,7 +10,7 @@ const transform = (): Transform => { transform: async ({ path, isBuild }) => { const compiled = await compiler.compileToString([path], { output: '.js', optimize: isBuild, verbose: isBuild, debug: !isBuild }) return { - code: `let output = {}; (function () { ${compiled} }).call(output); export default output.Elm;` + code: toESModule(compiled) } } }