https://github.com/softonic/marko-hot-reload
Watch changes in Marko templates in a directory and notify Marko to hot reload them
https://github.com/softonic/marko-hot-reload
Last synced: about 1 year ago
JSON representation
Watch changes in Marko templates in a directory and notify Marko to hot reload them
- Host: GitHub
- URL: https://github.com/softonic/marko-hot-reload
- Owner: softonic
- License: other
- Created: 2017-06-22T15:25:57.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-03T05:08:49.000Z (over 3 years ago)
- Last Synced: 2025-03-24T19:39:41.552Z (about 1 year ago)
- Language: JavaScript
- Size: 102 KB
- Stars: 3
- Watchers: 6
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# marko-hot-reload
Watch changes in Marko templates in a folder and notify Marko to hot reload them.
## Installation
```bash
npm install marko-hot-reload
```
or with `yarn`:
```bash
yarn add marko-hot-reload
```
## Usage
```js
const markoHotReload = require('marko-hot-reload');
const requiredTemplatesPath = '/path/to/templates/folder';
const requiredPageTemplatesPath = '/path/to/pages/folder';
// These options can prevent some issues on some Mac machines
const optionalChokidarWatchOptions = {
usePolling: true,
interval: 1000,
useFsEvents: false,
};
const optionalFileModifiedOptions = {
silent: true,
};
const optionalLogger = {
info: () => {},
error: () => {},
};
markoHotReload.enable({
templatesPath: requiredTemplatesPath,
pageTemplatesPath: requiredPageTemplatesPath,
watchOptions: optionalChokidarWatchOptions,
fileModifedOptions: optionalFileModifiedOptions,
logger: optionalLogger,
});
```
## The way it works
Given this folders structure, with `templatesPath` = "/client/views" & `pageTemplatesPath`= "/client/views/pages" :
```bash
client
views
components
layout
desktop-layout.tpl
mobile-layout.tpl
components
header.tpl
pages
faq
desktop-index.tpl
mobile-index.tpl
home
desktop-index.tpl
mobile-index.tpl
```
Whenever `header.tpl` is modified, the Hot Reload will invalidates it & all its direct ancestors up to the templates folder, as well as all the page templates. I.e. all the files invalidated are:
- /client/views/layout/components/header.tpl
- /client/views/layout/desktop-layout.tpl
- /client/views/layout/mobile-layout.tpl
- /client/views/pages/faq/desktop-index.tpl
- /client/views/pages/faq/mobile-index.tpl
- /client/views/pages/home/desktop-index.tpl
- /client/views/pages/home/mobile-index.tpl
## Contribute
1. Fork it: `git clone https://github.com/softonic/marko-hot-reload.git`
2. Create your feature branch: `git checkout -b feature/my-new-feature`
3. Commit your changes: `git commit -am 'Added some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D