application.js 文件在 rails 6 中被 webpacker 编译忽略
The application.js file is being ignored by webpacker compilation in rails 6
在从 rails 5
升级的 rails 6
应用程序中,我有以下包文件
#app/javascript/packs/application.js
import "core-js/stable";
import "regenerator-runtime/runtime";
require("trix")
require("@rails/actiontext")
和
#app/javascript/packs/application.scss
@import '../stylesheets/datatables.scss';
webpack-dev-server
服务器编译成功,但application.js
文件中包含的javascript不是运行。事实上,如果我将 require("trix")
更改为 require("no_such_file")
它不会导致编译错误,所以我的 application.js
被完全忽略了。我该如何解决这个问题?
问题与此有关 webpacker
issue (or feature). It seems that if you have another file called application
in the packs directory, e.g. application.scss
, then webpacker overwrites the output of application.js. Basically I needed to move application.scss
out of the packs directory and import it in the application.js
file. This post 在问题报告中对此进行了更详细的解释。
在从 rails 5
升级的 rails 6
应用程序中,我有以下包文件
#app/javascript/packs/application.js
import "core-js/stable";
import "regenerator-runtime/runtime";
require("trix")
require("@rails/actiontext")
和
#app/javascript/packs/application.scss
@import '../stylesheets/datatables.scss';
webpack-dev-server
服务器编译成功,但application.js
文件中包含的javascript不是运行。事实上,如果我将 require("trix")
更改为 require("no_such_file")
它不会导致编译错误,所以我的 application.js
被完全忽略了。我该如何解决这个问题?
问题与此有关 webpacker
issue (or feature). It seems that if you have another file called application
in the packs directory, e.g. application.scss
, then webpacker overwrites the output of application.js. Basically I needed to move application.scss
out of the packs directory and import it in the application.js
file. This post 在问题报告中对此进行了更详细的解释。