<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Loading a custom module from different file with  API4 and Dojo in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017990#M71428</link>
    <description>&lt;P&gt;You need to set an absolute path for your package.&lt;/P&gt;&lt;P&gt;Something like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;script&amp;gt;
var locationPath = location.pathname.replace(/\/[^\/]+$/, "");
window.dojoConfig = {
  packages: [
    {
      name: "widgets",
      location: locationPath + "/module/widgets"
    }
  ]
};
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That little regex will get you the absolute URL of the page your app is running and let the AMD loader know exactly where to find the package. Without it, it assumes it should look at the location the AMD loader is running, which will be on the CDN.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jan 2021 16:31:37 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2021-01-19T16:31:37Z</dc:date>
    <item>
      <title>Loading a custom module from different file with  API4 and Dojo</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017489#M71402</link>
      <description>&lt;P&gt;I am trying to create a demo app to understand how to minimize my code by creating more files.&lt;/P&gt;&lt;P&gt;I am using the base starter app sample on one js file and trying to add a widget on another. The code works on the same file but after the divide its breaking.&lt;/P&gt;&lt;P&gt;I added a dojo config, a dojo-ready function and a new define in the widgets.js file.&lt;/P&gt;&lt;P&gt;I am using "define" and not "require" on the widget.js because it's dependent on the main but not sure if it's ok because it will only be called once.&lt;/P&gt;&lt;P&gt;This is how my app looks:&lt;/P&gt;&lt;P&gt;modules(folder)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;-widgets.js&lt;BR /&gt;index.html&lt;BR /&gt;main.js&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV class="s-prose js-post-body"&gt;&lt;P&gt;&lt;STRONG&gt;index.html&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8"&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"&amp;gt;
  &amp;lt;title&amp;gt;ArcGIS API for JavaScript Tutorials: Create a Starter App&amp;lt;/title&amp;gt;
  &amp;lt;style&amp;gt;
    html, body, #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  &amp;lt;/style&amp;gt;
  &amp;lt;script type="text/javascript"&amp;gt;
    dojoConfig = {
      async: true,
      packages: [
        {
          name: "widgets",
          location: "modules/widgets" // or wherever you keep your custom code
        }
      ]
    };
  &amp;lt;/script&amp;gt;
  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css"&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.18/"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;script type="text/javascript" src="main.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;main.js&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="hljs-built_in"&gt;require&lt;/SPAN&gt;([
  &lt;SPAN class="hljs-string"&gt;"esri/Map"&lt;/SPAN&gt;,
  &lt;SPAN class="hljs-string"&gt;"esri/views/MapView"&lt;/SPAN&gt;,
  &lt;SPAN class="hljs-string"&gt;"dojo/ready"&lt;/SPAN&gt;,
  &lt;SPAN class="hljs-string"&gt;"widgets/searchWidget"&lt;/SPAN&gt;
], &lt;SPAN class="hljs-function"&gt;&lt;SPAN class="hljs-keyword"&gt;function&lt;/SPAN&gt;(&lt;SPAN class="hljs-params"&gt;&lt;SPAN class="hljs-built_in"&gt;Map&lt;/SPAN&gt;, MapView,ready&lt;/SPAN&gt;) &lt;/SPAN&gt;{
    ready(&lt;SPAN class="hljs-function"&gt;&lt;SPAN class="hljs-keyword"&gt;function&lt;/SPAN&gt; () &lt;/SPAN&gt;{


    &lt;SPAN class="hljs-keyword"&gt;var&lt;/SPAN&gt; map = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; &lt;SPAN class="hljs-built_in"&gt;Map&lt;/SPAN&gt;({
        &lt;SPAN class="hljs-attr"&gt;basemap&lt;/SPAN&gt;: &lt;SPAN class="hljs-string"&gt;"topo-vector"&lt;/SPAN&gt;
    });

      &lt;SPAN class="hljs-keyword"&gt;var&lt;/SPAN&gt; view = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; MapView({
        &lt;SPAN class="hljs-attr"&gt;container&lt;/SPAN&gt;: &lt;SPAN class="hljs-string"&gt;"viewDiv"&lt;/SPAN&gt;,
        &lt;SPAN class="hljs-attr"&gt;map&lt;/SPAN&gt;: map,
        &lt;SPAN class="hljs-attr"&gt;center&lt;/SPAN&gt;: [-&lt;SPAN class="hljs-number"&gt;118.80500&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;34.02700&lt;/SPAN&gt;], &lt;SPAN class="hljs-comment"&gt;// longitude, latitude&lt;/SPAN&gt;
      &lt;SPAN class="hljs-attr"&gt;zoom&lt;/SPAN&gt;: &lt;SPAN class="hljs-number"&gt;13&lt;/SPAN&gt;
      });
      
    &lt;SPAN class="hljs-keyword"&gt;var&lt;/SPAN&gt; widget = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; searchWidget(view)
     });


});&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;widget.js&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;define([&lt;SPAN class="hljs-string"&gt;"esri/widgets/Search"&lt;/SPAN&gt;], &lt;SPAN class="hljs-function"&gt;&lt;SPAN class="hljs-keyword"&gt;function&lt;/SPAN&gt;(&lt;SPAN class="hljs-params"&gt;Search&lt;/SPAN&gt;) &lt;/SPAN&gt;{ 
&lt;SPAN class="hljs-keyword"&gt;var&lt;/SPAN&gt; search


&lt;SPAN class="hljs-keyword"&gt;return&lt;/SPAN&gt;{
      
    &lt;SPAN class="hljs-attr"&gt;searchWidget&lt;/SPAN&gt;: &lt;SPAN class="hljs-function"&gt;&lt;SPAN class="hljs-keyword"&gt;function&lt;/SPAN&gt;(&lt;SPAN class="hljs-params"&gt;view&lt;/SPAN&gt;)&lt;/SPAN&gt;{

        search = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; Search({
            &lt;SPAN class="hljs-attr"&gt;view&lt;/SPAN&gt;: view
          });

        view.ui.add(search, &lt;SPAN class="hljs-string"&gt;'top-right'&lt;/SPAN&gt;);
    }
}


 });&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV class="mt24 mb12"&gt;&lt;DIV class="post-taglist grid gs4 gsy fd-column"&gt;&lt;DIV class="grid ps-relative"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 16 Jan 2021 21:49:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017489#M71402</guid>
      <dc:creator>litch</dc:creator>
      <dc:date>2021-01-16T21:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: Loading a custom module from different file with  API4 and Dojo</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017538#M71410</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;When you say API4 I assume you mean the new version of the Javascript API, which today is 4.18 and has nothing to do with the WebApp Builder. In that case, you are required to follow a more modern Javascript style, which includes nodeJS, npm for packages installation and Dojo is not really part of the API. You should follow ESRI's documentation and samples to try and understand the workflow but without prior knowledge and good understanding it can be quite overwhelming --&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/widgets-custom-widget/index.html" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/widgets-custom-widget/index.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;To write widgets in the style you suggested, you need to stick to version 3 of the API, which is still what's required if your purpose is to integrate the widget within the WebApp Builder&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jan 2021 22:19:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017538#M71410</guid>
      <dc:creator>shaylavi</dc:creator>
      <dc:date>2021-01-17T22:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Loading a custom module from different file with  API4 and Dojo</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017584#M71413</link>
      <description>&lt;P&gt;If I am getting this right, the link you sent is for developing widgets from scratch, which is not my intention.&lt;BR /&gt;I want to use existing "from the box" widgets in my code but after a while the js file bloats.&lt;/P&gt;&lt;P&gt;In my example the widget is just a simple search widget that consists of a few lines of code,&lt;BR /&gt;it worked on the sample with one js file.&amp;nbsp;&lt;BR /&gt;Do i still need to use typescript just to break the code and reference it?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I tried calling it as a src from the script tag and i tried "export"-ing it as a function and importing it in before i found the Dojo solution, but none of them worked.&lt;BR /&gt;&lt;BR /&gt;All the sample code i found was a single page JS, and the "getting started with the API" course mentions how fast the files can grow but doesn't provide an example of multiple files.&lt;BR /&gt;&lt;BR /&gt;do you have any other source or sample that is more inline with my problem or is it not possible at all to avoid using node?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2021 05:12:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017584#M71413</guid>
      <dc:creator>litch</dc:creator>
      <dc:date>2021-01-18T05:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Loading a custom module from different file with  API4 and Dojo</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017587#M71414</link>
      <description>&lt;P&gt;I'm really confused about what you're trying to achieve. If I understand this right, you're working with version 4 of the API, but don't want to create a widget, just call the existing ones OOB + combine dojo to separate them into modules? if that's all correct, you're just trying to learn how to use dojo modules?&amp;nbsp;Yet in your code, you refer to a widget.js file, which points to a widget code structure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you're trying to learn modules in Dojo, I suggest you start with that alone, before you start mixing the API and initialize widgets inside modules.&lt;/P&gt;&lt;P&gt;To understand better on creating modules with Dojo it's best you refer to their documentation.&lt;BR /&gt;There's also this good thread -&amp;nbsp;&lt;A href="http://dojo-toolkit.33424.n3.nabble.com/define-declare-vs-module-class-td3993005.html" target="_blank"&gt;http://dojo-toolkit.33424.n3.nabble.com/define-declare-vs-module-class-td3993005.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2021 05:42:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017587#M71414</guid>
      <dc:creator>shaylavi</dc:creator>
      <dc:date>2021-01-18T05:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: Loading a custom module from different file with  API4 and Dojo</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017600#M71416</link>
      <description>&lt;P&gt;Sorry for not making myself clear.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;I don't want to use Dojo at all if possible.&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;Here's a working app:&lt;BR /&gt;All I want to do is to call the search widget from another file:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8"&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"&amp;gt;
  &amp;lt;title&amp;gt;ArcGIS API for JavaScript Tutorials: Create a Starter App&amp;lt;/title&amp;gt;
  &amp;lt;style&amp;gt;
    html, body, #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  &amp;lt;/style&amp;gt;
  
    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css"&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.18/"&amp;gt;&amp;lt;/script&amp;gt;
  
  &amp;lt;script&amp;gt;  
    require([
      "esri/Map",
      "esri/views/MapView",
      "esri/widgets/Search"
      
      
    ], function(Map, MapView,Search) {

      var map = new Map({
        basemap: "topo-vector"
      });

      var view = new MapView({
        container: "viewDiv",
        map: map,
        center: [-118.80500, 34.02700], // longitude, latitude
      zoom: 13
      });
      
      
        var searchWidget = new Search({
          view: view
        });

        // Add the search widget to the top right corner of the view
        view.ui.add(searchWidget, {
          position: "top-right"
        });


    });
  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Is that possible without Dojo and Node? if so can you show me how?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2021 06:59:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017600#M71416</guid>
      <dc:creator>litch</dc:creator>
      <dc:date>2021-01-18T06:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Loading a custom module from different file with  API4 and Dojo</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017990#M71428</link>
      <description>&lt;P&gt;You need to set an absolute path for your package.&lt;/P&gt;&lt;P&gt;Something like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;script&amp;gt;
