Skip to content

Commit

Permalink
Use elm-esm instead of manually wrapping IIFE
Browse files Browse the repository at this point in the history
  • Loading branch information
hmsk committed Oct 31, 2020
1 parent b5f9639 commit ad53d3b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Plugin, Transform } from 'vite'
//@ts-ignore
import compiler from 'node-elm-compiler'
//@ts-ignore
import { toESModule } from 'elm-esm'

const transform = (): Transform => {
return {
test: ({ path }) => path.endsWith('.elm'),
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)
}
}
}
Expand Down

0 comments on commit ad53d3b

Please sign in to comment.