-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuse.js
101 lines (87 loc) · 3.31 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
const { fusebox, sparky } = require('fuse-box');
const { pluginTypeChecker } = require('fuse-box-typechecker');
console.log("=====================================================================================");
class Context {
isProduction;
runServer;
getBackendConfig(prod) {
return fusebox({
target: 'server',
entry: './src/backend/main.ts',
watcher: {
enabled: !prod,
include: ['./src/backend'],
ignored: ['dist', 'dev']
},
dependencies: { ignoreAllExternal: true },
logging: { level: 'succinct' },
plugins: [pluginTypeChecker({
name: 'backend',
basePath: './src/backend',
tsConfig: '../../tsconfig',
shortenFilenames: false
})],
cache: {
enabled: true,
root: '.cache/backend'
}
});
}
getFrontendConfig(prod) {
return fusebox({
target: 'browser',
entry: './src/frontend/index.ts',
dependencies: { include: ['tslib'] },
hmr: { plugin: './src/frontend/fuseHmrPlugin.ts' },
logging: { level: 'succinct' },
webIndex: {
publicPath: './',
template: 'src/frontend/index.html'
},
plugins: [pluginTypeChecker({
name: 'frontend',
basePath: './src/frontend',
tsConfig: '../../tsconfig',
shortenFilenames: false
})],
cache: {
enabled: !prod,
root: '.cache/frontend'
},
watcher: {
enabled: !prod,
include: ['./src/frontend'],
ignored: ['dist', 'dev'],
},
devServer: {
httpServer: prod ? false : { port: 4444 },
hmrServer: prod ? false : { port: 4444, connectionURL: 'ws://127.0.0.1:4444' }
}
});
}
}
const { task, rm, src } = sparky(Context);
let watchStarted = false;
task('default', async (ctx) => {
// this is run by the [start] npm task.
await rm('./dist');
await rm('/.cache'); // been tricked by cache...
const frontendConfig = ctx.getFrontendConfig();
await frontendConfig.runDev({ bundles: { distRoot: 'dist/frontend', app: 'app.js' } });
const backendConfig = ctx.getBackendConfig();
const { onComplete } = await backendConfig.runDev({ bundles: { distRoot: 'dist/backend', app: 'app.js' } });
await src(`./resources/**/*.*`).dest(`./dist/frontend`, `resources`).exec();
onComplete((output) => {
output.server.start({ argsBefore: ['--inspect-brk'] });
});
});
task('dist', async (ctx) => {
await rm('./dist');
await rm('/.cache');
const backendConfig = ctx.getBackendConfig(true);
await backendConfig.runDev({ bundles: { distRoot: 'dist/backend', app: 'app.js' } });
const frontendConfig = ctx.getFrontendConfig(true);
await frontendConfig.runProd({ uglify: true, bundles: { distRoot: 'dist/frontend', app: 'app.js' } });
await src(`./resources/**/*.*`).dest(`./dist/frontend`, `resources`).exec();
console.log("Dist finished. the generated code is available in the /dist folder.")
});