I created one module and i want to add js file to that module but in DOM i am getting "404 not found" my file are
My\Helloworld\view\frontend\requirejs-config.js
var config = {
map: {
'*': {
test1: 'My_Helloworld/js/test1'
}
},
};
My\Helloworld\view\frontend\web\js\test1.js
define([
"jquery"
], function($) {
"use strict";
$(document).ready(function(){
alert('Test JS');
});
});
My\Helloworld\view\frontend\templates\helloworld.phtml
<script type="text/javascript">
require(['jquery','test1'],function($){
$(window).load(function() {
$('.flexslider-8').flexslider({
animation: "fade",
controlNav: "thumbnails",
slideshowSpeed: 2000,
minItems: 2,
maxItems: 4
});
});
});
</script>
3 Answers 3
Instead of require(['jquery','test1'],function($){... try it with this:
require(['jquery','My_Helloworld/js/test1'],function($){ ...
This way you won't need the requirejs-config.js file.
-
thanks marius this is helped me lot...but i am not understanding that what wrong with requirejs-config.js fileAnand Ontigeri– Anand Ontigeri2016年01月05日 07:17:20 +00:00Commented Jan 5, 2016 at 7:17
-
Me neither. If I find something I will post it here.Marius– Marius2016年01月05日 07:17:58 +00:00Commented Jan 5, 2016 at 7:17
-
requirejs-config.js:: in my case it is somehow missing "/js/" part in the url, which is why it's throwing 404. Any idea?Adarsh Khatri– Adarsh Khatri2017年12月20日 09:01:44 +00:00Commented Dec 20, 2017 at 9:01
you can get it in any .phtml file by path
<link rel="stylesheet" type="text/css" href="<?php echo $block->getViewFileUrl('Package_Module::css/flexslider.css')?>">
I hope this will help you.
Please compare your try with How to load custom module js file in magento 2?. still you get same error then please comment here. You can implement use shim to maintain jQuery dependency.
-
i followed this one only but unfortunately i was getting 404 error but marius answer solved this 404 not found error.Anand Ontigeri– Anand Ontigeri2016年01月05日 07:26:57 +00:00Commented Jan 5, 2016 at 7:26