phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
36.64k stars 7.07k forks source link

The jsDeliver's `phaser@3.80.1/+esm` link doesn't work #6840

Open 8Observer8 opened 2 weeks ago

8Observer8 commented 2 weeks ago

I don't know is it an issue of jsDeliver or Phaser. I have created both. The jsDeliver's issue: https://github.com/jsdelivr/jsdelivr/issues/18585

This link doesn't work: https://cdn.jsdelivr.net/npm/phaser@3.80.1/+esm Try to run the example below.

Playground: https://plnkr.co/edit/MCZZM4MzkMSkFf4V?preview

index.html

<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>The jsDeliver's `phaser@3.80.1/+esm` link doesn't work</title>
</head>

<body>
    <p><a href="https://github.com/phaserjs/phaser/issues/6840" target="_black">Issue for Phaser</a></p>
    <p><a href="https://github.com/jsdelivr/jsdelivr/issues/18585" target="_black">Issue for jsDelivr</a></p>

    <script type="importmap">
        {
            "imports": {
                "phaser3": "https://cdn.jsdelivr.net/npm/phaser@3.80.1/+esm"
                // "phaser3": "https://8observer8.github.io/libs/phaser@3.80.1/phaser.esm.min.js"
            }
        }
    </script>

    <script type="module" src="./js/index.js"></script>
</body>

</html>

index.js

import { WEBGL, Game } from "phaser3";

const config = {
    type: WEBGL,
    width: 400,
    height: 300,
    scene: { preload, create, update },
    backgroundColor: "#555",
};

const game = new Game(config);

function preload() {
    console.log("preload");
}
function create() {}
function update() {}
photonstorm commented 2 weeks ago

jsDelivr is taking a perfectly valid ESM module and then running it through Rollup and Terser again. For reasons best known only to them. I assume it's screwing-up Phaser in the process. Maybe this works on some projects, but I doubt it will on Phaser until we move to being a purely ESM based library.

samme commented 2 weeks ago

You can use https://cdn.jsdelivr.net/npm/phaser@3.80.1/dist/phaser.esm.js etc. instead.

8Observer8 commented 2 weeks ago

I prefer to use GitHub Pages because there are problems sometimes with UNPKG and jsDelivr. I have made this page for some libraries: https://8observer8.github.io/tutorials/setup/how-to-setup-js-libraries-as-es6-modules/public/index.html

Phaser 3:

You can use these links for @box2d/core:

GitHub Pages:

Skypack:

jsDelivr:

These links do not work: