Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to TypeScript 🦄 #6

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
node_modules/
package-lock.json

npm-debug.log*
yarn-debug.log*
yarn-error.log*

# rollup
.rpt2_cache

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ npm install hotstuff
```

## Usage
The preferred method of pulling HotStuff into your project is using NPM and a CommonJS module system.
The preferred method of pulling HotStuff into your project is using NPM. You can use either the CommonJS `require` or module `import` syntax.

```javascript
const HotStuff = require('hotstuff')
// or
import HotStuff from 'hotstuff'
```

You can then create a new HotStuff object using one of the methods below.
Note: HotStuff attaches events using addEventListener on both the keydown and keyup events so the object you pass to HotStuff must support those events.
Note: HotStuff attaches events using addEventListener on both the keydown and keyup events so the object you pass to HotStuff must support those events.

```javascript
const element = document.getElementById('elem')
const hotStuff = new HotStuff(element)

// You can also attach to the window
// You can also attach to the window
const hotStuff = new HotStuff(window)
// by default HotStuff attaches itself to the window object if there is one
const hotStuff = new HotStuff()
Expand Down
83 changes: 83 additions & 0 deletions build/rollup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* eslint-disable */

// npm install rollup-plugin-typescript2 typescript --save-dev
import typescript from 'rollup-plugin-typescript2'
import { terser } from 'rollup-plugin-terser'
// import resolve from 'rollup-plugin-node-resolve'

// ------------------------------------------------------------------------------------------
// formats
// ------------------------------------------------------------------------------------------
// amd – Asynchronous Module Definition, used with module loaders like RequireJS
// cjs – CommonJS, suitable for Node and Browserify/Webpack
// esm – Keep the bundle as an ES module file
// iife – A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this, because it leads to smaller file sizes.)
// umd – Universal Module Definition, works as amd, cjs and iife all in one
// system – Native format of the SystemJS loader

const pkg = require('../package.json')

export default [
// CJS
{
input: 'src/index.ts',
plugins: [
typescript({useTsconfigDeclarationDir: true}),
],
external: Object.keys(pkg.dependencies || []),
output: {
file: 'dist/index.cjs.js',
format: 'cjs',
sourcemap: false,
name: 'Hotstuff',
exports: 'named',
}
},
// ESM
{
input: 'src/index.ts',
plugins: [
typescript({useTsconfigDeclarationDir: true}),
],
external: Object.keys(pkg.dependencies || []),
output: {
file: 'dist/index.esm.js',
format: 'esm',
sourcemap: false,
name: 'Hotstuff',
exports: 'named',
}
},
// CJS minified
{
input: 'src/index.ts',
plugins: [
typescript({useTsconfigDeclarationDir: true}),
terser()
],
external: Object.keys(pkg.dependencies || []),
output: {
file: 'dist/index.cjs.min.js',
format: 'cjs',
sourcemap: false,
name: 'Hotstuff',
exports: 'named',
}
},
// ESM minified
{
input: 'src/index.ts',
plugins: [
typescript({useTsconfigDeclarationDir: true}),
terser()
],
external: Object.keys(pkg.dependencies || []),
output: {
file: 'dist/index.esm.min.js',
format: 'esm',
sourcemap: false,
name: 'Hotstuff',
exports: 'named',
}
}
]
Loading