Add capability of automatically reloading files
This commit is contained in:
parent
40144c1dd6
commit
632091a0d8
78
gulpfile.ts
78
gulpfile.ts
|
@ -1,7 +1,11 @@
|
||||||
import GulpClient from "gulp";
|
import browserSync, { BrowserSyncInstance } from "browser-sync";
|
||||||
|
import GulpClient, { TaskFunction } from "gulp";
|
||||||
|
import path from "upath";
|
||||||
import { Context } from "./gulp/Context.js";
|
import { Context } from "./gulp/Context.js";
|
||||||
|
|
||||||
const { dest, parallel, src } = GulpClient;
|
const { dest, parallel, series, src, watch } = GulpClient;
|
||||||
|
const { join } = path;
|
||||||
|
|
||||||
const context = new Context();
|
const context = new Context();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,3 +84,73 @@ export function Build(): Promise<void>
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reloads all browsers using `browser-sync`.
|
||||||
|
*
|
||||||
|
* @param syncer
|
||||||
|
* The browser-sync instance to work on.
|
||||||
|
*
|
||||||
|
* @param filePath
|
||||||
|
* A glob-path which points to the files which must be reloaded.
|
||||||
|
*
|
||||||
|
* @returns
|
||||||
|
* The actual task.
|
||||||
|
*/
|
||||||
|
function BrowserSync(syncer: BrowserSyncInstance, filePath?: string): TaskFunction
|
||||||
|
{
|
||||||
|
let BrowserSync: TaskFunction = (done) =>
|
||||||
|
{
|
||||||
|
if (filePath)
|
||||||
|
{
|
||||||
|
syncer.reload(filePath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
syncer.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
|
||||||
|
return BrowserSync;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds and watches the files for changes.
|
||||||
|
*/
|
||||||
|
export function Watch(): void
|
||||||
|
{
|
||||||
|
let syncer = browserSync.create();
|
||||||
|
Build();
|
||||||
|
|
||||||
|
syncer.init({
|
||||||
|
open: false,
|
||||||
|
server: context.StaticPath(),
|
||||||
|
online: false
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
context.SourcePath(context.JSDirName),
|
||||||
|
series(
|
||||||
|
JavaScript,
|
||||||
|
BrowserSync(syncer, "*.js")));
|
||||||
|
|
||||||
|
watch(
|
||||||
|
context.SourcePath(context.StyleDirName, "**", "*.css"),
|
||||||
|
series(
|
||||||
|
Styles,
|
||||||
|
BrowserSync(syncer, "*.css")));
|
||||||
|
|
||||||
|
watch(
|
||||||
|
context.SourcePath(context.AssetDirName),
|
||||||
|
series(
|
||||||
|
Assets,
|
||||||
|
BrowserSync(syncer, join(context.AssetDirName, "**", "*"))));
|
||||||
|
|
||||||
|
watch(
|
||||||
|
context.SourcePath("**", "*.html"),
|
||||||
|
series(
|
||||||
|
WebPages,
|
||||||
|
BrowserSync(syncer, "*.html")));
|
||||||
|
}
|
||||||
|
|
1492
package-lock.json
generated
1492
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -12,8 +12,10 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@manuth/eslint-plugin-typescript": "^4.0.0",
|
"@manuth/eslint-plugin-typescript": "^4.0.0",
|
||||||
"@manuth/tsconfig": "^3.0.2",
|
"@manuth/tsconfig": "^3.0.2",
|
||||||
|
"@types/browser-sync": "^2.26.3",
|
||||||
"@types/gulp": "^4.0.10",
|
"@types/gulp": "^4.0.10",
|
||||||
"@types/node": "^18.11.10",
|
"@types/node": "^18.11.10",
|
||||||
|
"browser-sync": "^2.27.10",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"eslint": "^8.23.1",
|
"eslint": "^8.23.1",
|
||||||
"gulp": "^4.0.2",
|
"gulp": "^4.0.2",
|
||||||
|
|
14
src/index.html
Normal file
14
src/index.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8'>
|
||||||
|
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
||||||
|
<title>Connect Four</title>
|
||||||
|
<meta name='viewport' content='width=device-width, initial-scale=1'>
|
||||||
|
<link rel='stylesheet' type='text/css' media='screen' href='main.css'>
|
||||||
|
<script src='main.js'></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
äh
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue