Webpack 加载了所有东西,但 worker

Webpack eveything loads but the worker

我正在尝试使用 webpack 来捆绑我的 React 项目。在我定义 webpack_public_path 变量后,所有模块和所有内容都加载得很好。 除了工人以外的一切。

const path = require('path');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');

module.exports = {
    mode: "production",

    resolve: {
        extensions: ["*", ".ts", ".tsx", ".js", ".mjs", ".css", ".ttf"]
    },

    module: {
        rules: [
            {
                test: /\.worker\.js$/,
                use: {
                    loader: 'worker-loader',
                    options: {inline: true}
                },
            },
            {
                test: /\.mjs$/,
                include: /node_modules/,
                type: 'javascript/auto'
            },
            {
                test: /\.css$/i,
                use: ['style-loader', 'css-loader'],
            },
            {
                test: /\.ttf$/,
                use: ['file-loader']
            },
            {
                test: /\.ts(x?)$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: "ts-loader"
                    }
                ]
            }
        ]
    },
    plugins: [
        new MonacoWebpackPlugin({
            languages: ['markdown'],
        })
    ],
    entry: './src/index.tsx',
    output: {
        path: path.resolve(__dirname, 'assets'),
        filename: 'graphqlschemaeditor.js'
    }
};

这是我的webpack.config.js

有人知道我做错了什么吗?非常感谢

您是否尝试过明确指定 publicPath

例如

{
  loader: 'worker-loader',
  options: { publicPath: '/workers/' }
}

这可能会解决加载问题。