/
fuse.js
124 lines (123 loc) · 3.17 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
require('dotenv').config();
const {
FuseBox,
Sparky,
EnvPlugin,
CSSPlugin,
CopyPlugin,
WebIndexPlugin,
QuantumPlugin,
} = require('fuse-box');
const { src, task, exec, context } = require("fuse-box/sparky");
const transformInferno = require('ts-transform-inferno').default;
const transformClasscat = require('ts-transform-classcat').default;
context(class {
getConfig() {
return FuseBox.init({
homeDir: 'src',
hash: this.isProduction,
output: 'dist/$name.js',
experimentalFeatures: true,
cache: !this.isProduction,
sourceMaps: !this.isProduction,
transformers: {
before: [ transformInferno({ classwrap: true }) ],
},
plugins: [
EnvPlugin({
PAYPAL_ENV: process.env.PAYPAL_ENV,
PAYPAL_CLIENTID: process.env.PAYPAL_CLIENTID,
NODE_ENV: this.isProduction ? 'production' : 'development',
HOST: this.isProduction
? 'https://gridgenerator.com'
: 'https://localhost:8080'
}),
CSSPlugin(),
CopyPlugin({ files: ['*.svg', '*.png', 'countries.json']}),
WebIndexPlugin({
title: 'Grid Generator',
template: 'src/app.html'
}),
this.isProduction &&
QuantumPlugin({
bakeApiIntoBundle: 'client/bundle',
treeshake: true,
uglify: false
})
]
});
}
});
task('clean', _ => Sparky.src('dist/').clean('dist/').exec());
task('env', (ctx) => {
ctx.isProduction = true;
});
task('client', async (ctx) => {
const fuse = ctx.getConfig();
if (ctx.isProduction) {
fuse
.bundle('client/bundle')
.target('browser@esnext')
.instructions('>main.tsx');
} else {
fuse
.bundle('client/bundle')
.target('browser@esnext')
.watch('**')
.hmr()
.instructions('>main.tsx');
}
await fuse.run();
});
task('data', async (ctx) => {
const fuse = ctx.getConfig();
fuse
.bundle('converter/data')
.target('browser@esnext')
.instructions('>data.ts');
await fuse.run();
})
task('server', async (ctx) => {
const fuse = ctx.getConfig();
fuse
.bundle('server/bundle')
.watch('**')
.target('server@esnext')
.instructions('> [server/server.tsx]')
.completed(proc => {
proc.require({
close: ({ FuseBox }) => FuseBox.import(FuseBox.mainFile).shutdown()
});
});
await fuse.run();
});
task('converter', async (ctx) => {
const fuse = ctx.getConfig();
fuse
.bundle('converter/index')
.target('server@esnext')
.instructions('> [server/converter.ts]')
.completed(proc => {
proc.require({
close: ({ FuseBox }) => FuseBox.import(FuseBox.mainFile).shutdown()
});
});
await fuse.run();
});
task('dev', ['clean', 'client', 'server'], async (ctx) => {
const fuse = ctx.getConfig();
fuse.dev({
proxy: {
'/auth/google': {
target: 'http://localhost:3333/',
changeOrigin: false
/*
pathRewrite: {
'^/api': '/',
},*/
}
}
});
await fuse.run();
});
task('prod', ['clean', 'env', 'client']);