【问题标题】:How to get Parcel to compile a Phaser game with 'classProperties'?如何让 Parcel 使用“classProperties”编译 Phaser 游戏?
【发布时间】:2023-03-26 12:40:01
【问题描述】:

我完成了一个 Phaser 游戏教程,该教程在使用以下方法链接到 Web 上的 Phaser.js 库时运行良好: <script src="//cdn.jsdelivr.net/npm/phaser@3.50.1/dist/phaser.js"></script>

但是现在当我尝试在本地使用 Phaser 和 npm 以及 Parcel 来运行游戏时,我得到了编译错误: @parcel/transformer-js: This experimental syntax requires enabling the parser plugin: 'classProperties'

这是由这种类型的代码引起的:

export default class Game extends Phaser.Scene
{
    /** @type {Phaser.Physics.Arcade.Sprite} */
    player;

我在 Google 上找不到任何东西,除了有人说要将插件添加到我的 package.json 文件中,所以现在我有了:

"dependencies": 
{
    "@babel/plugin-proposal-class-properties": "^7.13.0",
    "parcel": "^2.0.0-nightly.548",
    "phaser": "^3.53.1"
}

请问我还能做些什么来解决这个问题?

【问题讨论】:

    标签: phaser-framework parceljs


    【解决方案1】:

    您需要在项目的根目录中添加一个.babelrc 文件,其中包含以下代码:

    {
        "plugins": 
        [
          "@babel/plugin-proposal-class-properties"
        ]
    }
    

    来源:https://robkendal.co.uk/blog/2019-05-13-configure-parcel-js-and-babel-to-use-javascript-proposal-class-properties

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-30
      • 2017-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-02
      相关资源
      最近更新 更多