gkjohnson / three-mesh-bvh

A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes.
https://gkjohnson.github.io/three-mesh-bvh/example/bundle/raycast.html
MIT License
2.39k stars 247 forks source link

umd package missing .js #600

Closed deyihu closed 8 months ago

deyihu commented 8 months ago

Describe the bug

umd package

Browser cannot recognize .cjs

The browser will not run the scripts inside

NFX)`9DPJCC@SHSWUG9SSYF

To Reproduce

Code

  <script type="text/javascript" src="https://unpkg.com/three@0.138.0/build/three.min.js"></script>
<script src="https://unpkg.com/three-mesh-bvh@0.6.8/build/index.umd.cjs"></script>

Live example

-

Expected behavior

umd package Should use js as the extension

  <script type="text/javascript" src="https://unpkg.com/three@0.138.0/build/three.min.js"></script>
<script src="https://unpkg.com/three-mesh-bvh@0.6.8/build/index.umd.js"></script>

need update rollup config

{
        input: './src/index.js',
        treeshake: false,
        external: p => /^three/.test( p ),

        output: {

            name: 'MeshBVHLib',
            extend: true,
            format: 'umd',
            file: './build/index.umd.js',
            sourcemap: true,

            globals: p => /^three/.test( p ) ? 'THREE' : null,

        },

    },

Screenshots

If applicable, add screenshots to help explain your problem (drag and drop the image).

Platform:

gkjohnson commented 8 months ago

There's not browser requirement that javascript files end with a .js extension - this is an issue with unpkg.com setting the returned content type to "text/plain" rather than "application/javascript" in the response headers. Please report it to them. Both .cjs and .mjs extensions are used fairly broadly to distinguish module-style js files and commonjs-style ones.