webpack-loader生成的块从webpack-dev-server发出404错误

时间:2017-11-08 04:55:44

标签: webpack webpack-dev-server web-worker

这是我的webpack配置的缩写:

const path = require('path');
const webpack = require('webpack');

const src = path.resolve(__dirname, 'src');
const dst = path.resolve(__dirname, 'www');
const node_modules = path.resolve(__dirname, 'node_modules');

module.exports = {
  module: {
      rules: [
          {
              test: /\.worker\.js$/,
              use: {
                  loader: 'worker-loader',
                  options: {
                      inline: false,
                      fallback: false,
                      name: '.' + path.sep + 'js' + path.sep + '[name].js'
                  }
              }
          },
          {
              test: /\.js$/,
              loader: 'babel-loader',
              options: {
                  presets: ['es2017', 'es2016', 'es2015' ],
              }
          },
          {
              test: /\.scss$/,
              use: [{ loader: "style-loader" },
                    { loader: "css-loader",
                      options: {
                          url: false
                      }},
                    { loader: "sass-loader" }]
          }
      ]
  },
  context: src,
  entry: {
    app: '.' + path.sep + 'js' + path.sep + 'app.js',
    styles: '.' + path.sep + 'styles' + path.sep + 'styles.scss'
  },
  output: {
    path: dst,
    filename: '.' + path.sep + 'js' + path.sep + '[name].js'
  }
};

我指的是这样的工人:

import StationWorker from './stations.worker.js';
...
        this.stationWorker = new WorkerConnection (new StationWorker ());

当我使用node_modules\.bin\webpack-dev-server -d --progress --content-base platforms\browser\www --port 8081运行我的应用时,输出告诉我它已生成.\js\stations.worker.js

         Asset     Size  Chunks                    Chunk Names
   .\js\app.js  15.2 MB       0  [emitted]  [big]  app
.\js\styles.js  1.07 MB       1  [emitted]  [big]  styles
...
Child worker:
    chunk    {0} .\js\stations.worker.js (main) 2.55 MB [entry] [rendered]

但是,当我的代码尝试加载此生成的文件时,我从服务器收到404错误。我尝试了各种组合,不包括名称中的路径,使用默认设置,并使用publicPath指定路径,所有这些都具有相同的效果。

如何让worker-loader生成webpack-dev-server能够投放的代码?

0 个答案:

没有答案