title: How to pass Django template variables to a WebPack module
body: <p>I am just learning about WebPack module, and I am thinking of moving the entire JS infrastructure of my Django app to modules. It seems that a straightforward way of doing this is to create a webpack module for each Django template (or view), and have a single <code>&lt;script&gt;</code> tag on each page.</p>
  
  <p>However, I'm trying to find a way of passing the content of Django template variables to these webpack modules. Previously I could have these variables inlined:</p>
  
  <pre><code>&lt;script&gt;
  //Sample code..
  var arr = [];
  {% for s in vars %}
  arr.push(s);
  {% endfor %}
  &lt;/script&gt;
  </code></pre>
  
  <p>Now, I only have:</p>
  
  <pre><code>&lt;script src="temp.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>One potential solution I found is to define the webpack module to be a library that exports a single root function to the global namespace in the browser. Then use an inline <code>script</code> tag to put the Django variables into a JS variable, and pass this as arguments to the exported function.</p>
  
  <p>This somehow feels like a clumsy way of doing things. Any ideas as to how I can handle this better?</p>
  
  <p>Thanks!</p>