title: Electron - Javascript (ES6) - import remote Class
body: <p><strong>EDIT :<br>
  02/09 -</strong> It seems that the import code is fine (like the one in the response), but my class code is not good (bad ES6 ? bad transpilation ?)</p>
  
  <p><strong>Initial post :</strong><br>
  I'm trying to import a remote class from my electron app.</p>
  
  <ul>
  <li>I have a static server to host my html/js files</li>
  <li>I'd like to import a class from that server, in order to use it in the main process of my electron app.</li>
  </ul>
  
  <p>Is it possible ?</p>
  
  <p>I found some solution like :</p>
  
  <pre><code>var vm = require('vm')
  var concat = require('concat-stream');
  require('http')
    .get(
      {
        host: 'localhost', 
        port: 8123, 
        path:"/dist/SomeViewModel.js" 
      }, 
      function(res) {
        res.setEncoding('utf8');
        res.pipe(concat({ encoding: 'string' }, function(remoteSrc) {
          vm.runInThisContext(remoteSrc, 'remote_modules/SomeViewModel.js')
        }));
      } );
  </code></pre>
  
  <p>it seems to tun without error, but I don't understand how to use it ...<br>
  <code>var someVM = new SomeViewModel()</code> doesn't work for example (not surprised ...).</p>
  
  <p>Here is SomeViewModel :</p>
  
  <pre><code>export default class SomeViewModel {
    constructor(options) {
      this.element1 = options.element1,
      this.element2 = options.element2
    };
  }
  </code></pre>
  
  <p>The class is babelized and becomes that :</p>
  
  <pre><code>(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&amp;&amp;require;if(!u&amp;&amp;a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&amp;&amp;require;for(var o=0;o&lt;r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  var SomeViewModel = function SomeViewModel(options) {
    _classCallCheck(this, SomeViewModel);
  
    this.element1 = options.element1, this.element2 = options.element2;
  };
  
  exports["default"] = SomeViewModel;
  module.exports = exports["default"];
  
  },{}]},{},[1]);
  
  //# sourceMappingURL=SomeViewModel.js.map
  </code></pre>
  
  <p>Is that a good way to go ? (I know about security, it's just how to)</p>