项目作者: stakodiak

项目描述 :
enable basic livereload from vim + JS snippet
高级语言: JavaScript
项目地址: git://github.com/stakodiak/vim-livereload.git
创建时间: 2018-12-14T02:25:43Z
项目社区:https://github.com/stakodiak/vim-livereload

开源协议:GNU Affero General Public License v3.0

下载


vim command + JS snippet for crapshoot livereload

screen recording

  1. " use in vim
  2. :autocmd BufWritePost * execute "!echo `date` > %.update"
  1. <!-- add in webpage -->
  2. <script src="https://www.alexstachowiak.com/livereload.js"></script>

The Algorithm

  1. Serve files using python -m SimpleHTTPServer 8869
  1. Update a file, "$file.update", on save

    1. :autocmd BufWritePost * execute "!echo `date` > %.update"
  2. Reload webpage when change is detected

    1. /* Also at: https://www.alexstachowiak.com/livereload.js */
    2. <script>
    3. let current = null;
    4. setInterval(() => {
    5. fetch(window.location.href + '.update')
    6. .then(r => r.text())
    7. .then(content => {
    8. if (current == null)
    9. current = content;
    10. else if (current != content)
    11. window.location.href = window.location.href;
    12. })
    13. }, 1000);
    14. </script>

Works for index.html, etc., but the save command will need to be updated if the file and URL don’t share a name.