How run text-to-svg on browser?

649 views Asked by At

I wish run text-to-svg on browser. I install watchify, browserify and babel via npm install.

code of client/index.js

import TextToSVG from '../node_modules/text-to-svg/src/'

let textToSVG

window.onload = () => {
    console.log("onload")

  TextToSVG.load("vendor/Nautilus.otf", (err, t2s) => {
    if (err) {
        console.log("loading font error", err)
      return;
    }
    textToSVG = t2s;
  });
}

next, I run in console:

node_modules/.bin/watchify client/index.js -t babelify -o public/index.js

...and got error:

SyntaxError: 'import' and 'export' may only appear at the top level (6:0) while parsing /home/tln/www/0temp/draw-text2/node_modules/text-to-svg/src/index.js while parsing file: /home/tln/www/0temp/draw-text2/node_modules/text-to-svg/src/index.js

is it possible, run text-to-svg on browser?

1

There are 1 answers

0
LeetCodes On

i know this is an old question, but all you have to do is run npm run build, and it will produce a build folder with the built js file and everything you need, then just add the script to your site and upload the .js file and .otf file, i made the same mistake of just assuming it wouldnt work in browser and found this question without thinking until i looked at the package.json and found the build command and tried it