title: How to create typescript library with webworkers using worker-loader
body: <p>I try to create typescript library with web workers. When I test my code with webpack-dev-server everything looks good, all files are found, but when I make npm run build and try to use lib in another local project (npm install /local/path), I see <code>GET http://localhost:8080/X.worker.js </code> in browser console.</p>
  <p>webpack.config.js:</p>
  <pre><code>const path = require('path');
  
  module.exports = {
      devtool: 'inline-source-map',
      entry: {
          'mylib': './src/index.ts',
          'mylib.min': './src/index.ts',
      },
      output: {
          path: path.resolve(__dirname, '_bundles'),
          filename: '[name].js',
          libraryTarget: 'umd',
          library: 'mylib',
          umdNamedDefine: true
      },
      resolve: {
          extensions: ['.ts', '.tsx', '.js']
      },
      optimization: {
          minimize: true
      },
      module: {
          rules: [
              {
                  test: /\.tsx?$/,
                  loader: 'awesome-typescript-loader',
                  exclude: /node_modules/,
                  query: {
                      declaration: false,
                  }
              },
              {
                  test: /\.worker\.js$/,
                  use: {
                      loader: &quot;worker-loader&quot;
                  }
              },
          ]
      }
  };
  </code></pre>
  <p>tsconfig.json</p>
  <pre><code>{
      &quot;compilerOptions&quot;: {
          &quot;target&quot;: &quot;es5&quot;,
          &quot;module&quot;: &quot;es6&quot;,
          &quot;lib&quot;: [
              &quot;webworker&quot;,
              &quot;es2015&quot;,
              &quot;dom&quot;
          ],
          &quot;moduleResolution&quot;: &quot;node&quot;,
          &quot;sourceMap&quot;: true,
          &quot;strict&quot;: true,
          &quot;alwaysStrict&quot;: true,
          &quot;outDir&quot;: &quot;lib&quot;,
          &quot;resolveJsonModule&quot;: true,
          &quot;declaration&quot;: true,
          &quot;skipLibCheck&quot;: true,
          &quot;allowJs&quot;: true
      },
      &quot;include&quot;: [
          &quot;**/*.ts&quot;,
          &quot;**/*.tsx&quot;
      ],
      &quot;exclude&quot;: [
          &quot;node_modules&quot;,
          &quot;lib&quot;,
      ]
  }
  </code></pre>
  <p>package.json</p>
  <pre><code>{
    &quot;name&quot;: &quot;mylib&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;description&quot;: &quot;&quot;,
    &quot;main&quot;: &quot;_bundles/mylib.js&quot;,
    &quot;scripts&quot;: {
      &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;,
      &quot;webpack&quot;: &quot;webpack&quot;,
      &quot;build&quot;: &quot;rm -rf ./lib &amp;&amp; tsc&quot;,
      &quot;serve&quot;: &quot;webpack-dev-server&quot;,
      &quot;clean&quot;: &quot;rm -rf _bundles lib lib-esm&quot;,
      &quot;newbuild&quot;: &quot;npm run clean &amp;&amp; tsc &amp;&amp; tsc -m es6 --outDir lib-esm &amp;&amp; webpack&quot;
    },
    &quot;repository&quot;: {
      &quot;type&quot;: &quot;git&quot;,
      &quot;url&quot;: &quot;...&quot;
    },
    &quot;keywords&quot;: [],
    &quot;author&quot;: &quot;&quot;,
    &quot;license&quot;: &quot;ISC&quot;,
    &quot;bugs&quot;: {
      &quot;url&quot;: &quot;...&quot;
    },
    &quot;homepage&quot;: &quot;...e&quot;,
    &quot;devDependencies&quot;: {
      &quot;prettier&quot;: &quot;^2.1.2&quot;,
      &quot;tslint&quot;: &quot;^6.1.3&quot;,
      &quot;tslint-config-prettier&quot;: &quot;^1.18.0&quot;,
      &quot;worker-loader&quot;: &quot;^3.0.5&quot;
    },
    &quot;dependencies&quot;: {
       ...
    }
  }
  </code></pre>
  <p>Example on how I import workers:</p>
  <pre><code>import X from &quot;worker-loader!./X&quot;;
  </code></pre>