-
Notifications
You must be signed in to change notification settings - Fork 3
/
fuse.js
92 lines (81 loc) · 2.38 KB
/
fuse.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const { FuseBox, WebIndexPlugin, BabelPlugin, EnvPlugin, QuantumPlugin, SVGPlugin } = require('fuse-box')
const path = require('path')
const express = require('express')
var compression = require('compression')
const TypeHelper = require('fuse-box-typechecker').TypeHelper
const PORT = process.env.PORT || 3030
const isProduction = !!process.env.NODE_ENV
var typeHelper = TypeHelper({
tsConfig: './tsconfig.json',
basePath: './',
name: 'Typechecker',
yellowOnOptions: true
})
const client = FuseBox.init({
target: 'browser',
homeDir: 'packages/client',
plugins: [
SVGPlugin(),
EnvPlugin({
API_URL: process.env.API_URL || `http://localhost:${PORT}`,
DB_USERNAME: process.env.DB_USERNAME,
DB_HOST: process.env.DB_HOST,
NODE_ENV: 'development'
}),
WebIndexPlugin({
template: './packages/client/index.html',
path: '/static/'
}),
isProduction &&
QuantumPlugin({
removeExportsInterop: false,
uglify: true,
treeshake: true
})
],
output: 'dist/static/$name.js',
alias: {
react: 'preact-compat',
'react-dom': 'preact-compat'
}
})
client
.bundle('client')
.watch('client/**')
.instructions(`>src/index.tsx`)
.completed(() => typeHelper.runSync())
client.dev({ root: false }, server => {
const dist = path.resolve('./dist')
const app = server.httpServer.app
app.use(compression())
app.use('/static/', express.static(path.join(dist, 'static')))
app.get('*', function(req, res) {
res.sendFile(path.join(dist, 'static/index.html'))
})
})
client.run()
const server = FuseBox.init({
target: 'server',
homeDir: 'packages/server',
output: 'dist/server/$name.js',
plugins: [
EnvPlugin({
PORT,
DB_PASSWORD: process.env.DB_PASSWORD,
DB_USERNAME: process.env.DB_USERNAME,
DB_HOST: process.env.DB_HOST,
NODE_ENV: 'development'
})
]
})
server.dev({ port: 4455, httpServer: false })
server
.bundle('server')
.watch('server/**') // watch only server related code.. bugs up atm
.instructions(' > [src/index.ts]')
// launch and restart express
.completed(proc => {
proc.start()
typeHelper.runSync()
})
server.run()