在我requirejs-config.js
文件[MyModule]/view/frontend
下放置,我包括我所有的JS文件是這樣的:Magento的2 - 不導入JS文件RequireJS配置文件,沒有錯誤拋出
var config = {
paths: {
"jquery.min": "MyVend_MyModule/js/jquery.min",
"bootstrap": "MyVend_MyModule/js/bootstrap.min",
"bootstrap-datepicker": "MyVend_MyModule/js/bootstrap-datepicker.min",
"bootstrap-select": "MyVend_MyModule/js/bootstrap-select.min",
"jquery.smoothState": "MyVend_MyModule/js/jquery.smoothState",
"moment": "MyVend_MyModule/js/moment.min",
...
},
shim: {
// 'libname' : ['dependency']
"bootstrap": [ "jquery"],
"bootstrap-datepicker": [ "jquery"],
"bootstrap-select": [ "jquery"],
"jquery.smoothState": [ "jquery"],
"moment": [ "jquery"],
...
}
};
我的JS文件放在[MyModule]/view/frontend/web/js
和下文件名匹配,我可以向你保證。
好的,所以我做了bin/magento setup:static-content:deploy
和bin/magento setup:upgrade
等等。這些文件被鏡像到/pub/static/...
,所以我知道他們在那裏。當我刷新頁面時,requirejs-config.js
在/pub/static/_requirejs/...
下包含我的配置文件的內容,所以我知道那裏也是。然而,javascript並沒有被導入到頁面中,我可以在查看網絡標籤(我使用Chrome)時刷新來確認。所有它導入的CSS文件,我聲明在我的佈局xml文件下:
<css src="MyVend_MyModule::css/bootstrap-select.min.css"/>
<css src="MyVend_MyModule::css/animate.min.css"/>
<css src="MyVend_MyModule::css/famfamfam-flags.css"/>
<css src="MyVend_MyModule::css/magnific-popup.css"/>
...
那些得到正確導入,他們在網頁上。但是,我的JS文件沒有被導入,即使這些文件在/pub/static
之下,並且它在requirejs-config.js
文件中。有什麼我做錯了嗎?沒有錯誤,這讓我更加困惑。
我會將這張貼在Magento SE上,請不要標記爲重複。
我將我的代碼更改爲像您的代碼。它仍然不起作用。 –