为了安装 bootstrap-sass gem 我是从 application.scss 中删除 *= require_self 还是用 import '@require_self' 替换它
For installing bootstrap-sass gem do I remove *= require_self from application.scss or replace it with import '@require_self'
我正在安装 bootstrap-sass
gem 并且与 application.scss 有关的这一行让我感到困惑。
'Then, remove all the *= require_self and *= require_tree . statements from the sass file. Instead, use @import to import Sass files.'
我是删除 *= require_self
和 *= require_tree .
并用 import '@require_self'
和 import '@require_tree .'
替换它们,还是直接删除它们。
也适用于 application.scss 中的任何其他导入文件,如
*= require dataTables/jquery.dataTables
*= require froala/froala_editor.min.css
我应该把它们改成
@import 'dataTables/jquery.dataTables'
@import 'froala/froala_editor.min.css'
只是感到困惑,想在这里确认要做什么。
在使用 bootstrap-sass 时,删除 application.scss
中的所有内容并添加以下内容:
#"bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
@import "bootstrap-sprockets";
@import "bootstrap";
如果你想加载额外的 scss/sass 文件,你可以 @import 它们到 application.scss
如果你想加载 css 个文件,你可以 *= 要求 它们像下面这样:
/*
*= require_self
*= require your_css_file
*/
@import "bootstrap-sprockets";
@import "bootstrap";
我在 Bootstrap 4 Ruby Gem for Rails https://github.com/twbs/bootstrap-rubygem 中遇到了类似的问题。它的指令还包含短语:
Then, remove all the *= require and *= require_tree statements from
the Sass file. Instead, use @import to import Sass files.
Do not use *= require in Sass or your other stylesheets will not be
able to access the Bootstrap mixins and variables.
这里有矛盾。
如果我按照他们告诉我的去做 - 这意味着我失去了取消将所有 (s)css
文件捆绑到一个 application.scss
(和一个 application.css
在浏览器中)在开发阶段。如果我手动将我所有的 scss 文件导入 application.css
- 这意味着我将每个文件的内容注入到一个更大的文件中,而 Sprockets 不再控制这种捆绑 - 因为我手动进行。而且我不喜欢它 - 在开发阶段,因为我无法清楚地看到这种样式来自哪个 css
文件。
所以我选择了另一个选项 - 我让 application.css
保持不变,然后我创建了一个 bootstrap_code.scss
文件(未能将其命名为 bootstrap.scss
,因为它混淆了 Rails)里面有一个 @import "bootstrap";
指令,最后我为自己的样式创建了一些 z.scss
文件 - 只是为了确保它们会出现 AFTER 相同的 bootstrap 风格。
当然,我的解决方案有一个缺点,我的 scss
-files 不能
access the Bootstrap mixins and variables
(因为 Sprockets 将它们转换为 css
让它们没有机会首先潜入 Bootstrap scss
),但因为我只需要一个普通的 css
来自 Bootstrap暂时还可以。
当然在生产阶段我可以 return 到 gem 文档 ("remove all the *= require ...") 中描述的推荐方法,如果我真的需要 Bootstrap mixins 和变量(我通常不需要的东西)。
我正在安装 bootstrap-sass
gem 并且与 application.scss 有关的这一行让我感到困惑。
'Then, remove all the *= require_self and *= require_tree . statements from the sass file. Instead, use @import to import Sass files.'
我是删除 *= require_self
和 *= require_tree .
并用 import '@require_self'
和 import '@require_tree .'
替换它们,还是直接删除它们。
也适用于 application.scss 中的任何其他导入文件,如
*= require dataTables/jquery.dataTables
*= require froala/froala_editor.min.css
我应该把它们改成
@import 'dataTables/jquery.dataTables'
@import 'froala/froala_editor.min.css'
只是感到困惑,想在这里确认要做什么。
在使用 bootstrap-sass 时,删除 application.scss
中的所有内容并添加以下内容:
#"bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
@import "bootstrap-sprockets";
@import "bootstrap";
如果你想加载额外的 scss/sass 文件,你可以 @import 它们到 application.scss
如果你想加载 css 个文件,你可以 *= 要求 它们像下面这样:
/*
*= require_self
*= require your_css_file
*/
@import "bootstrap-sprockets";
@import "bootstrap";
我在 Bootstrap 4 Ruby Gem for Rails https://github.com/twbs/bootstrap-rubygem 中遇到了类似的问题。它的指令还包含短语:
Then, remove all the *= require and *= require_tree statements from the Sass file. Instead, use @import to import Sass files.
Do not use *= require in Sass or your other stylesheets will not be able to access the Bootstrap mixins and variables.
这里有矛盾。
如果我按照他们告诉我的去做 - 这意味着我失去了取消将所有 (s)css
文件捆绑到一个 application.scss
(和一个 application.css
在浏览器中)在开发阶段。如果我手动将我所有的 scss 文件导入 application.css
- 这意味着我将每个文件的内容注入到一个更大的文件中,而 Sprockets 不再控制这种捆绑 - 因为我手动进行。而且我不喜欢它 - 在开发阶段,因为我无法清楚地看到这种样式来自哪个 css
文件。
所以我选择了另一个选项 - 我让 application.css
保持不变,然后我创建了一个 bootstrap_code.scss
文件(未能将其命名为 bootstrap.scss
,因为它混淆了 Rails)里面有一个 @import "bootstrap";
指令,最后我为自己的样式创建了一些 z.scss
文件 - 只是为了确保它们会出现 AFTER 相同的 bootstrap 风格。
当然,我的解决方案有一个缺点,我的 scss
-files 不能
access the Bootstrap mixins and variables
(因为 Sprockets 将它们转换为 css
让它们没有机会首先潜入 Bootstrap scss
),但因为我只需要一个普通的 css
来自 Bootstrap暂时还可以。
当然在生产阶段我可以 return 到 gem 文档 ("remove all the *= require ...") 中描述的推荐方法,如果我真的需要 Bootstrap mixins 和变量(我通常不需要的东西)。