title: Webpack can not use __dirname?
body: <p>I am trying to use node-postgres to hook my app up to Postgres. The code I use is:</p>
  
  <pre><code>import React from 'react';
  import pg from 'pg';
  import fs from 'fs';
  var cn = {
    host: 'localhost', // server name or IP address; 
    port: 5432,
    database: 'my_db',
    user: 'myname',
    password: 'mypass'
  };
  </code></pre>
  
  <p>and it produces the error:</p>
  
  <pre><code>index.js:5 Uncaught ReferenceError: __dirname is not defined
  up  @ index.js:5
  __webpack_require__ @ bootstrap 539ecc7…:19
  (anonymous function)  @ client.js:4
  __webpack_require__ @ bootstrap 539ecc7…:19
  (anonymous function)  @ index.js:3
  console.EventEmitter._events  @ index.js:81
  __webpack_require__ @ bootstrap 539ecc7…:19
  (anonymous function)  @ app.js:26957
  __webpack_require__ @ bootstrap 539ecc7…:19
  content @ bootstrap 539ecc7…:39
  __webpack_require__ @ bootstrap 539ecc7…:19
  (anonymous function)  @ bootstrap 539ecc7…:39
  (anonymous function)  @ bootstrap 539ecc7…:39
  webpackUniversalModuleDefinition  @ universalModuleDefinition:7
  (anonymous function)  @ universalModuleDefinition:10
  </code></pre>
  
  <p>The path on index.js provided in the console is webpack:///./~/pg/~/pgpass/lib/index.js:5</p>
  
  <p>I tried @Renzo Poddighe solution at <a href="https://stackoverflow.com/questions/32693835/how-to-write-file-with-node-webkit-js">how to write file with node webkit js?</a> but I still get the same error. I think it may have something to do with the discussions at <a href="https://github.com/nwjs/nw.js/wiki/Differences-of-JavaScript-contexts#resolving-relative-paths-to-other-scripts" rel="noreferrer">https://github.com/nwjs/nw.js/wiki/Differences-of-JavaScript-contexts#resolving-relative-paths-to-other-scripts</a> and <a href="https://github.com/nwjs/nw.js/issues/264" rel="noreferrer">https://github.com/nwjs/nw.js/issues/264</a>. They say that</p>
  
  <pre><code>// __dirname is not defined in webkit context, this is only node.js thing
  console.log(__dirname); // undefined
  </code></pre>
  
  <p>and</p>
  
  <p>__dirname works in Node.js modules, i.e. in JavaScript code that was called with require().
  __dirname doesn't work only in WebKit scripts, i.e. in JavaScript code that was called with HTML , or jQuery's $.getScript(), or any other similar method.</p>
  
  <p>Any ideas? Let me know what other information I need to include.</p>
  
  <p><strong>edit</strong></p>
  
  <p>I think my target is </p>
  
  <pre><code>var config = {
    entry: { app: './src/index.jsx'},
    output: {
       libraryTarget: 'umd',
       path: path.join(__dirname, 'dist'),
       filename: '[name].js'
    }, ...
  </code></pre>
  
  <p>My webpack.config.js looks like:</p>
  
  <pre><code>...
    node: {
      console: true,
      __dirname: true,
      dns: 'empty',
      fs: 'empty',
      net: 'empty',
      tls: 'empty'
    }
  ...
  </code></pre>