Commit e4c9961d authored by Tim's avatar Tim

remove examples dir

parent a410f3b1
{
"name": "typescript-starter-example-browser",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"start": "http-server -c-1 ./build/ -o",
"build": "rollup -c && cpy src/index.html build/"
},
"devDependencies": {
"cpy-cli": "^1.0.1",
"http-server": "^0.9.0",
"rollup": "^0.41.4",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-typescript": "^0.8.1",
"typescript": "^2.2.0"
},
"dependencies": {
"typescript-starter": "^1.2.1"
},
"private": true
}
// rollup.config.js
import typescript from 'rollup-plugin-typescript';
import nodeResolve from 'rollup-plugin-node-resolve';
const pkg = require('./package');
export default {
entry: 'src/test.ts',
moduleId: pkg.name,
moduleName: 'BrowserTest',
// entry: 'dist/es/index.js',
dest: 'build/test.js',
format: 'iife',
sourceMap: true,
plugins: [
typescript({
typescript: require('typescript') // use local version
}),
nodeResolve({
module: true,
jsnext: true,
browser: true,
extensions: [ '.js', '.json' ],
preferBuiltins: false
})
]
}
<html>
<head>
<script src="test.js"></script>
</head>
<body>
</body>
</html>
// Note: we're not using the double method, so it should be excluded from the bundle
import { power, asyncABC } from 'typescript-starter'
let output = ''
function log (str: string) {
console.log(str)
output += str + '\n'
}
function logAndAlert (data: string[]) {
log('✔ asyncABC returned: ' + data)
window.alert(output)
}
log('Output:')
if (power(3,4) === 81) {
log('✔ power(3,4) === 81')
} else {
log('The "power" method seems to be broken.')
}
asyncABC().then( abc => logAndAlert(abc) )
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "build",
"rootDir": "src",
"module": "es6",
"declaration": false,
"removeComments": true,
"lib": [
"dom"
]
},
"include": [
"src/*.ts"
]
}
{
"name": "typescript-starter-example-node-typescript",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"start": "node build/test.js",
"build": "tsc"
},
"devDependencies": {
"@types/node": "^7.0.5",
"typescript": "^2.1.6"
},
"dependencies": {
"typescript-starter": "^1.2.1"
},
"private": true
}
// Typescript should resolve this using the same algorithm as Node.js.
// See examples/node-vanilla for more info.
import { double, power, asyncABC } from 'typescript-starter'
import * as assert from 'assert'
assert(double(6) === 12)
console.log('✔ double(6) === 12')
assert(power(3,4) === 81)
console.log('✔ power(3,4) === 81')
asyncABC().then( abc => console.log('✔ asyncABC returned:', abc) )
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "build",
"rootDir": "src"
},
"include": [
"src/*.ts"
]
}
{
"name": "typescript-starter-example-node-vanilla",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"start": "node test.js"
},
"dependencies": {
"typescript-starter": "^1.2.1"
},
"private": true
}
// Node.js should resolve this to the root of the repo. Since the path returns a
// directory, node will look for the `main` property in `package.json`, which
// should point to the `main` build.
var starter = require('typescript-starter');
// now we can use the library
var assert = require('assert');
assert(starter.double(6) === 12);
console.log("✔ starter.double(6) === 12");
assert(starter.power(3,4) === 81);
console.log("✔ starter.power(3,4) === 81");
starter.asyncABC().then( abc => console.log("✔ asyncABC returned:", abc) );
# Usage Examples
This directory (`/examples`) can be deleted when forking this project. It contains some simple examples of how forks of `typescript-starter` can be used by other projects. (Usually you'll want to provide these instructions in your root `readme.md`.)
## Node (Vanilla)
This shows the simplest use case – a quick, hacked-together Node.js project with no type safety, and no pre-processing. This is the way most of the Node.js ecosystem currently expects to import a node modules.
```bash
cd examples/node-vanilla
# install and run the example
npm install
npm run
```
## Node (Typescript)
This is for larger and more established Node.js projects which use Typescript for type safety. You'll notice that the type declarations and inline documentation from `typescript-starter` are accessible to [Typescript-compatible editors](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Editor-Support) like [vscode](https://code.visualstudio.com/).
```bash
cd examples/node-typescript
# install the dependencies
npm install
# type-check and build the example
npm run build
# run the example
npm start
```
## Browser (tree-shaking with Rollup)
This project imports the `power` and `asyncABC` functions from the ES6 output of `typescript-starter`, without importing the `double` function. This allows for the `double` method to be completely excluded from output via [Rollup's tree-shaking](http://rollupjs.org/), making the final javascript bundle potentially much smaller, even before using a minifier like [Uglify](https://github.com/mishoo/UglifyJS2).
To demonstrate, this example doesn't minify or remove comments. You can see where some javascript has been excluded from the bundle.
```bash
cd examples/browser
# install the dependencies
npm install
# build the javascript bundle
npm run build
# start a server and open the test in a browser
npm start
```
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment