mliebelt/pgn-parser

Documentation: Using pgn-parser in the Browser

Bebul opened this issue · 1 comments

Bebul commented

I had hard time to make the library possible to use in the client side application, Browser.

The successfull steps were at last:

  1. install Browserify
  2. store the parse function as window property
    File: parsePgn.js
   const parser =  require('./pgn-parser.js')
   window.parsePgn = parser.parse
  1. process newly created parsePgn.js through Browserify:
 browserify parsePgn.js -o pgn-bundle.js
  1. in the index.html then use
 <script type="text/javascript" src="pgn/pgn-bundle.js"></script>
  1. and the parsePgn is now available:
     let gameList = parsePgn('[White "Me"] [Black "Magnus"] 1. f4 e5 2. g4 Qh4#', {startRule: "game"});

Thank you a lot for documenting that tedious process in a ticket. The reason that there is no documentation at all about that is, that I am using the library only as part of PgnViewerJS, which in itself has a build process that ensures that the whole thing runs in a browser. I am not at all an expert in Javascript and the best way to bring libraries to the browser, I would not have suspected that someone is interested in this.

I will take your ticket as a reminder, that there may be different ways to use the library, and check the (sparse) documentation, and hopefully improve it then later. Thank you!