我认识到这个问题已被提出了一千次,而且我觉得我已经阅读过其他大多数帖子,但我似乎还无法解决这个问题。
我刚刚开始使用Ruby on Rails,并尝试在我的项目中使用Compass / Sass / Suzy。他们都(主要)工作但是罗盘编译器存在一些问题。
首先使用bundle exec compass watch
(有和没有--poll
)不会做任何事情。 (这是假设我理解这个命令的重点是它会动态编译,我不必刷新页面来查看我的更改,但我可能是错的)
其次,当我在更改我的.scss文件后刷新页面时,编译完成并重新加载页面需要30-35秒。这是无法忍受的。我已经读到最新的指南针轨道存在一些问题'但大多数帖子都说这是几年前的事。最新的罗盘轨道是否完美无缺,或者是否存在引起这种情况的常见问题?
由于我刚学习,我只有一个控制器/视图/ scss文件,所以我非常积极,我没有任何依赖循环问题。
以下是我目前如何设置项目的方法。 (我认为它设置得当,但也许有人可以指出我做错了。)
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
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
application.css.scss
@import "compass";
@import "breakpoint";
@import "welcome.scss";
作为进一步说明,我遇到了这个问题,每个编译指南针都抛出了一个弃用的警告。我遵循了似乎阻止它的建议here。怀疑它涉及但是为了防止我的无知妨碍解决方案,我想我会提到它。
修改
我想我会把我的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;
}
编辑2 我想我应该提到我在Windows 10上。
答案 0 :(得分:1)
当您在裸骨项目或某个没有资产管道的框架上使用罗盘时,将使用compass watch
命令。它会监视文件系统的更改并将您的SASS文件编译为CSS。它可以与livereloadx一起使用,但这不是主要目的。
您不希望将compass watch
与Rails一起使用。相反,Rails有一个内置的assets pipeline,可以更好地完成工作。
如果您仍想使用指南针的其他功能,则应使用compass-rails
gem。
gem 'sass-rails'
gem 'compass-rails'
然后运行bundle
来安装宝石。
application.scss
如果您有application.css
个文件,请将其重命名为application.scss
。请注意,不应将其命名为.css.scss
。删除任何看起来像注释的sprockets指令:
#= require 'foo'
而是使用SASS @import
指令:
@import "compass"
然后follow the steps in the readme设置扩展程序,例如susy。
答案 1 :(得分:1)
尽量不要导入整个罗盘。
而是只导入你想要的模块,即:
@import "compass/typography/links/link-colors"