-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuse.dev.js
More file actions
49 lines (43 loc) · 1.21 KB
/
fuse.dev.js
File metadata and controls
49 lines (43 loc) · 1.21 KB
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
const esbuild = require('esbuild');
const fs = require('fs');
const http = require('http');
const path = require('path');
const stylus = require('stylus');
const stylusPlugin = {
name: 'stylus',
setup(build) {
build.onLoad({ filter: /\.styl$/ }, async (args) => {
const source = await fs.promises.readFile(args.path, 'utf8');
const css = await new Promise((resolve, reject) => {
stylus(source)
.set('filename', args.path)
.set('compress', false)
.render((err, css) => err ? reject(err) : resolve(css));
});
return { contents: css, loader: 'css' };
});
},
};
const startDevServer = async () => {
const ctx = await esbuild.context({
entryPoints: ['src/index.ts'],
bundle: true,
outfile: 'public/index.js',
sourcemap: true,
target: ['es2015'],
platform: 'browser',
plugins: [stylusPlugin],
});
await ctx.watch();
console.log('Watching for changes...');
const { host, port } = await ctx.serve({
servedir: 'public',
port: 4444,
fallback: 'public/index.html',
});
console.log(`Dev server running at http://localhost:${port}`);
};
startDevServer().catch((err) => {
console.error(err);
process.exit(1);
});