Skip to content

Commit

Permalink
Adds frontend setup with melange and webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed May 19, 2024
1 parent 5f349de commit 22ebb78
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
_esy
*~
*~
static
_build
3 changes: 2 additions & 1 deletion bin/main.re
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ let hello_route_handler = _request =>
);

let hello_route: Dream.route = Dream.get("/", hello_route_handler);
let statics_route: Dream.route = Dream.get("/static/**", Dream.static("./static"));

let handler = Dream.router([hello_route]);
let handler = Dream.router([hello_route, statics_route]);

// request => promise(response)
Dream.run(~port=8000, ~interface="localhost", handler);
4 changes: 4 additions & 0 deletions client/app.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
switch (ReactDOM.querySelector("#root")) {
| Some(el) => ignore @@ ReactDOM.Client.hydrateRoot(el, <Reason_india_website_js.App />)
| None => ()
};
7 changes: 7 additions & 0 deletions client/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(melange.emit
(alias client)
(target app)
(libraries melange reason_india_website_js reason-react)
(preprocess
(pps reason-react-ppx melange.ppx))
(module_systems commonjs))
1 change: 1 addition & 0 deletions dune
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(data_only_dirs node_modules esy.lock _esy)
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(lang dune 3.15)

(name reason_india_website)
(using melange 0.1)

(generate_opam_files true)

Expand Down
8 changes: 8 additions & 0 deletions lib/js/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(library
(name reason_india_website_js)
(modes melange)
(libraries melange reason-react)
(preprocess
(pps melange.ppx reason-react-ppx)))

(copy_files# "../native/*.re")
15 changes: 15 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const Path = require("path");

let buildFolder = Path.join(__dirname, "_build/default/client");

module.exports = (env) => ({
devtool: env.production ? false : "inline-cheap-module-source-map",
entry: {
app: Path.join(buildFolder, "/app/client/app.js"),
},
mode: 'development',
output: {
path: Path.join(__dirname, "static"),
filename: "[name].js",
},
});

0 comments on commit 22ebb78

Please sign in to comment.