1

我正在关注本教程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(自定义,而不是库)?

4

1 回答 1

1

因为 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为您选择的路径。

于 2019-08-09T20:01:23.380 回答