-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuse.js
93 lines (83 loc) · 2.42 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
//@ts-check
const {
FuseBox,
SVGPlugin,
CSSPlugin,
CSSResourcePlugin,
QuantumPlugin,
WebIndexPlugin,
Sparky,
JSONPlugin,
RawPlugin,
} = require("fuse-box");
const rimraf = require("rimraf"); //fuse-box can 'clean' but this works better for me
const historyFallback = require( 'connect-history-api-fallback')
var browserSync = require("browser-sync").create();
let fuse, app, vendor, isProduction; //isProduction set by sparky task 'prod'.
Sparky.task("config", () => {
fuse = new FuseBox({
homeDir: "src",
sourceMaps: !isProduction, //so you can see nicely formated code for debugging
hash: isProduction, // what's this?
output: "dist/$name.js", // where did $name from?
useTypescriptCompiler: true, // makes sense
experimentalFeatures: true, // what's this?
target: "browser",
plugins: [
CSSPlugin(),
SVGPlugin(), // for importing
JSONPlugin(), // for importing
RawPlugin([".frag", ".vert"]),
WebIndexPlugin({
// to create an index.html file in dist
template: "src/react/index.html"
}),
isProduction &&
QuantumPlugin({
// reduce bundle size
treeshake: false, //remove unused code
uglify: true // tightly pack the js
})
]
});
vendor = fuse.bundle("vendor").instructions("~ react/index.jsx"); // what's ~ mean?
app = fuse.bundle("app").instructions("> [react/index.jsx]"); // what's > [] mean?
});
Sparky.task("rmDist", () => {
//clean wasn't removing the maps
rimraf.sync("./dist");
rimraf.sync("./.fusebox");
});
Sparky.task("setProdTrue", () => {
isProduction = true;
});
// async load this stuff with fetch, $.get etc. not import
Sparky.task("copyAssets", () => {
return Sparky.src("./assets/**/*", { base: "./src" }).dest("./dist");
});
Sparky.task("browserSync", () => {
browserSync.init({
server: {
baseDir: "./dist",
middleware: [
historyFallback()
]
}
});
});
//node fuse.js dev runs the bellow. you could try hmr with app.watch().hmr()
Sparky.task("dev", ["rmDist", "browserSync", "config"], () => {
app.watch().completed(() => {
browserSync.reload();
});
return fuse.run();
});
//node fuse.js prod runs the bellow
Sparky.task("prod", ["setProdTrue", "rmDist", "config"], () => {
return fuse.run();
});
Sparky.task("default", () => {
console.log(
"no arg given to fuse.js: use 'node fuse.js dev' or 'node fuse.js prod'"
);
});