Skip to content

Commit

Permalink
hmr example
Browse files Browse the repository at this point in the history
  • Loading branch information
nchanged committed Feb 6, 2020
1 parent bbebc58 commit 1eaa8e9
Show file tree
Hide file tree
Showing 12 changed files with 2,170 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions hmr-plugin-example/fuse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { fusebox } from 'fuse-box';
import * as path from 'path';
const fuse = fusebox({
cache: true,
devServer: true,
entry: 'src/index.ts',
hmr : { plugin : "src/hmr.ts"},
target: 'browser',
webIndex: {
template: 'src/index.html',
},
});

fuse.runDev({
bundles: {
app: 'app.js',
distRoot: path.join(__dirname, 'dist'),
},
});
15 changes: 15 additions & 0 deletions hmr-plugin-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"author": "",
"description": "",
"devDependencies": {
"fuse-box": "4.0.0-alpha.302",
"node-sass": "^4.13.1"
},
"license": "ISC",
"main": "index.js",
"name": "hmr-plugin-example",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.0.0"
}
3 changes: 3 additions & 0 deletions hmr-plugin-example/src/components/BarComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const BarComponent = "BarComponentString"
export default BarComponent;

3 changes: 3 additions & 0 deletions hmr-plugin-example/src/components/FooComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const FooComponentString = "FooComponentString"
export default FooComponentString;

16 changes: 16 additions & 0 deletions hmr-plugin-example/src/hmr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HMRHelper, HMRPayload } from "fuse-box/types/hmr";
export default function(payload: HMRPayload, helper: HMRHelper) {
const { updates } = payload;
if (helper.isStylesheeetUpdate) {
helper.flushModules(updates);

helper.updateModules()

helper.callModules(updates);
} else {
helper.flushAll();
helper.updateModules()

helper.callEntries();
}
}
14 changes: 14 additions & 0 deletions hmr-plugin-example/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta content="ie=edge" http-equiv="X-UA-Compatible" />
<title></title>

</head>
<body>
<div id="root"></div>
$bundles
</body>
</html>
6 changes: 6 additions & 0 deletions hmr-plugin-example/src/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import "other";

#root {
height: 500px;
width: 100%;
}
14 changes: 14 additions & 0 deletions hmr-plugin-example/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import "./index.scss";

async function main(){
const foo = await import("./components/FooComponent")
const bar = await import("./components/BarComponent");

document.getElementById("root").innerHTML = `
<div class="foo">${foo.default}</div>
<div class="bar">${bar.default}</div>
`
}


main();
12 changes: 12 additions & 0 deletions hmr-plugin-example/src/other.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#root {
background-color: white;
border: 1px solid hotpink;
padding: 20px;
}

.foo {
color:red;
}
.bar {
color: green;
}
Loading

0 comments on commit 1eaa8e9

Please sign in to comment.