Skip to content

Commit

Permalink
some final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
TipzCM committed Feb 28, 2020
1 parent fcb1a12 commit ebaea05
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
56 changes: 52 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,60 @@
This will bundle a simple typescript app with third party dependencies into a single javascript library for browsers (ie, can be consumed by a script tag).
## README

This is an example of a typescript app that is compiled down to a single js file for consumption in a browser.

## Technologies used
* typescript
* karma
* jasmine
* rollup (for bundling)


## How to use

`npm install`
`npm install` // installs

`npm run build`
`npm run build` // bundles

Output will be created in `dist/bundle.js`

Load `test/index.html` in browser and check console logs.
Load `test/index.html` in browser.

All exported classes are available under the namespace specified in
rollup.config.js -> output.name value (MyNamespace here)

## Unit testing

### Prerequisit

Chrome installed on machine

### Running

`./node_modules/karma/bin/karma start`

Runs tests without debugging.
Uses ChromeHeadless (ie, no browser will open).

### Debugging

Step 1
`./node_modules/karma/bin/karma start --no-single-run --browser=Chrome`

Step 2
Click "Debug" button

Step 3
Inspect page, go to sources, open up base/src and find ts files of interest (greeter.spec.ts and greeter.ts).

Step 4
Set breakpoints in browser and refresh page


## Helpful Hints

May wish to install karma and karma-cli globally:

`npm install karma karma-cli -g`

Then you can run using:
`karma start`
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function(config) {
"**/*.ts": "karma-typescript"
},
reporters: ["progress", "karma-typescript"],
browsers: ["Chrome"],
browsers: ["ChromeHeadless"],
singleRun: true
})
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"scripts": {
"build": "rollup -c",
"watch": "rollup -cw",
"prod:test": "./node_modules/karma/bin/karma start",
"test": "./node_modules/karma/bin/karma start --no-single-run --browser=Chrome"
},
"author": "leif stawnyczy",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
{
file: 'dist/bundle.js',
format: 'iife',
name: 'version'
name: 'MyNamespace'
}
],
external: [
Expand Down
14 changes: 12 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { Greeter } from "./greeter";

let greeter = new Greeter();
export class Test {
greeter: Greeter;

greeter.greet();
constructor() {
this.greeter = new Greeter();

this.greeter.greet();
}

callme() {
console.log(this.greeter.returnSomething(1.2));
}
}
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<script src="../dist/bundle.js"></script>
Expand Down

0 comments on commit ebaea05

Please sign in to comment.