title: Avoid bundling lib dependencies with webpack + handlebars loader
body: <p>I'm writing a library using handlebars templates and I want to use Webpack to bundle it.
  I'm using <a href="https://github.com/altano/handlebars-loader" rel="nofollow">handlebars-loader</a> so that I can require and precompile the templates.</p>
  
  <p>However I don't want handlebars (nor handlebars/runtime) to be included in my compiled library and thus, I would like to set them as externals.</p>
  
  <p>Here is my config file:</p>
  
  <pre class="lang-js prettyprint-override"><code>module.exports = {
      context: __dirname + '/src',
      entry: './index.js',
      output: {
          path: __dirname + '/dist',
          filename: 'stuff.js',
          libraryTarget: 'umd',
          library: 'Stuff'
      },
      externals: [{
          'handlebars/runtime': {
              root: 'Handlebars',
              amd: 'handlebars.runtime',
              commonjs2: 'handlebars/runtime',
              commonjs: 'handlebars/runtime'
          }
      }],
      module: {
          loaders: [
              { test: /\.handlebars$/, loader: 'handlebars-loader' }
          ]
      }
  };
  </code></pre>
  
  <p>Unfortunately it doesn't work and handlebars-loader still makes handlebars/runtime to be bundled...</p>
  
  <p>I believe it is because I do not require handlebars/runtime directly, rather it is required in the code added by the loader.</p>
  
  <p>Is there a way to mark it as external?</p>
  
  <p><strong>Edit:</strong> I know I need handlebars/runtime to compile my template. But as I am building a library, I want it to be provided by the user of the library instead of being included. This way, if my user is also using Handlebars, the library is not loaded twice.
  I believe it is good practice for libraries to avoid bundling any dependency (it is something we see much too often in my humble opinion).</p>