Magento 2 – Pass PHP Variable to External JS for Custom Theme

javascriptmagento2requirejsrequirejs-config.js

I have created a custom theme in app/design/frontend/Vendor/Themename

In theme directory I have Themename/requirejs-config.js

var config = {
   deps: [
      "js/custom",
   ]
};

Themename/web/js/custom.js

require([
   'jquery'
], function ($) {

   console.log('adsa');
   console.log(config);
});

I have a phtml file included and I am passing php variable to external js

<script type="text/x-magento-init">
{
    "*": {
        "js/custom": {
            "contacturl": "<?php echo $block->getUrl("contact/index/post"); ?>"
        }
    }
}
</script>

This is the error I am getting Config is not defined.

enter image description here

I am in the developer mode
What I tried

Cleared Cache

Cleared Var Directory

Best Answer

I got this working using this

define([
   'jquery'
], function ($) {

   console.log('adsa');
   return function (config) {
       console.log(config.contacturl);
   }
});

Though I am not sure why its not working with require.