]> Untitled Git - lemmy-ui.git/blob - fuse.ts
9de9d564a185e7274f6d5a62c5cd9ae873e5005a
[lemmy-ui.git] / fuse.ts
1 import { CSSPlugin, FuseBox, FuseBoxOptions, Sparky } from 'fuse-box';
2 import path = require('path');
3 import TsTransformClasscat from 'ts-transform-classcat';
4 import TsTransformInferno from 'ts-transform-inferno';
5 /**
6  * Some of FuseBoxOptions overrides by ts config (module, target, etc)
7  * https://fuse-box.org/page/working-with-targets
8  */
9 let fuse: FuseBox;
10 const fuseOptions: FuseBoxOptions = {
11   homeDir: './src',
12   output: 'dist/$name.js',
13   sourceMaps: { inline: false, vendor: false },
14   /**
15    * Custom TypeScript Transformers (compile Inferno tsx to ts)
16    */
17   transformers: {
18     before: [TsTransformClasscat(), TsTransformInferno()],
19   },
20 };
21 const fuseClientOptions: FuseBoxOptions = {
22   ...fuseOptions,
23   plugins: [
24     /**
25      * https://fuse-box.org/page/css-resource-plugin
26      * Compile Sass {SassPlugin()}
27      * Make .css files modules-like (allow import them like modules) {CSSModules}
28      * Make .css files modules like and allow import it from node_modules too {CSSResourcePlugin}
29      * Use them all and bundle with {CSSPlugin}
30      * */
31     CSSPlugin(),
32   ],
33 };
34 const fuseServerOptions: FuseBoxOptions = {
35   ...fuseOptions,
36 };
37
38 Sparky.task('clean', () => {
39   /**Clean distribute (dist) folder */
40   Sparky.src('dist/').clean('dist/');
41 });
42 Sparky.task('config', () => {
43   fuse = FuseBox.init(fuseOptions);
44   fuse.dev();
45 });
46 Sparky.task('test', ['&clean', '&config'], () => {
47   fuse.bundle('client/bundle').test('[**/**.test.tsx]', null);
48 });
49 Sparky.task('client', () => {
50   fuse.opts = fuseClientOptions;
51   fuse
52     .bundle('client/bundle')
53     .target('browser@esnext')
54     .watch('client/**')
55     .hmr()
56     .instructions('> client/index.tsx');
57 });
58 Sparky.task('copy-assets', () =>
59   Sparky.src('**/**.*', { base: 'src/assets' }).dest('dist/assets')
60 );
61 Sparky.task('server', () => {
62   /**Workaround. Should be fixed */
63   fuse.opts = fuseServerOptions;
64   fuse
65     .bundle('server/bundle')
66     .watch('**')
67     .target('server@esnext')
68     .instructions('> [server/index.tsx]')
69     .completed(proc => {
70       proc.require({
71         // tslint:disable-next-line:no-shadowed-variable
72         close: ({ FuseBox }) => FuseBox.import(FuseBox.mainFile).shutdown(),
73       });
74     });
75 });
76 Sparky.task(
77   'dev',
78   ['&clean', '&config', '&client', '&server', '&copy-assets'],
79   () => {
80     fuse.run();
81   }
82 );