text-to-svg icon indicating copy to clipboard operation
text-to-svg copied to clipboard

Browser Based Sample not working

Open villanus opened this issue 7 years ago • 15 comments

The file /test/browser.html is not working.

The url for browser.js referenced in the browser sample is wrong.
Tried browser.js is but it throws error on line 7 import TextToSVG from '../src';

villanus avatar Apr 17 '17 06:04 villanus

Hi @villanus,

Please try npm run build to get transpiled code.

shrhdk avatar Apr 18 '17 12:04 shrhdk

Do I need to browserify it after?
Is it possible for you to do an update with a working web version?

I am on a windows asp setup and running node on server is not an option

Thanks

villanus avatar Apr 19 '17 07:04 villanus

Do I need to browserify it after?

No, you just need npm run build

I tried /test/browser.html, and it worked correctly.

This is my steps.

$ node -v
v6.9.4
$ git clone https://github.com/shrhdk/text-to-svg.git
$ cd text-to-svg
$ npm install
$ npm run build

after this

  1. Open browser.html
  2. Click load button and see success message.
  3. Click getSVG button

shrhdk avatar Apr 20 '17 03:04 shrhdk

Is it possible to use text-to-svg without gulp? Actually I would like to use it bundling with browserify

SimoneMSR avatar May 15 '17 23:05 SimoneMSR

It did not work for me.

villanus avatar May 16 '17 08:05 villanus

@SimoneMSR Yes, my test code for web browser also using Browserify.

Please refer the following task:

https://github.com/shrhdk/text-to-svg/blob/b4a77854f907a0c61228c056f711ba0dfd5c0196/gulpfile.babel.js#L51

shrhdk avatar May 20 '17 14:05 shrhdk

@villanus

I tried with Safari, Chrome and Firefox on macOS Sierra, and it works correctly.

Could you tell me your environment?

Have you seen the success! message after font loading? It takes few minutes to load the font in narrow band.

shrhdk avatar May 20 '17 14:05 shrhdk

@shrhdk thanks for your reply. How do I use that script, I have included in my main.js the row

require("text-to-svg/build/test/browser.js")

but it prompt an error: Cannot find module './path' from folder

Where am I wrong? I have also used concatenify like this

var concatenify = require('concatenify');
concatenify("main.js");
concatenify("text-to-svg/build/test/browser.js");

...but nothing.

SimoneMSR avatar May 30 '17 18:05 SimoneMSR

Even the command npm run build does not work. It says

no gulp file

I have node v 7.0.0

SimoneMSR avatar May 30 '17 19:05 SimoneMSR

Never worked for me either but I am on node 4. Maybe you can build the web version and do a update to the code?

villanus avatar May 30 '17 23:05 villanus

How run text-to-svg on browser?

pyjack avatar Dec 16 '18 05:12 pyjack

Hi @pyjack,

Please try the following steps.

  1. Build the code in the project root directory.
$ npm install
$ npm run build
  1. Open test/browser.html with Web Browser.

shrhdk avatar Dec 16 '18 08:12 shrhdk

It still does not work, path is not defined in browsers, only in node.

ikoruk avatar Jun 27 '19 16:06 ikoruk

I've Installed it like @shrhdk said and it works, It provides an app with a simple UI, and I can now use it to convert text to svg from the browser.

But I was not able to make it work on my own environment, l tried to run it on a React App following the docs, but also got the path Issue and It was very frustrating. It said something about Webpack not including certain node components by default anymore, I don't know, I guess I'm not smart enough... I wish there were codepen examples and/or tutorials in the docs.

natirivero avatar Mar 24 '23 14:03 natirivero

<script type="module">
  import TextToSVG from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
  
  // First argument is URL on web browsers, but it is file path on Node.js.
  TextToSVG.load(
    'https://rawgit.com/shrhdk/text-to-svg/master/fonts/ipag.ttf',
    function (err, textToSVG) {
      const svg = textToSVG.getSVG('hello');
      console.log(svg);
    }
  );
</script>

@shrhdk Console: r.load is not a function

natirivero avatar Mar 24 '23 15:03 natirivero