Skip to content

Browsers

Vitaly Tomilov edited this page Jun 19, 2020 · 10 revisions

As explained on the main page, the easiest way to use this library from a browser is via TypeScript, so you can bundle it any way you want. And that's why this library doesn't ship with the browser file, to avoid bloating.

If, however, you do need to include it manually into an HTML page, you can create such browser-compatible file yourself, using Browserify, as explained in the example below.

Example below will generate a single JavaScript file, with the complete connection-string library, which then can be included directly into any HTML page, with all types available from the cs namespace.

  1. Create a generate folder somewhere, and make it current.
  2. Install Browserify, by running npm i browserify
  3. Install connnection-string, by running npm i connection-string
  4. Make folder node_modules/browserify/bin current
  5. Run node cmd.js ../../connection-string/dist/index.js -o cs.js -s cs
  6. Copy generated cs.js file into your project

Now any HTML file that includes cs.js will be able to access all types via cs namespace:

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="./cs.js"></script>
</head>
<body>
    <script>
        console.log(new cs.ConnectionString('test://localhost:123'));
        // You also have access to cs.HostType
    </script>
</body>
</html>

P.S. You will also want to uglify production version of the cs.js file.

Clone this wiki locally