Skip to content

Commit 5a8d707

Browse files
committed
initial
1 parent 3782c8f commit 5a8d707

File tree

19 files changed

+3146
-1
lines changed

19 files changed

+3146
-1
lines changed

.DS_Store

6 KB
Binary file not shown.

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_size = 2
6+
indent_style = tab
7+
quote_type = double
8+
9+
insert_final_newline = true
10+
max_line_length=120
11+
trim_trailing_whitespace = true
12+
13+
[*.{json,md,yml,yaml}]
14+
indent_style = space
15+
16+
[*.md]
17+
max_line_length=80
18+
trim_trailing_whitespace = false

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ pids
1010
*.pid
1111
*.seed
1212
*.pid.lock
13-
13+
.fusebox
14+
.vscode
15+
dist
1416
# Directory for instrumented libs generated by jscoverage/JSCover
1517
lib-cov
1618

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Fuse react demo
2+
3+
This demo demostrates the following
4+
5+
- [fuse-react](https://github.com/fuse-box/fuse-react) router and lazy loading
6+
- FuseBox automatic JS Code Splitting
7+
- FuseBox automatic CSS Code Splitting
8+
9+
## Install and run
10+
11+
```
12+
npm install;
13+
node fuse dist
14+
```
15+
16+
If you want to run it in development mode
17+
18+
```
19+
node fuse
20+
```

fuse.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const { src, task, context, bumpVersion } = require("fuse-box/sparky");
2+
const { FuseBox, QuantumPlugin, CSSPlugin, SassPlugin, WebIndexPlugin } = require("fuse-box");
3+
4+
task("default", async context => {
5+
await context.clean();
6+
await context.development();
7+
});
8+
9+
task("dist", async context => {
10+
await context.clean();
11+
await context.dist();
12+
});
13+
14+
context(
15+
class {
16+
getConfig() {
17+
return FuseBox.init({
18+
homeDir: "src",
19+
target: "browser@es5",
20+
hash: this.isProduction,
21+
output: "dist/$name.js",
22+
plugins: [
23+
[SassPlugin(), CSSPlugin()],
24+
WebIndexPlugin({
25+
template: "src/index.html"
26+
}),
27+
this.isProduction &&
28+
QuantumPlugin({
29+
css: true,
30+
uglify: true
31+
})
32+
]
33+
});
34+
}
35+
async clean() {
36+
await src("./dist")
37+
.clean("dist/")
38+
.exec();
39+
}
40+
41+
async prepareDistFolder() {
42+
await bumpVersion("package.json", { type: "patch" });
43+
await src("./package.json")
44+
.dest("dist/")
45+
.exec();
46+
}
47+
48+
dist() {
49+
this.isProduction = true;
50+
const fuse = this.getConfig();
51+
fuse.dev({ fallback: "index.html" });
52+
fuse
53+
.bundle("demo")
54+
.splitConfig({
55+
dest: "/chunks/"
56+
})
57+
.instructions(">app.tsx");
58+
return fuse.run();
59+
}
60+
61+
development() {
62+
const fuse = this.getConfig();
63+
fuse.dev({ fallback: "index.html" });
64+
fuse
65+
.bundle("demo")
66+
.hmr()
67+
.instructions(">app.tsx")
68+
.watch();
69+
return fuse.run();
70+
}
71+
}
72+
);

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "fuse-react-demo",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/fuse-box/fuse-react-demo.git"
12+
},
13+
"author": "",
14+
"license": "ISC",
15+
"bugs": {
16+
"url": "https://github.com/fuse-box/fuse-react-demo/issues"
17+
},
18+
"homepage": "https://github.com/fuse-box/fuse-react-demo#readme",
19+
"devDependencies": {
20+
"fuse-box": "^3.5.0",
21+
"node-sass": "^4.9.3",
22+
"typescript": "^3.0.1",
23+
"uglify": "^0.1.5",
24+
"uglify-js": "^3.4.8"
25+
},
26+
"dependencies": {
27+
"fuse-react": "^1.0.19",
28+
"react": "^16.4.2",
29+
"react-dom": "^16.4.2"
30+
}
31+
}

src/app.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import * as React from "react";
2+
import * as ReactDOM from "react-dom";
3+
import { Link, Switch } from "fuse-react";
4+
import "./style.scss";
5+
6+
const config = {
7+
routes: {
8+
"/blog": {
9+
component: () => import("./routes/blog/Blog")
10+
},
11+
"/news": {
12+
component: () => import("./routes/news/News")
13+
},
14+
"/listing": {
15+
component: () => import("./routes/listing/Listing")
16+
}
17+
}
18+
};
19+
class Menu extends React.Component {
20+
public render() {
21+
const menuConfig = [
22+
{ to: "/blog", label: "Blogs" },
23+
{ to: "/news", label: "News" },
24+
{ to: "/listing", label: "Listing" }
25+
];
26+
return (
27+
<div className="menu">
28+
{menuConfig.map((item, i) => (
29+
<Link activeClassName="active" key={i} to={item.to}>
30+
{item.label}
31+
</Link>
32+
))}
33+
</div>
34+
);
35+
}
36+
}
37+
class MyRootComponent extends React.Component {
38+
public render() {
39+
return (
40+
<div className="demo">
41+
<div className="left">
42+
<Menu />
43+
</div>
44+
<div className="right">
45+
<Switch config={config} />
46+
</div>
47+
</div>
48+
);
49+
}
50+
}
51+
52+
ReactDOM.render(<MyRootComponent />, document.querySelector("#root"));

src/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title></title> $css
6+
</head>
7+
8+
<body>
9+
<div id="root"></div> $bundles
10+
</body>
11+
12+
</html>

src/routes/blog/Blog.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.blog {
2+
h1 {
3+
color: royalblue;
4+
}
5+
}

src/routes/blog/Blog.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as React from "react";
2+
import "./Blog.scss";
3+
export class Blogs extends React.Component {
4+
public render() {
5+
return (
6+
<div className="page blog">
7+
<h1>Blogs</h1>
8+
<p>
9+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
10+
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
11+
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
12+
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
13+
est laborum.
14+
</p>
15+
<p>
16+
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem
17+
aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.
18+
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni
19+
dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit
20+
amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam
21+
aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit
22+
laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea
23+
voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla
24+
pariatur
25+
</p>
26+
</div>
27+
);
28+
}
29+
}

0 commit comments

Comments
 (0)