-
Notifications
You must be signed in to change notification settings - Fork 8
Browsers
Vitaly Tomilov edited this page Dec 22, 2020
·
10 revisions
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 shown below.
Here we generate a single connection-string.js
file, with complete library, which then can be included directly into any HTML page, with everything available from cs
namespace (which you can change).
- Create folder
generate
somewhere, and make it current. - Install Browserify, by running
npm i browserify
- Install
connection-string
, by runningnpm i connection-string
- Generate file
connection-string.js
with this command:
node ./node_modules/browserify/bin/cmd.js ./node_modules/connection-string/dist/index.js -o connection-string.js -s cs
- Copy generated
connection-string.js
file into your project.
Now any HTML file that includes connection-string.js
will be able to access everything via cs
namespace:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="./connection-string.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 might also want to uglify production version of the connection-string.js
file.