# Is there a faster way to develop plugin theme CSS / JS (e.g. livereload)?

**URL:** https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859
**Category:** Development
**Created:** [June 3, 2017, 12:45am UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859 "2017-06-03T00:45:50Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![kara-todd](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kara-todd/32/73219_2.png) [@kara-todd](https://meta.discourse.org/u/kara-todd)
#### Post date: [June 3, 2017, 12:45am UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/1 "2017-06-03T00:45:50Z")

</div>

Hey there,

I’m trying develop a custom theme/plugin which will add a few additional templates and some general styling to discourse.

In pursuit of this, it would be great to get some kind of livereload/auto-injected CSS action going on, as reloading the page and wating 2s to notice I have made a typo is slowly adding up to quite a significant chunk of time. 🙂

It seems like the [recommendation is to use autopec](https://meta.discourse.org/t/development-mode-super-slow/2179/65), but I’m a little confused as to how this is supposed to work.

I have discourse setup and running locally using vagrant. I’ve ssh’d into the box and can run the server, see the admin page etc.

Should I run autospec and then start the server? or vice-versa? Will this effectively work to live reload the CSS so that I don’t have to refresh the app? Or am I just completely off-base here?

Any suggestions would be appreciated. 🙂

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 3, 2017, 1:27am UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/2 "2017-06-03T01:27:34Z")

</div>

> [@kara-todd](#):
>
> auto-injected CSS

This already works, just click preview on the theme and it will update as you go.

---

<div class="post-metadata">

### Author: ![kara-todd](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kara-todd/32/73219_2.png) [@kara-todd](https://meta.discourse.org/u/kara-todd)
#### Post date: [June 3, 2017, 1:31am UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/3 "2017-06-03T01:31:26Z")

</div>

Thanks @sam I think I wasn’t clear in this case.

I’m not developing a theme in the CSS section of the admin panel.

Rather, I’m creating a plugin which contains raw scss files which “themes” the discourse instance and also some of the custom elements that I will be injecting into outlets.

So I have a css files being loaded by my plugin:

```
plugin.rb
register_asset "stylesheets/base-theme.scss"

```

I’d really like to get these live reloading (similar to guard-livereload,)

Developing in the admin isn’t really sustainable from my viewpoint as there are going to be several developers working on files and having version control / git commit flow process is a pretty high priority.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 3, 2017, 1:33am UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/4 "2017-06-03T01:33:41Z")

</div>

I think the live reloader should work as long as you launch puma

> <https://github.com/discourse/discourse/blob/main/lib/stylesheet/watcher.rb#L13>

---

<div class="post-metadata">

### Author: ![kara-todd](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kara-todd/32/73219_2.png) [@kara-todd](https://meta.discourse.org/u/kara-todd)
#### Post date: [June 3, 2017, 1:38am UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/5 "2017-06-03T01:38:23Z")

</div>

Ok. I think this my confusion.

So for example,

I start my server with `bundle exec rails s -b 0.0.0.0` and then visit my local environment at `http://127.0.0.1:4000/` (bound port through vagrant.)

If I then make any changes to the scss I don’t see any changes until I manually refresh the page (which takes a few seconds.)

If I understand correctly, puma should be running when I `bundle exec rails` and changes _are_ being picked up but I just have to hit reload on the page… the styles are not injected into the app live…

Am I missing a step?

---

<div class="post-metadata">

### Author: ![kara-todd](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kara-todd/32/73219_2.png) [@kara-todd](https://meta.discourse.org/u/kara-todd)
#### Post date: [June 3, 2017, 1:41am UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/6 "2017-06-03T01:41:47Z")

</div>

I have been previously been developing a standalone ember app so I have been hopelessly spoiled by `ember server` 😉

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 3, 2017, 1:48am UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/7 "2017-06-03T01:48:47Z")

</div>

Try bundle exec puma, does it work?

I will test out plugin live reload on Monday I may have missed something

Certainly works for themes and discourse assets

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 3, 2017, 1:53am UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/8 "2017-06-03T01:53:56Z")

</div>

Link me to the plugin repo you have, either here or via a pm so I have something to test 😊

---

<div class="post-metadata">

### Author: ![kara-todd](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kara-todd/32/73219_2.png) [@kara-todd](https://meta.discourse.org/u/kara-todd)
#### Post date: [June 5, 2017, 2:45am UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/9 "2017-06-05T02:45:24Z")

</div>

As an update to this @sam here’s what I’m seeing when I boot my server. I PM’d you details for the codebase I’m using.

```
vagrant@discourse:/vagrant$ bundle exec rails s -b 0.0.0.0
=> Booting Puma
=> Rails 4.2.8 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Staring CSS change watcher
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://0.0.0.0:3000D

```

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 5, 2017, 2:37pm UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/10 "2017-06-05T14:37:11Z")

</div>

I just confirmed that live-reload works fine with the plugin you linked me.

The issue is vagrant. Vagrant mounts stuff in a terrible way and breaks inotify/kqueue file change notification. This leaves you stuck with all file watching broken from what I can see.

I recommend you avoid vagrant and just do a local Discourse install.

For my test,

1. I checked out your plugin
2. Ran `bin/puma`
3. Edited header.scss and added `body { background-color: red !important; }
4. The background turned red, no need to reload the page or anything.

---

<div class="post-metadata">

### Author: ![kara-todd](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kara-todd/32/73219_2.png) [@kara-todd](https://meta.discourse.org/u/kara-todd)
#### Post date: [June 5, 2017, 10:51pm UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/11 "2017-06-05T22:51:48Z")

</div>

Thanks Sam!

I followed the [instructions for setting up discourse locally](https://github.com/discourse/discourse/blob/master/docs/DEVELOPMENT-OSX-NATIVE.md) and now it’s working for me as well. 😃

This will make my life much easier so thank you very much for your time on this.

---

<div class="post-metadata">

### Author: ![eatcodetravel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eatcodetravel/32/94385_2.png) [@eatcodetravel](https://meta.discourse.org/u/eatcodetravel)
#### Post date: [January 19, 2018, 10:29pm UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/12 "2018-01-19T22:29:32Z")

</div>

Hey @sam,

Should this work for JavaScript files too?, I’m trying it but I have to remove the cache every time I add/edit a file.

I added this line to see if sprockets pick up new changes and it works without removing the cache.

```ruby
# config/environments/development.rb
config.assets.paths += %W(#{config.root}/plugins/<plugin-name>/assets/javascripts/**/*)

```

Should we add this by default in development? (for all plugins instead of a specific one), or there’s a better way?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 23, 2018, 7:47am UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/13 "2018-03-23T07:47:00Z")

</div>

I am cleaning up my bookmarks, @eviltrout you do a lot of JS are you noticing any cache issues amending JS in plugins? Do we need to add an assets.path?

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [March 23, 2018, 3:15pm UTC](https://meta.discourse.org/t/is-there-a-faster-way-to-develop-plugin-theme-css-js-e-g-livereload/63859/14 "2018-03-23T15:15:21Z")

</div>

No, Javascript is more or less perfect for editing, plugins and all. The only time you have to clear tmp is when you add or remove one.

The reloading issues I have are always on the server side.
