-
Notifications
You must be signed in to change notification settings - Fork 8
Browsers
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.
- Create a
generate
folder somewhere, and make it current. - Install Browserify, by running
npm i browserify
- Install
connnection-string
, by runningnpm i connection-string
- Make folder
node_modules/browserify/bin
current - Run
node cmd.js ../../connection-string/dist/index.js -o cs.js -s cs
- 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.