How to configure Rails 3.2+/4 to generate .js instead of .js.coffee by default?(如何配置 Rails 3.2+/4 默认生成 .js 而不是 .js.coffee?)
问题描述
我已经看到这个问题的许多变体,其中所有答案都只是建议从 Gemfile 中删除 coffee-rails gem(这个和这个).
I have seen a number of variations of this question where all the answers simply suggest removing the coffee-rails gem from the Gemfile (this one and this one).
这不是我要寻找的答案.我可能仍然想在项目中编写一些 CoffeeScript,我只是希望 JavaScript (.js) 成为 Rails 生成器的默认值.
This is not the answer that I am looking for. I may still want to write some CoffeeScript in the project, I just want JavaScript (.js) to be the default for the Rails generators.
这也意味着 将 .js.coffee 重命名为 .js 每次我生成代码的建议不是一个理想的解决方案.
This also means the suggestions to rename .js.coffee to .js every time I generate code is not a desirable solution.
我可以更改 Rails 中的某种配置以使 .js 成为默认配置,但仍然启用 CoffeeScript(资产管道应该仍然能够转译 .js.coffee 我可以写的文件)?
Is there some sort of configuration in Rails I can change to make .js the default, but still leave CoffeeScript enabled (Asset Pipeline should still be able to transpile an .js.coffee files that I may write)?
推荐答案
你可以通过 自定义生成器配置.
config.generators do |g|
g.javascript_engine :js
end
# or
config.generators.javascript_engine = :js
您可以在这里查看更多可用的配置选项.
这篇关于如何配置 Rails 3.2+/4 默认生成 .js 而不是 .js.coffee?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何配置 Rails 3.2+/4 默认生成 .js 而不是 .js.coffee?
基础教程推荐
- fetch 是否支持原生多文件上传? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
