-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bart Schuurmans
committed
Jun 21, 2022
1 parent
21709d9
commit 9d74564
Showing
6 changed files
with
538 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/.merlin | ||
/.bsb.lock | ||
/lib/ | ||
/node_modules/ | ||
/public/bundle/ | ||
/public/sw.js* | ||
/public/workbox-*.js* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# lumi-rescript-dev | ||
|
||
This is a utility to build and bundle rescript projects using esbuild. | ||
|
||
- Very fast builds | ||
- Watcher with live-reload | ||
- Service workers | ||
- Sass support | ||
|
||
## How to use | ||
|
||
Simply run `lumi-rescript-dev build` in your project root. Typically, you'll want to add the following to your `package.json`. | ||
|
||
```json | ||
{ | ||
"scripts": { | ||
"prepare": "lumi-rescript-dev build", | ||
"start": "lumi-rescript-dev watch", | ||
"start-prod": "lumi-rescript-dev watch '{\"http\":{\"proxy\":{\"target\":\"https://your-prod.com/\"}}}'", | ||
"clean": "rescript clean && rm -rf public/bundle" | ||
}, | ||
} | ||
``` | ||
|
||
## Project structure | ||
|
||
The default config expects something like the following project structure: | ||
``` | ||
project-name | ||
├── bsconfig.json | ||
├── package.json | ||
├── public | ||
│ ├── images | ||
│ │ ├── favicon.ico | ||
│ │ ├── icons-512.png | ||
│ │ └── some-image.png | ||
│ ├── index.html | ||
│ └── site.webmanifest | ||
└── src | ||
├── css | ||
│ ├── default.scss | ||
│ └── main.sass | ||
├── Index.res | ||
└── Util.res | ||
``` | ||
|
||
Generated files will end up in `lib` and `public/bundle`, by default. | ||
|
||
## Configuration | ||
The default configuration can be inspected using `lumi-rescript-dev dump-config`, and changes can be made by adding them to the `lumi-rescript-dev` key in your `package.json`. | ||
|
||
## JS API | ||
Alternatively, if you require more configuration flexibility, the code can be imported from your own code. | ||
```js | ||
const {main, defaultConfig} = require('lumi-rescript-dev') | ||
|
||
main(defaultConfig, { | ||
root: __dirname | ||
// ... | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const watchman = require('fb-watchman') | ||
|
||
class Watchman { | ||
constructor() { | ||
this.client = new watchman.Client() | ||
} | ||
command(...args) { | ||
return new Promise((resolve, reject) => { | ||
this.client.command(args, (err, resp) => { | ||
if (err) reject(err) | ||
else resolve(resp) | ||
}) | ||
}) | ||
} | ||
async setup_watches(dirname) { | ||
const { warning, watch, relative_path } = await this.command("watch-project", dirname) | ||
if (warning) { | ||
console.warn('[watchman]', warning); | ||
} | ||
console.log('[watchman] watch established on:', watch, 'relative_path:', relative_path); | ||
Object.assign(this, { watch, relative_path }) | ||
this.clock = await this.command("clock", watch) | ||
} | ||
async subscribe(name, expression) { | ||
const sub = { | ||
expression, | ||
fields: ["name", "size", "mtime_ms", "exists", "type"], | ||
since: this.clock | ||
} | ||
if (this.relative_path) sub.relative_root = this.relative_path | ||
await this.command('subscribe', this.watch, name, sub) | ||
} | ||
on(x, y) { | ||
return this.client.on(x, y) | ||
} | ||
} | ||
module.exports.Watchman = Watchman |
Oops, something went wrong.