我正在使用带有引导程序的Rails 4应用程序。在某些时候,资产编译得到了加强,现在如果我对SCSS文件进行任何更改,重新加载页面需要一分多钟。更改JS文件不会导致此延迟。我不知道造成这种情况的原因,但是当我试图自己预编译资产时,这个过程大约需要2秒钟才能完成。不确定为什么当它在飞行中发生时需要一分钟,有时超过2分钟。
我正在使用带有livereload的guard,当我在样式表中保存更改时,页面是实时加载但没有任何样式表。如果我重新加载页面,渲染需要一分钟。我希望有一些显而易见的事情我只是失踪而且有人发现了它。
在进行故障排除时,我切换了配置,以便在application.css.scss中加载scss文件(使用*= require
语法),然后在每个文件中导入bootstrap变量和mixin,但这一点很慢。我也试过使用CDN引导程序然后覆盖,但也几乎一样慢,并且很难覆盖这么多类。
延迟是在渲染布局期间,但只有在我对样式表进行更改时才会发生。任何其他变化,它会立即加载。
我有一堆我需要做的设计/ css工作,这个问题几乎是不可能的。请帮忙。
(我可能会在这里发布一些其他文件。请告诉我,我会发布。)
这是我的宝石文件:
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
application.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输出:
还有什么我可以添加的吗?或任何要运行的测试?
答案 0 :(得分:0)
根据我的经验,//= require
在开发环境中比@import
快,但在某些情况下可能很麻烦