Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing gl-matrix with experimental scope hoisting results in it excluded #1888

Closed
kirbysayshi opened this issue Aug 13, 2018 · 2 comments
Closed

Comments

@kirbysayshi
Copy link

kirbysayshi commented Aug 13, 2018

馃悰 bug report

When importing any module/export from gl-matrix, using typescript, and --experimental-scope-hoisting, the resulting bundle is devoid of all gl-matrix code. The bundle for the gist linked below looks like this, for example:

// index.ts
import { mat4 } from 'gl-matrix';
console.log('mat4?', mat4);
(function () {
// ASSET: index.ts
var $QCb$exports = {};
var $QCb$export$__esModule = true;
$QCb$exports.__esModule = $QCb$export$__esModule;
var $QCb$var$gl_matrix_1 = {};
console.log('mat4?', $QCb$var$gl_matrix_1.mat4);

if (typeof exports === "object" && typeof module !== "undefined") {
  // CommonJS
  module.exports = $QCb$exports;
} else if (typeof define === "function" && define.amd) {
  // RequireJS
  define(function () {
    return $QCb$exports;
  });
}
})();

I've tried as many variations of import and paths that I can think of, but still cannot get gl-matrix included in the final bundle.

Perhaps I'm doing something wrong!

馃帥 Configuration (.babelrc, package.json, cli command)

Completely unconfigured, aside from experimental scope hoisting and --no-minify for the sake of readability when debugging.

https://gist.github.com/kirbysayshi/f1c38d272cb3d5832342f8fc5c689fb6

npm install
npm run build
cd dist/ && serve # then visit in a browser. You'll see `undefined` in the console!

馃 Expected Behavior

mat4 / gl-matrix is included in the bundle

馃槸 Current Behavior

Nothing from gl-matrix is included in the bundle, aside from the name assigned to the import statement.

All code that depends on gl-matrix fails, since it's not there.

馃拋 Possible Solution

I haven't been able to find a workaround, and have tried:

The only thing that works so far is to not use TypeScript! Included in the gist is an index.js file to demonstrate that.

I've also tried using a simple require statement, which also fails to include gl-matrix:

const glMatrix = require('gl-matrix');
console.log('mat4?', mat4);

Which results in:

(function () {
console.log('mat4?', mat4); // ASSET: index.ts
})();

Which, by the way, is amazingly small! Once this issue gets fixed a zero-conf tree shaking + scope hoisting is going to be a killer feature!

馃敠 Context

Just trying to use TypeScript plus the scope hoisting to cut down on bundle size! In this case it's for the JS13K competition that starts soon.

馃捇 Code Sample

https://gist.github.com/kirbysayshi/f1c38d272cb3d5832342f8fc5c689fb6

See above for steps to reproduce!

@mischnic
Copy link
Member

This seems to have gotten fixed.
@kirbysayshi Does it work now?

@kirbysayshi
Copy link
Author

Sorry that I never came back to this. Yes, it has been fixed! Thank you for all your hard work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants