-
Notifications
You must be signed in to change notification settings - Fork 166
Preparation
Go back to How to use
Before start, let's see the different ways to use roosterjs. There are several ways to use RoosterJs, all of these ways have the same functionalities. You just need to pick one according to your project environment.
(You can find all source code of the examples in this page under publish/samplecode in source code.)
Under package roosterjs/dist, there are 10 files:
-
rooster.js
The packed code for roosterjs, contains all packages -
rooster.d.ts
Type definition for rooster.js -
rooster.js.map
Source map for rooster.js -
rooster-min.js
Minified version of rooster.js -
rooster-min.js.map
Source map for minified version of rooster.js -
rooster-amd.js
The packed code for roosterjs, in AMD format -
rooster-amd.d.ts
Type definition for rooster-amd.js -
rooster-amd.js.map
Source map for rooster-amd.js -
rooster-amd-min.js
Minified version of rooster-amd.js -
roosterjs-amd-min.js.map
Source map for minified version of rooster-amd.js
It is a simple way to reference to rooster.js from HTML file directly, then you can reference to all roosterjs types/functions/classes via roosterjs
object:
<html>
<body>
<div style="width: 500px; height: 400px; border: solid 1px black" id="contentDiv"></div>
<script src="rooster.js"></script>
<script>
var contentDiv = document.getElementById("contentDiv");
var editor = roosterjs.createEditor(contentDiv);
</script>
</body>
</html>
When working with NodeJs, you can use require
to reference to rooster-amd.js:
var roosterjs = require("./rooster-amd.js");
var contentDiv = document.getElementById("contentDiv");
var editor = roosterjs.createEditor(contentDiv);
With typescript, you can use import keyword to reference rooster-amd.js:
import * as RoosterJs from './rooster-amd';
let contentDiv = document.getElementById('contentDiv') as HTMLDivElement;
let editor = RoosterJs.createEditor(contentDiv);
/// <reference path="./rooster" />
let contentDiv = document.getElementById('contentDiv') as HTMLDivElement;
let editor = roosterjs.createEditor(contentDiv);
In this case you need to explicitly link to rooster.js in HTML file (Supporse your typescript file will be packed to editor.js):
<html>
<body>
<div style="width: 500px; height: 400px; border: solid 1px black" id="contentDiv"></div>
<script src="rooster.js"></script>
<script src="editor.js"></script>
</body>
</html>
When working with NodeJs, it is recommended to use NPM packages of roosterjs:
package.json:
{
"name": "editor",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"roosterjs": "^6.4.1"
}
}
typescript file:
import * as RoosterJs from 'roosterjs';
let contentDiv = document.getElementById("contentDiv") as HTMLDivElement;
let editor = RoosterJs.createEditor(contentDiv);