Skip to content

Commit

Permalink
a way to bundle typescript to single javascript file for browser
Browse files Browse the repository at this point in the history
  • Loading branch information
TipzCM committed Feb 27, 2020
1 parent 80eddd1 commit 848b88a
Show file tree
Hide file tree
Showing 8 changed files with 1,230 additions and 27 deletions.
3 changes: 3 additions & 0 deletions greeter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class Greeter {
greet(): void;
}
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1,204 changes: 1,191 additions & 13 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@
"main": "dist/index.js",
"module": "dist/index.es.js",
"types": "dist/index.d.ts",
"files": ["dist"],
"files": [
"dist"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build":"rollup -c",
"watch":"rollup -cw"
"build": "rollup -c",
"watch": "rollup -cw"
},
"author": "leif stawnyczy",
"license": "MIT",
"dependencies": {
"@rollup/plugin-json": "^4.0.2",
"@types/mathjs": "^6.0.4",
"mathjs": "^6.6.1"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-node-resolve": "^7.1.1",
"rollup": "^1.31.1",
"rollup-plugin-typescript2": "^0.26.0",
"typescript": "^3.8.2"
Expand Down
18 changes: 9 additions & 9 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import typescript from 'rollup-plugin-typescript2'

import resolve from '@rollup/plugin-node-resolve'
import pkg from './package.json'
import commonjs from '@rollup/plugin-commonjs'


export default {
input: 'src/index.ts',
output: [
{
file: pkg.main,
format: 'cjs',
},
{
file: pkg.module,
format: 'es',
},
file: 'dist/bundle.js',
format: 'iife',
name: 'version'
}
],
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],

plugins: [
resolve(),
commonjs(),
typescript({
typescript: require('typescript'),
}),
Expand Down
6 changes: 5 additions & 1 deletion src/greeter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { sqrt } from "mathjs";

export class Greeter {
greet() {
console.log('hello world');
let rounded = sqrt(-4);

console.log('hello world ' + rounded);
}
}
8 changes: 8 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<script src="../dist/bundle.js"></script>
</head>
<body>

</body>
</html>
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"declarationDir": "./dist",
"module": "es6",
"noImplicitAny": true,
"lib": ["es5", "dom", "ES2015"],
"outDir": "./dist",
"target": "es5"
},
Expand Down

0 comments on commit 848b88a

Please sign in to comment.