Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hmrInjector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if (import.meta.hot) {

import.meta.hot.accept()
import.meta.hot.accept([
"${dependencies.join('", "')}"
${dependencies.length < 1 ? '' : '"' + dependencies.join('", "') + '"'}
], () => { console.log("[vite-plugin-elm] Dependency is updated") })

import.meta.hot.on('hot-update-dependents', (data) => {
Expand Down
20 changes: 20 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ts-expect-error typing isn't provided
import nodeElmcompiler from 'node-elm-compiler'
import { normalize, relative } from 'path'
import * as path from 'path'
import type { ModuleNode, Plugin } from 'vite'
import { injectHMR } from './hmrInjector.js'
import { acquireLock } from './mutex.js'
Expand Down Expand Up @@ -30,6 +31,25 @@ export const plugin = (userOptions: Parameters<typeof parseOptions>[0] = {}): Pl
return {
name: 'vite-plugin-elm',
enforce: 'pre',
resolveId(source, importer) {
if (source.endsWith('.elm')) {
if (source.startsWith('/')) {
return {
id: source,
external: false,
}
}
if (!importer) {
return null
}
const absolutePath = path.resolve(path.dirname(importer), source)
return {
id: absolutePath,
external: false,
}
}
return null
},
handleHotUpdate({ file, server, modules }) {
const { valid } = parseImportId(file)
if (!valid) return
Expand Down