在 rails 6 中将自定义 javascript 代码放在哪里?

Where to put custom javascript code in rails 6?

我正在学习本教程 https://medium.com/@guilhermepejon/how-to-install-bootstrap-4-3-in-a-rails-6-app-using-webpack-9eae7a6e2832 并且在某一点上它说

Let’s start by creating a new css manifest inside our app/javascript 
folder. We will use this file to import all our css from now on.

$ mkdir app/javascript/stylesheets
$ touch app/javascript/stylesheets/application.scss

Note: In an existing app, you’ll have to import all your current css 
to the folder we created above, and import them through the newly 
created manifest file.

我就是消化不了。将样式表文件夹和文件放在 javascripts/ 下有什么意义。这是合乎逻辑的还是好的方法?我也看过很多其他网站和 1 个视频(现在找不到)。如果它是推荐的方式,为什么 rails 不默认提供它。

如果不是这个,请建议替代放置 javascript(自定义,而不是库)?

因为 Webpack 主要是 JavaScript 的捆绑器,我猜创作者很久以前就选择了 app/javascript 作为默认目录名称,因为它在当时看起来足够具有描述性。你不是第一个觉得奇怪的人: https://github.com/rails/webpacker/issues/130#issuecomment-282901244

如果您不喜欢,另一种方法是更改​​ config/webpacker.yml 文件中的默认目录名称。如果文件看起来像这样:

# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
  source_path: app/javascript

您可以将 source_path 更改为您选择的路径。