【发布时间】:2020-09-20 11:42:59
【问题描述】:
这是错误的文本
我正在尝试在 Phaser 3.23.0 的游戏中加载一些图像 图片在下面文件中的函数 preload() 中加载
main.js
import Phaser from 'phaser';
function preload() {
this.load.image('sky', 'assets/sky.png');
this.load.image('ground', 'assets/platform.png');
this.load.image('star', 'assets/star.png');
this.load.image('bomb', 'assets/bomb.png');
this.load.spritesheet('dude',
'assets/dude.png',
{ frameWidth: 32, frameHeight: 48 });
}
function create() {
this.add.image(400, 300, 'sky');
}
function update() {
}
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
scene: {
preload,
create,
update,
},
};
// eslint-disable-next-line no-unused-vars
const game = new Phaser.Game(config);
const canvas = document.querySelector('canvas');
console.log(game);
我输入
npm run webpack-dev-server --mode development
并在 localhost:8080 启动 webpack-dev-server
然后我得到这些错误:
这些是控制台中的错误。 Chrome 浏览器。
这些是网络中的错误。 Chrome浏览器
这些是控制台中的错误。火狐浏览器。
Firefox 没有任何网络活动。一个请求都没有。
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Making your first Phaser 3 Game - Part 1</title>
<style type="text/css">
</style>
</head>
<body>
</body>
</html>
webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const config = {
entry: './src/scripts/main.js',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'sass-loader',
],
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: {
loader: 'file-loader?name=/src/assets/[name].[ext]',
options: {
name: '[name].[hash].[ext]',
outputPath: 'assets/',
},
},
},
{
test: /\.html$/i,
loader: 'html-loader',
},
],
},
output: {
path: path.resolve(
__dirname,
'dist',
),
},
plugins: [
new HtmlWebpackPlugin({
title: 'Output Management',
template: './src/index.html',
}),
],
};
module.exports = (env, argv) => {
if (argv.mode === 'development') {
config.devtool = 'source-map';
config.output.filename = 'main.bundle.js';
}
if (argv.mode === 'production') {
config.plugins.push(new CleanWebpackPlugin());
config.output.filename = 'main.[hash].bundle.js';
}
return config;
};
This 是提出此问题时的回购协议。
【问题讨论】:
标签: javascript webpack webpack-dev-server phaser