Merge pull request #7 from JulianWebb/hot-reload

Hot reload
This commit is contained in:
Nicola 2021-04-26 22:39:32 +02:00 committed by GitHub
commit 81abc75b1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9641 additions and 47 deletions

9650
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,11 +6,17 @@
"scripts": {
"build": "node ./build.js ./build",
"serve": "node ./server.js ./build 3000",
"test": "npm run build && npm run serve"
"test": "npm run build && npm run serve",
"hot": "concurrently \"nodemon --exec npm test\" \"await tcp localhost:3000 && open-cli http://localhost:3000\""
},
"author": "Lospec",
"license": "ISC",
"nodemonConfig": {
"ext": "js,hbs,scss",
"ignore": "build/"
},
"dependencies": {
"concurrently": "^6.0.2",
"express": "^4.16.4",
"fs-extra": "^7.0.1",
"gulp": "^4.0.2",
@ -20,7 +26,12 @@
"gulp-sass": "^4.0.2",
"handlebars-helper-svg": "git+https://bitbucket.org/skeddles/npm-handlebars-helper-svg-lospec-open-source.git",
"nodemon": "^2.0.7",
"open": "^6.0.0",
"open": "^8.0.6",
"open-cli": "^6.0.1",
"sass": "^1.17.3"
},
"devDependencies": {
"reload": "^3.1.1",
"wait-cli": "^1.0.0"
}
}

View File

@ -1,6 +1,6 @@
const path = require('path');
const express = require('express');
const reload = require('reload');
const app = express();
const BUILDDIR = process.argv[2] || './build';
@ -13,6 +13,11 @@ app.get('/', (req, res) => {
console.log('error sending file', err);
} else {
console.log("Server: Successfully served index.html");
setTimeout(()=>{
console.log('closing server');
res.app.server.close();
process.exit();
},1000*10);
}
});
});
@ -20,14 +25,9 @@ app.get('/', (req, res) => {
//ROUTE - other files
app.use(express.static(path.join(__dirname, BUILDDIR)));
//start server
var server = app.listen(PORT, () => {
console.log(`\nTemp server started at http://localhost:${PORT}!`);
//console.log('press ctrl+c to stop ');
var opn = require('open');
// opens the url in the default browser
opn(`http://localhost:${PORT}`);
reload(app).then(() => {
//start server
app.server = app.listen(PORT, function () {
console.log('Web server listening on port ' + PORT)
})
});

View File

@ -621,5 +621,6 @@
</script>
<script src="/pixel-editor/pixel-editor.js"></script>
<script src="/reload/reload.js"></script>
</body>
</html>