[英]Rails/Compass/Sass Compile Super Slow
I recognize that this issue has been brought up a thousand times, and I feel like I have read most other posts on it but I still can't seem to figure this one out. 我认识到这个问题已经提出了一千次,而且我觉得我已经阅读了大部分其他帖子,但我似乎仍然无法想出这一点。
I'm just starting with Ruby on Rails and am trying to use Compass/Sass/Suzy in my project. 我刚刚开始使用Ruby on Rails,我正在尝试在我的项目中使用Compass / Sass / Suzy。 They all work (mostly) but am having some issues with the compass compiler.
他们都(主要)工作但是罗盘编译器有一些问题。
First off using bundle exec compass watch
(with and without --poll
) does nothing. 首先使用
bundle exec compass watch
(有和没有--poll
)什么都不做。 (this is assuming I understand the point of this command which is that it re compiles on the fly and I don't have to refresh the page to see my changes but I could be wrong) (这是假设我理解这个命令的重点是它在运行中重新编译,我不必刷新页面来查看我的更改,但我可能是错的)
Secondly when I do refresh the page after a change to my .scss file it takes 30-35 seconds for the compile to finish and reload the page. 其次,当我在更改我的.scss文件后刷新页面时,编译完成并重新加载页面需要30-35秒。 This is unbearable.
这是无法忍受的。 I've read that there are some issues with the latest 'compass-rails' but most of the posts that said this were a few years old.
我已经读到最新的'compass-rails'存在一些问题,但大多数帖子都说这是几年之久。 Does the latest compass-rails work flawlessly or is there a common issue that causes this?
最新的罗盘轨道是否完美无缺或是否存在导致此问题的常见问题?
Since I am just learning I only have a one controller/view/scss file so I'm pretty positive I don't have any dependency loop issues. 因为我刚刚学习我只有一个控制器/视图/ scss文件所以我非常积极我没有任何依赖循环问题。
Here is how I have the project currently set up. 以下是我目前如何设置项目的方法。 (I think it is setup properly but maybe someone can point out something I've done wrong.)
(我认为它设置正确,但也许有人可以指出我做错了。)
application.rb application.rb中
require_relative 'boot'
require 'rails/all'
require 'susy'
require 'compass'
require 'breakpoint'
require 'normalize-scss'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module PersonalWeb
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.
end
end
Gemfile 的Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.18', '< 0.5'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'susy'
gem 'compass-rails'
gem 'breakpoint'
gem 'normalize-scss'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
bundle
bundle
application.css.scss application.css.scss
@import "compass";
@import "breakpoint";
@import "welcome.scss";
As a further note I had that issue where on each compile compass threw a deprecated warning. 作为进一步的说明,我遇到了这个问题,每个编译指南针都抛出了一个弃用的警告。 I followed the advice here which seemed to stop it.
我按照这里的建议似乎阻止了它。 Doubt it is involved but to prevent my ignorance getting in the way of a solution I figured I'd mention it.
怀疑它涉及但是为了防止我的无知妨碍解决方案,我想我会提到它。
EDIT 编辑
I figured I'd throw in my welcome.scss just in case there is something stupid in there I've done. 我想我会把我的welcome.scss扔进去,以防万一我做过蠢事。
welcome.scss welcome.scss
@import "normalize";
@import "partials/variables";
@import "partials/layout";
@import "partials/mixins";
@import "grids";
header {
height: 100px;
background: $blue;
color: $white;
margin-bottom: 10px;
padding: 10px;
}
.wrapper {
background: $white;
margin: 0 auto;
max-width: 900px;
}
nav {
text-align: center;
ul, li {
padding: 0;
}
li {
background: $gray;
}
a {
text-decoration: none;
color: $white;
&:hover {
color: $yellow;
}
}
}
.first-row {
height: 100px;
margin-bottom: 10px;
padding: 10px;
}
.first-row .first {
background: $yellow;
height: 100%;
}
.first-row .second {
height: 100%;
}
.first-row .second div {
background: $orange;
height: 100%;
}
.pic-gallery {
div {
background: $violet;
height: 100%;
margin-bottom: 10px;
padding: 10px;
}
}
.content-bar {
div {
background: $green;
height: 100%;
margin-bottom: 10px;
padding: 10px;
}
}
footer {
height: 100px;
background: $blue;
color: $white;
margin-top: 10px;
padding: 10px;
clear: both;
}
header {
@include full;
.logo {
@include span(wide 1.75);
@include border-radius(0px);
}
h1 {
@include span(last 2);
@include breakpoint((max-width 50em)){
@include span(last 2);
}
}
}
.wrapper {
@include container;
}
Edit 2 Thought I should mention I am on Windows 10. 编辑2以为我应该提到我在Windows 10上。
The compass watch
command is used when you are using compass on a bare bones project or some framework without an assets pipeline. 当您在裸骨项目或没有资产管道的某个框架上使用罗盘时,将使用
compass watch
命令。 It watches the file system for changes and compiles your SASS files to CSS. 它会监视文件系统的更改并将您的SASS文件编译为CSS。 It can be used with livereloadx but thats not the main purpose.
它可以与livereloadx一起使用,但这不是主要目的。
You don't want to use compass watch
with Rails. 你不想在
compass watch
上使用compass watch
。 Rails instead has a built-in assets pipeline which does the job better. 相反,Rails有一个内置的资产管道 ,可以更好地完成工作。
If you still want to use the other features of compass you should use the compass-rails
gem. 如果您仍想使用指南针的其他功能,您应该使用
compass-rails
gem。
gem 'sass-rails'
gem 'compass-rails'
Then run bundle
to install the gems. 然后运行
bundle
来安装gem。
application.scss
application.scss
If you have a application.css
file rename it application.scss
. 如果您有
application.css
文件,请将其重命名为application.scss
。 Note that is should not be named .css.scss
. 请注意,不应将其命名为
.css.scss
。 Remove any sprockets directives which are comments that look like: 删除任何看起来像注释的sprockets指令:
#= require 'foo'
Instead use the SASS @import
directives: 而是使用SASS
@import
指令:
@import "compass"
Then follow the steps in the readme to setup the extensions such as susy. 然后按照自述文件中的步骤设置扩展名,例如susy。
Try not importing the whole of compass. 尽量不要导入整个指南针。
Instead import just the module you want, ie: 而只导入您想要的模块,即:
@import "compass/typography/links/link-colors"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.