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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working in browser #19

Closed
frankietaylor opened this issue Oct 9, 2015 · 6 comments
Closed

Not working in browser #19

frankietaylor opened this issue Oct 9, 2015 · 6 comments

Comments

@frankietaylor
Copy link

Output generated with
browserify index.js -o out.js

when ran in browser throws the following error:
Uncaught TypeError: Cannot read property 'replace' of undefined

Using the github source.

@samanthamjohn
Copy link

brotli is looking for process.argv[1], which won't be defined in the browser. As a work around, if you're using browserify:

if (global.process.argv.length < 2) {
    global.process.argv.push('');
}

@defue
Copy link
Contributor

defue commented Feb 20, 2016

I can't make it work in browser either. Compiled it with browserify, fixed the errors in the compiled file. But after the compiled js file is loaded in browser (without errors) I still can't access neither fontkit or require function thus the example from Readme.md doesn't work. Could someone please point me out how to correctly compile and use fontkit in browsers?

@defue
Copy link
Contributor

defue commented Feb 20, 2016

I got it to work . I created a file compile.js with the below content.
fontkit = require('fontkit');
And compiled it using browserify
browserify compile.js -o fontkit.js
Then added fontkit.js in script tag to browser and then I was able to use fontkit object in my scripts.

@defue
Copy link
Contributor

defue commented Feb 20, 2016

The result fonkit.js is 1.1 MB or 840KB minified. Does anyone know how to reduce the size?

@devongovett
Copy link
Member

The huge part is WOFF2 support (Emscripten compile). You can make a custom build using only the font formats you need to support.

var fontkit = require('fontkit/base');
fontkit.registerFormat(require('fontkit/src/TTFFont'));

You can see all the formats supported in the default configuration.

@Pomax
Copy link
Contributor

Pomax commented Feb 20, 2016

Remember that the example in the readme is an offline/server-side node example. If you're bundling, make sure to use the correct syntax: bundlers don't magically create "for the web" bundles, you need to tell them what to do. In the case of browserify, you need to use the --standalone flag, and you probably need to tell it to shim the global nodejs process variable. If you're using webpack, you need to tell it that it's output should be "for the web with a var export". If you're using any other bundler, the same process applies: make sure you're using the syntax necessary to turn "not for the browser" code into "for the browser" code.

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

No branches or pull requests

5 participants