如何使用Middleman v4.2正确设置livereload?

时间:2019-07-14 07:41:49

标签: ruby bundler middleman livereload middleman-4

我没有使用Ruby或Gem的丰富经验,但是我正在尝试将另一个存储库的副本复制到我的计算机上以进行本地开发。

我能够在localhost上成功建立站点,但是似乎无法设置livereload扩展。

我对Ruby的语法不太熟悉,所以希望有人可以纠正我,如果我做错了事,因为livereload根本对我不起作用。

当我进入项目目录并运行bundle exec middleman时,在命令提示符下得到以下内容:

== The Middleman is loading
  Please add the following to your Gemfile to avoid polling for changes:
    gem 'wdm', '>= 0.1.0' if Gem.win_platform?
== LiveReload accepting connections from ws://192.168.1.56:35729
#<Thread:0x0000000005b20368@C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/middleman-livereload-3.4.6/lib/middleman-livereload/reactor.rb:44 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        7: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/middleman-livereload-3.4.6/lib/middleman-livereload/reactor.rb:45:in `block in start_threaded_reactor'
        6: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.7-x64-mingw32/lib/eventmachine.rb:196:in `run'
        5: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:144:in `run_machine'
        4: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:562:in `run'
        3: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:559:in `ensure in run'
        2: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:559:in `each'
        1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:559:in `block in run'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:559:in `close': Bad file descriptor (Errno::EBADF)
  Please add the following to your Gemfile to avoid polling for changes:
    gem 'wdm', '>= 0.1.0' if Gem.win_platform?

如果我对sources目录中的script.js文件进行了更改,则好像livereload正在监视文件,因为在命令提示符下,我得到了:

= LiveReloading path: /javascripts/script.js
== LiveReloading path: /assets/uswds/js/uswds.js
== LiveReloading path: /assets/uswds/js/uswds.min.js
== LiveReloading path: /javascripts/site.js

但是,我看不到localhost:4567上的实时变化(即,alert('testing')直到刷新后才会弹出)。

我在这里做错什么了吗?希望能对您的设置有所帮助。很多Google搜索只显示了大约2-3年前的问题,而我看不到任何与我的问题相关的信息。

GemFile:

gem 'middleman', '~> 4.2'
gem 'middleman-autoprefixer', '~> 2.7'
gem 'tzinfo-data', platforms: [:mswin, :mingw, :jruby]
gem 'wdm', '~> 0.1', platforms: [:mswin, :mingw]
gem "middleman-livereload", "~> 3.4.3"
gem 'eventmachine', '~> 1.2', '>= 1.2.7'
gem 'em-websocket', '~> 0.5.1'

config.rb

# Activate and configure extensions
# https://middlemanapp.com/advanced/configuration/#configuring-extensions

activate :autoprefixer do |prefix|
  prefix.browsers = "last 2 versions"
end
activate :livereload

page '/*.xml', layout: false
page '/*.json', layout: false
page '/*.txt', layout: false

helpers do
  def is_page_selected(page)
    if current_page.url == page
      return ' class="usa-current"'
    end
    case page
    when '/designphase.html'
      if current_page.url == "/team.html" || current_page.url == "/participants.html" || current_page.url == "/publicsector.html" || current_page.url == "/designchange.html"
        return ' class="usa-current"'
      end
    when '/communicatingideas.html'
      if current_page.url == "/envisioning.html" || current_page.url == "/ideation.html" || current_page.url == "/iteration.html" || current_page.url == "/feedback.html"
        return ' class="usa-current"'
      end
    end
    return ''
  end
end

本地宝石列表:

activesupport (5.0.7.2, 5.0.7.1)
addressable (2.6.0, 2.5.2)
autoprefixer-rails (8.6.5)
backports (3.15.0, 3.11.4)
bigdecimal (default: 1.3.4)
bundler (1.17.1)
cmath (default: 1.0.0)
coffee-script (2.4.1)
coffee-script-source (1.12.2)
compass-import-once (1.0.5)
concurrent-ruby (1.1.5, 1.1.3)
contracts (0.13.0)
csv (default: 1.0.0)
date (default: 1.0.0)
dbm (default: 1.0.0)
did_you_mean (1.2.0)
dotenv (2.7.4, 2.5.0)
em-websocket (0.5.1)
erubis (2.7.0)
etc (default: 1.0.0)
eventmachine (1.2.7 x64-mingw32)
execjs (2.7.0)
fast_blank (1.0.0)
fastimage (2.1.5)
fcntl (default: 1.0.0)
ffi (1.11.1 x64-mingw32, 1.9.25 x64-mingw32)
fiddle (default: 1.0.0)
fileutils (default: 1.0.2)
gdbm (default: 2.0.0)
haml (5.1.1, 5.0.4)
hamster (3.0.0)
hashie (3.6.0)
http_parser.rb (0.6.0)
i18n (0.9.5, 0.7.0)
io-console (default: 0.4.6)
ipaddr (default: 1.2.0)
json (default: 2.1.0)
kramdown (1.17.0)
listen (3.0.8)
memoist (0.16.0)
middleman (4.2.1)
middleman-autoprefixer (2.9.0)
middleman-cli (4.2.1)
middleman-core (4.2.1)
middleman-livereload (3.4.6)
minitest (5.11.3, 5.10.3)
net-telnet (0.1.1)
openssl (default: 2.1.2)
padrino-helpers (0.13.3.4)
padrino-support (0.13.3.4)
parallel (1.17.0, 1.12.1)
power_assert (1.1.1)
psych (default: 3.0.2)
public_suffix (3.1.1, 3.0.3)
rack (2.0.7, 2.0.6)
rack-livereload (0.3.17)
rake (12.3.0)
rb-fsevent (0.10.3)
rb-inotify (0.10.0, 0.9.10)
rdoc (default: 6.0.1)
sass (3.4.25)
sassc (2.0.1)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
servolux (0.13.0)
stringio (default: 0.0.1)
strscan (default: 1.0.0)
temple (0.8.1, 0.8.0)
test-unit (3.2.7)
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.9)
tzinfo (1.2.5)
tzinfo-data (1.2018.9)
uglifier (3.2.0)
wdm (0.1.1)
webrick (default: 1.4.2)
xmlrpc (0.3.0)
zlib (default: 1.0.0)

0 个答案:

没有答案