-
Notifications
You must be signed in to change notification settings - Fork 1
/
watch-task.js
50 lines (47 loc) · 1.03 KB
/
watch-task.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const fs = require('fs')
const esbuild = require("esbuild")
let entry = ""
if (fs.existsSync("./src/demo.tsx")) {
entry = "./src/demo.tsx"
}
else if (fs.existsSync("./src/demo.ts")) {
entry = "./src/demo.ts"
}
else if (fs.existsSync("./src/demo.js")) {
entry = "./src/demo.js"
}
else {
throw new Error("Entry not found")
}
module.exports = function() {
esbuild.serve(
{
host: "localhost",
port: 3001,
servedir: __dirname + "/assets"
},
{
write: false,
entryPoints: [entry],
outfile: __dirname + "/assets/demo.js",
sourcemap: true,
sourcesContent: true,
bundle: true,
target: "es2017",
plugins: [],
define: {
"process.env.NODE_ENV": '"development"',
global: "window",
"process.env": "{}"
},
minify: false,
loader: {
".png": "dataurl"
}
}).then(result => {
// Server listening
console.log("http://localhost:3001/index.html")
}).catch(err => {
console.error(err.message)
})
}