【发布时间】:2014-10-02 23:21:39
【问题描述】:
我正在使用带有引导程序的 Rails 4 应用程序。在某些时候,资产编译变得无聊,现在如果我对 SCSS 文件进行任何更改,重新加载页面需要一分钟多的时间。更改 JS 文件不会导致此延迟。我不知道是什么原因造成的,但是当我尝试自己预编译资产时,该过程大约需要 2 秒才能完成。不知道为什么当它在飞行中发生时需要一分钟以上,有时超过 2 分钟。
我正在使用带有 livereload 的守卫,当我在样式表中保存更改时,页面被 livereloaded 但没有任何样式表。如果我重新加载页面,渲染需要一分钟。我希望有一些明显的东西我只是错过了,有人发现了它。
在进行故障排除时,我切换了配置,以便在 application.css.scss 中加载 scss 文件(使用 *= require 语法),然后在每个文件中导入引导变量和 mixins,但这同样慢。我还尝试使用 CDN 引导程序,然后覆盖,但速度几乎一样慢,而且覆盖这么多类令人头疼。
延迟是在布局的渲染过程中,但它只发生在我对样式表进行更改时。任何其他更改都会立即加载。
我有一堆设计/css 工作需要做,而这个问题几乎是不可能的。请帮忙。
(我可能还应该在这里发布一些其他文件。请告诉我,我会发布它。)
这是我的 gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=networkrf
gem 'rails', '4.0.1'
gem 'pg', '0.15.1'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'sass-rails', '>= 3.2'
gem 'autoprefixer-rails'
gem 'bcrypt-ruby', '3.1.2'
gem 'faker', '1.1.2'
gem 'will_paginate', '3.0.4'
gem 'bootstrap-will_paginate', '0.0.9'
gem 'font-awesome-rails'
gem 'httparty'
gem 'gmaps4rails'
gem 'geocoder'
gem 'sprockets_better_errors'
group :development, :test do
gem 'thin'
end
group :development, :test do
gem 'rspec-rails', '2.13.1'
gem 'guard-rspec', '2.5.0'
gem 'spork-rails', github: 'sporkrb/spork-rails'
gem 'childprocess', '0.3.6'
gem 'guard-livereload', require: false
gem 'guard-spork', '1.5.0'
gem 'rack-livereload'
gem 'rb-fsevent', require: false
gem 'factory_girl_rails', '4.2.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
gem 'growl', '1.0.3'
gem 'capybara-screenshot'
gem 'launchy'
end
# gem 'sass-rails', '4.0.0'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.0'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'rails_12factor'
gem 'unicorn'
gem 'newrelic_rpm'
end
# gem 'fog'
# gem 'rmagick', '2.13.2'
# gem 'carrierwave'
这里是 development.rb
Networkrf::Application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.compress = false
config.assets.debug = true
config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload)
config.assets.raise_production_errors = true
end
应用程序.rb
require File.expand_path('../boot', __FILE__)
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
require "csv"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module Networkrf
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
end
end
application.css.scss
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require font-awesome
*= require main
*/
main.css.scss
/**
*
* Loads all stylesheets for the application in order
*
**/
@import "bootstrap-custom";
@import "variables";
@import "theme";
@import "base";
@import "components";
@import "nav";
@import "home";
@import "scenes";
@import "custom";
@import "typography";
@import "utility";
rack-mini-test gem 输出:
还有什么我可以补充的吗?或任何要运行的测试?
【问题讨论】:
标签: ruby-on-rails twitter-bootstrap ruby-on-rails-4 sass asset-pipeline