var locationPath = location.pathname.replace(/\/[^\/]+$/, "");
window.dojoConfig = {
  packages: [
    {
      name: "widgets",
      location: locationPath + "/module/widgets"
    }
  ]
};
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That little regex will get you the absolute URL of the page your app is running and let the AMD loader know exactly where to find the package. Without it, it assumes it should look at the location the AMD loader is running, which will be on the CDN.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 16:31:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1017990#M71428</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-01-19T16:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Loading a custom module from different file with  API4 and Dojo</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1020262#M71509</link>
      <description>&lt;P&gt;It worked! I also had to change the code to a constructor and add declare.&lt;BR /&gt;In the accessor page it states dojo/_base/declare&lt;SPAN&gt;&amp;nbsp;was removed.&lt;/SPAN&gt;&lt;BR /&gt;Is this the right way to import functions in the api?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;main.js&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var loc = location.pathname.replace(/\/[^/]+$/, '');
require({
  packages: [
    { name: "modules", location: loc + "/modules"}
  ]
},[
  "esri/Map",
  "esri/views/MapView",
  "modules/widgets/MySearchWidget",
  "dojo/ready"
], function(
  Map,
  MapView,
  MySearchWidget,
) {
  var map = new Map({
    basemap: "topo-vector"
  });

  var view = new MapView({
    container: "viewDiv",
    map: map,
    center: [-118.80500, 34.02700], // longitude, latitude
    zoom: 13
  });
  
  var SearchWidget = MySearchWidget(view);
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;mySearchWidget,js&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;define([
  "dojo/_base/declare",
  "esri/widgets/Search"
], function(
  declare,
  Search
) {
  return declare( null, {
    constructor: function( view ) {
      var search = new Search({
        view: view
      });
      view.ui.add( search, "top-right" );
    }
  });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2021 22:44:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/loading-a-custom-module-from-different-file-with/m-p/1020262#M71509</guid>
      <dc:creator>litch</dc:creator>
      <dc:date>2021-01-26T22:44:35Z</dc:date>
    </item>
  </channel>
</rss>

