Express 使用webpack开发中间件时,如何在phaser应用程序中加载图像?

Express 使用webpack开发中间件时,如何在phaser应用程序中加载图像?,express,webpack,phaser-framework,webpack-dev-middleware,Express,Webpack,Phaser Framework,Webpack Dev Middleware,我有网页包/相位器/快速项目。当我加载应用程序时,Chrome控制台中出现以下错误,无法加载图像: GET http://localhost:8080/assets/ui/blue_button03.png 500 (Internal Server Error) GET http://localhost:8080/assets/ui/blue_button02.png 500 (Internal Server Error) 在相位器中加载这些图像: this.load.image('blue

我有网页包/相位器/快速项目。当我加载应用程序时,Chrome控制台中出现以下错误,无法加载图像:

GET http://localhost:8080/assets/ui/blue_button03.png 500 (Internal Server Error)

GET http://localhost:8080/assets/ui/blue_button02.png 500 (Internal Server Error)
在相位器中加载这些图像:

this.load.image('blueButton1', 'assets/ui/blue_button02.png');
this.load.image('blueButton2', 'assets/ui/blue_button03.png');
我尝试在我的phaser代码中包含的每个静态文件上都有相同的错误

网页包配置:

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

// Phaser webpack config
const phaserModule = path.join(__dirname, '/node_modules/phaser/')
const phaser = path.join(phaserModule, 'src/phaser.js')

const definePlugin = new webpack.DefinePlugin({
    __DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')),
    WEBGL_RENDERER: true, // I did this to make webpack work, but I'm not really sure it should always be true
    CANVAS_RENDERER: true // I did this to make webpack work, but I'm not really sure it should always be true
})

module.exports = {
    entry: {
        app: './src/js/main.js',
        vendor: ['phaser']
    },
    devtool: '#source-map',
    mode: 'development',
    target: 'web',
    output: {
        pathinfo: true,
        path: path.resolve(__dirname, 'dev'),
        publicPath: '/',
        library: '[name]',
        libraryTarget: 'umd',
        filename: '[name].js'
    },
    plugins: [
        definePlugin,
        new HtmlWebpackPlugin({
            filename: './index.html',
            template: './src/html/index.html',
            chunks: ['vendor', 'app'],
            chunksSortMode: 'manual',
            minify: {
                removeAttributeQuotes: false,
                collapseWhitespace: false,
                html5: false,
                minifyCSS: false,
                minifyJS: false,
                minifyURLs: false,
                removeComments: false,
                removeEmptyAttributes: false
            },
            hash: false
        }),
        new webpack.NoEmitOnErrorsPlugin()
    ],
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: "babel-loader"
            },
            {
                // Loads the javacript into html template provided.
                // Entry point is set below in HtmlWebPackPlugin in Plugins 
                test: /\.html$/,
                use: [
                {
                    loader: "html-loader",
                    //options: { minimize: true }
                }
                ]
            },
            {
                test: /\.(png|svg|jpg|gif|wav)$/,
                use: ['file-loader']
            },
            {
                test: /\.css$/,
                use: [ 'style-loader', 'css-loader' ]
            },
            { test: /phaser-split\.js$/, use: ['expose-loader?Phaser'] },
            { test: [/\.vert$/, /\.frag$/], use: 'raw-loader' }
        ]
    }
}
这就是我在我的server.js中使用webpack dev中间件的方式:

const app = express(),
            DIST_DIR = __dirname,
            HTML_FILE = path.join(DIST_DIR, 'index.html'),
            compiler = webpack(config);

var server = http.Server(app);

// binds the serv object we created to socket.io
var io = socketio(server);

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

app.get('*', (req, res, next) => {
    compiler.outputFileSystem.readFile(HTML_FILE, (err, result) => {
        if (err) {
            return next(err);
        }
        res.set('content-type', 'text/html');
        res.send(result);
        res.end();
    });
});

const PORT = process.env.PORT || 8080;
项目结构:

 +-- dev
 |  |  
 |  +-- assets
 |  +-- index.html
 |  +-- app.js
 |  +-- server.js
 |  +-- vendor.js
 |    
 +-- src
 |  |  
 |  +-- assets
 |  +-- html
 |  |
 |  |  +-- index.html
 |  |
 |  +-- server
 |  |
 |  |  +-- server.js
 |  |
 |  +-- js
 |  |
 |  |  +-- main.js
 |  |
 |    
 +-- package.json
 |    
 +-- webpack.config.js

有什么建议可以让它正常工作吗?因为如果我不使用webpack开发中间件应用程序,效果会很好。但每次进行某些更改时都要重建project实在太烦人了。

如果您首先导入资产,Webpack将解析捆绑包中的路径。然后,您可以将其加载到相位器中,如下所示:

import blueButton1 from '../assets/ui/blue_button02.png'
this.load.image('blueButton1', blueButton1);
作为替代方案,您可以使用以下插件:

能否共享项目的目录结构?添加了目录结构