Skip to content

Webpack web-workers loader not working #2138

@xavibonell

Description

@xavibonell

Hi, I'm building an app using webpack, which it's been incredibly helpful so far, but now I need to add some web workers into the mix, and I tryed using a built-in plugin to load them, but I followed the example here, the official repository, and I couldn't make it work.
My webpack.dev.js looks like this:

import webpack              from 'webpack';
import assign               from 'object-assign';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';

import prodCfg              from './webpack.prod.config.js';

var ExtractTextPlugin = require("extract-text-webpack-plugin");
var DEBUG = process.env.NODE_ENV !== 'production' ? true : false;
var styles = 'css!less';

Object.assign = assign;

export default function (app) {
  const config = Object.assign(prodCfg, {
    devtool: 'cheap-module-inline-source-map',
    entry:  
     [
      'webpack-hot-middleware/client',
      './client',
      'styles/main.less'
    ],
    module: {
      loaders: [
        {
          test:    /\.jsx?$/,
          exclude: /node_modules/,
          loader:  'babel',
          query:   {
            plugins: [
              [
                'react-transform', {
                transforms: [{
                  transform: 'react-transform-hmr',
                  imports:   ['react'],
                  locals:    ['module']
                }]
              }
              ]
            ]
          }
        },
        {
          test: /\.css$/,
          loader: DEBUG ? 'style!' + styles : ExtractTextPlugin.extract(styles)
        },
        { 
          test: /\.less$/, 
          loader: DEBUG ? 'style!' + styles : ExtractTextPlugin.extract(styles)
        }
      ]
    },
    plugins: [
      new webpack.optimize.OccurenceOrderPlugin(),
      new webpack.HotModuleReplacementPlugin(),
      new webpack.NoErrorsPlugin(),
      new ExtractTextPlugin("style.css", {allChunks: true })
    ],
    worker: {
      output: {
        filename: "hash.worker.js",
        chunkFilename: "[id].hash.worker.js"
      }
    }
  });

  const compiler = webpack(config);

  app.use(webpackDevMiddleware(compiler, {noInfo: true, publicPath: config.output.publicPath}));
  app.use(webpackHotMiddleware(compiler));
}

and when I try to load the file I try it like this:
var Worker = require("worker!worker.js");

It would never find the file, the only files exported by webpack are the bundle.js and the style.css, it looks like the worker loader is not loading anything at all.

Any help would be very welcomed! Thank you very much in advance!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions