Navigation Menu

Skip to content

Commit

Permalink
custom server
Browse files Browse the repository at this point in the history
  • Loading branch information
nchanged committed Jan 8, 2018
1 parent 2c774bd commit efdb7a3
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
55 changes: 55 additions & 0 deletions examples/custom-server/fuse.js
@@ -0,0 +1,55 @@
const { FuseBox, Sparky, WebIndexPlugin, QuantumPlugin } = require("fuse-box");
const { src, task, watch, context, fuse } = require("fuse-box/sparky");


context(class {
getConfig() {
return FuseBox.init({
homeDir: "src",
output: "dist/$name.js",
target: "browser@es5",
hash: this.isProduction,
plugins: [
WebIndexPlugin(),
this.isProduction && QuantumPlugin({
bakeApiIntoBundle: "app",
uglify: true,
extendServerImport: true
})
]
})
}
createBundle(fuse) {
const app = fuse.bundle("app");
if (!this.isProduction) {
app.watch()
app.hmr()
}
app.instructions(">index.ts");
return app;
}
});
task("clean", () => src("dist").clean("dist").exec() )

task("launch-server", async context => {
const server = FuseBox.init({ target: "server", homeDir: "server", output: "dist/server/$name.js" })
server.bundle("server")
.completed(proc => proc.start())
.instructions(">[server.ts]").watch()
await server.run();
});

task("default", ["clean", "launch-server"], async context => {
const fuse = context.getConfig();
fuse.dev({ httpServer: false });
context.createBundle(fuse);
await fuse.run();
});

task("dist", ["clean", "launch-server"], async context => {
context.isProduction = true;
const fuse = context.getConfig();
fuse.dev(); // remove it later
context.createBundle(fuse);
await fuse.run();
});
9 changes: 9 additions & 0 deletions examples/custom-server/server/server.ts
@@ -0,0 +1,9 @@
import * as express from "express";
import * as path from "path";

const app = express()

app.use(express.static(path.resolve("dist")))


app.listen(3000, () => console.log('Example app listening on port 3000!'))
10 changes: 10 additions & 0 deletions examples/custom-server/server/tsconfig.json
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES6",
"jsx": "react",
"importHelpers": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
}
1 change: 1 addition & 0 deletions examples/custom-server/src/index.ts
@@ -0,0 +1 @@
console.log("hello world");
10 changes: 10 additions & 0 deletions examples/custom-server/src/tsconfig.json
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES5",
"jsx": "react",
"importHelpers": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
}

0 comments on commit efdb7a3

Please sign in to comment.