Skip to content

Commit

Permalink
Update deno example
Browse files Browse the repository at this point in the history
  • Loading branch information
dalcib committed Apr 14, 2021
1 parent 5ef53b0 commit fc0511a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
23 changes: 13 additions & 10 deletions example-deno/build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as esbuild from 'https://deno.land/x/esbuild/mod.js'
import { cache } from './../deno/mod.ts'
//import { cache } from './../deno/mod.ts'
import { cache } from 'https://deno.land/x/esbuild_plugin_cache/mod.ts'

const importmap = {
imports: {
Expand All @@ -8,12 +9,14 @@ const importmap = {
},
}

esbuild.build({
entryPoints: ['./index.tsx'],
bundle: true,
format: 'esm',
plugins: [cache({ importmap, directory: './cache' })],
outfile: 'bundle.js',
})

esbuild.stop()
esbuild
.build({
entryPoints: ['./index.tsx'],
bundle: true,
format: 'esm',
plugins: [cache({ importmap, directory: './cache' })],
outfile: 'bundle.js',
})
.then((result, error) => {
esbuild.stop()
})
7 changes: 4 additions & 3 deletions example-deno/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ esbuild.serve({ servedir: './' }, {}).then(() => {
)
return clients.push(req)
}
const path = ~url.split('/').pop().indexOf('.') ? url : `/index.html`
const path = ~url.split('/').pop().indexOf('.') ? url : `/index.html` //for PWA with router
const res = await fetch('http://localhost:8000' + path, { method, headers })
const text = await res.text()
await req.respond({ body: text, statusCode: res.statusCode, headers: res.headers })
})
setTimeout(() => {
if (clients.length === 0) Deno.run({ cmd: ['cmd', '/c', 'start', `http://localhost:3000`] })
}, 2000)
const open = { darwin: ['open'], linux: ['xdg-open'], windows: ['cmd', '/c', 'start'] }
if (clients.length === 0) Deno.run({ cmd: [...open[Deno.build.os], 'http://localhost:3000'] })
}, 2000) //open the browser only if it is not opened yet
})

0 comments on commit fc0511a

Please sign in to comment.