opentypejs / opentype.js

Read and write OpenType fonts using JavaScript.
https://opentype.js.org/
MIT License
4.49k stars 477 forks source link

dist/opentype.js dist works, opentype.min.js fails to load font #293

Closed valrus closed 7 years ago

valrus commented 7 years ago

Expected Behavior

I'm trying to load the League Gothic font downloadable on this page, specifically either the leaguegothic-regular-webfont.ttf or LeagueGothic-Regular.otf files.

Current Behavior

Using the current master of opentype.js (this commit), loading either font works fine.

However, using opentype.min.js (same commit), I get the following error in the opentype.load callback:

Could not load font: TypeError: _font2.default is not a constructor

Steps to Reproduce (for bugs)

  1. Download League Gothic from https://www.theleagueofmoveabletype.com/league-gothic
  2. Place either the .otf or .ttf version of the Regular font in a location accessible to the server
  3. Load opentype.min.js: <script src="static/js/text/opentype.min.js"></script>
  4. Load the font as shown in "Loading a font" (the path I used was 'static/fonts/leaguegothic/leaguegothic-regular-webfont.ttf')

Context

This isn't too killer as my project requires loading an mp3 too, so an extra 150K or so won't be a dealbreaker, but it's weird that minification seems to have broken something.

Your Environment

fdb commented 7 years ago

Thanks for the report. I'll check it out.

fdb commented 7 years ago

It seems to do with the usage of the new ES6-style import/exports we wrote. Apparently the minifier is not too happy with them.

fdb commented 7 years ago

Apparently UglifyJS doesn't work with ES6 modules.

I'll check if using the uglify-es version helps.

fdb commented 7 years ago

Short answer: no it doesn't :-)

I know just use the following command line to produce the minified build:

uglifyjs ./dist/opentype.js > ./dist/opentype.min.js

This seems to avoid the issues with ES2015, since Uglify only sees the babelified code.