TLDR; You have to start the http server (simple-http) and load your HTML files through it.
For example, let's say you have a HTML file named hello.html
and a JS script file named script.js
in /home/user/Documents/javascript
folder.
hello.html:
<!doctype html>
<html>
<head>
<!-- Include skewer.js as a script -->
<script src="http://localhost:8080/skewer"></script>
<!-- Include my script.js file -->
<script src="script.js"></script>
</head>
<body>
<p>Hello world</p>
</body>
</html>
script.js:
alert('hey!');
init.el (or .emacs):
(require 'simple-httpd)
;; set root folder for httpd server
(setq httpd-root "/home/user/Documents/javascript")
It's time to start the server: M-x httpd-start
, and open the index.html
file in the browser, by visiting http://localhost:8080/hello.html
. You should get the alert in the browser and now call skwer-repl
.
You can further interact with the browser through the repl. So, everything you evaluate in the repl will be transmitted to the browser. For example if you type console.log('hey!')
in the repl, you will get this message in the browser's console.
If you want to interactively modify HTML (e.g. live update HTML tags from emacs), add to your
init.el (or .emacs):
(add-hook 'html-mode-hook 'skewer-html-mode)
Now when you are in your .html file you can evaluate tags with C-M-x (skewer-html-eval-tag
), and these will be immediately updated in your browser.
Keep in mind that conversely, this also applies to CSS and CSS files.
boids.js
buffer?C-x C-k
does not work inskewer-html-mode