Skip to content

Commit ffa65d0

Browse files
authored
Merge pull request #16 from tymondesigns/feature/typescript
adding ts support
2 parents 932acd6 + 5d6aa82 commit ffa65d0

7 files changed

Lines changed: 30 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules
22
.DS_Store
33
*.log
4+
.rpt2_cache
45
build
56
dist
67
package-lock.json

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"prepare:babel": "babel --presets env src/*.js -d dist && npm t",
1414
"lint": "eslint src",
1515
"test:build": "node dist/cli.js --no-compress --cwd test/demo",
16-
"test": "npm run -s lint && npm run -s build && npm run -s test:build",
16+
"test:build:ts": "node dist/cli.js --no-compress --cwd test/ts-demo --entry=src/index.ts",
17+
"test": "npm run -s lint && npm run -s build && npm run -s test:build && npm run -s test:build:ts",
1718
"release": "npm run -s prepare && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
1819
},
1920
"repository": "developit/microbundle",
@@ -54,9 +55,11 @@
5455
"rollup-plugin-postcss": "^1.1.0",
5556
"rollup-plugin-preserve-shebang": "^0.1.4",
5657
"rollup-plugin-sizes": "^0.4.2",
58+
"rollup-plugin-typescript": "^0.8.1",
5759
"rollup-plugin-strict-alias": "^1.0.0",
5860
"rollup-plugin-uglify": "^2.0.1",
5961
"sade": "^1.3.1",
62+
"typescript": "^2.6.2",
6063
"uglify-es": "^3.3.6"
6164
},
6265
"devDependencies": {

src/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs';
2-
import { resolve, relative, dirname, basename } from 'path';
2+
import { resolve, relative, dirname, basename, extname } from 'path';
33
import chalk from 'chalk';
44
import { map, series } from 'asyncro';
55
import promisify from 'es6-promisify';
@@ -17,6 +17,7 @@ import gzipSize from 'gzip-size';
1717
import prettyBytes from 'pretty-bytes';
1818
import shebangPlugin from 'rollup-plugin-preserve-shebang';
1919
import flow from 'rollup-plugin-flow';
20+
import typescript from 'rollup-plugin-typescript';
2021
import camelCase from 'camelcase';
2122

2223
const interopRequire = m => m.default || m;
@@ -186,6 +187,8 @@ function createConfig(options, entry, format, writeMeta) {
186187
catch (e) {}
187188
}
188189

190+
const useTypescript = extname(entry)==='.ts';
191+
189192
let config = {
190193
inputOptions: {
191194
input: exportType ? resolve(__dirname, '../src/lib/__entry__.js') : entry,
@@ -202,7 +205,8 @@ function createConfig(options, entry, format, writeMeta) {
202205
inject: false,
203206
extract: !!writeMeta
204207
}),
205-
flow({ all: true }),
208+
useTypescript && typescript(),
209+
!useTypescript && flow({ all: true }),
206210
nodent({
207211
exclude: 'node_modules/**',
208212
noRuntime: true,
@@ -216,7 +220,7 @@ function createConfig(options, entry, format, writeMeta) {
216220
}
217221
}
218222
}),
219-
buble({
223+
!useTypescript && buble({
220224
exclude: 'node_modules/**',
221225
jsx: options.jsx || 'h',
222226
objectAssign: options.assign || 'Object.assign',

test/demo/src/two.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export async function two(...args) {
22
return args.reduce( (total, value) => total + value, 0);
3-
}
3+
}

test/ts-demo/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "ts-demo"
3+
}

test/ts-demo/src/car.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
interface Driveable {
2+
drive(distance: number): boolean;
3+
}
4+
5+
export default class Car implements Driveable {
6+
public drive(distance: number): boolean {
7+
return true;
8+
}
9+
}

test/ts-demo/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Car from './car';
2+
3+
let Ferrari = new Car();
4+
5+
export default Ferrari;

0 commit comments

Comments
 (0)