Merge pull request #16 from tymondesigns/feature/typescript

adding ts support
This commit is contained in:
Jason Miller 2018-01-22 14:33:55 -05:00 committed by GitHub
commit ffa65d07e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 5 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
node_modules
.DS_Store
*.log
.rpt2_cache
build
dist
package-lock.json

View File

@ -13,7 +13,8 @@
"prepare:babel": "babel --presets env src/*.js -d dist && npm t",
"lint": "eslint src",
"test:build": "node dist/cli.js --no-compress --cwd test/demo",
"test": "npm run -s lint && npm run -s build && npm run -s test:build",
"test:build:ts": "node dist/cli.js --no-compress --cwd test/ts-demo --entry=src/index.ts",
"test": "npm run -s lint && npm run -s build && npm run -s test:build && npm run -s test:build:ts",
"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"
},
"repository": "developit/microbundle",
@ -54,9 +55,11 @@
"rollup-plugin-postcss": "^1.1.0",
"rollup-plugin-preserve-shebang": "^0.1.4",
"rollup-plugin-sizes": "^0.4.2",
"rollup-plugin-typescript": "^0.8.1",
"rollup-plugin-strict-alias": "^1.0.0",
"rollup-plugin-uglify": "^2.0.1",
"sade": "^1.3.1",
"typescript": "^2.6.2",
"uglify-es": "^3.3.6"
},
"devDependencies": {

View File

@ -1,5 +1,5 @@
import fs from 'fs';
import { resolve, relative, dirname, basename } from 'path';
import { resolve, relative, dirname, basename, extname } from 'path';
import chalk from 'chalk';
import { map, series } from 'asyncro';
import promisify from 'es6-promisify';
@ -17,6 +17,7 @@ import gzipSize from 'gzip-size';
import prettyBytes from 'pretty-bytes';
import shebangPlugin from 'rollup-plugin-preserve-shebang';
import flow from 'rollup-plugin-flow';
import typescript from 'rollup-plugin-typescript';
import camelCase from 'camelcase';
const interopRequire = m => m.default || m;
@ -186,6 +187,8 @@ function createConfig(options, entry, format, writeMeta) {
catch (e) {}
}
const useTypescript = extname(entry)==='.ts';
let config = {
inputOptions: {
input: exportType ? resolve(__dirname, '../src/lib/__entry__.js') : entry,
@ -202,7 +205,8 @@ function createConfig(options, entry, format, writeMeta) {
inject: false,
extract: !!writeMeta
}),
flow({ all: true }),
useTypescript && typescript(),
!useTypescript && flow({ all: true }),
nodent({
exclude: 'node_modules/**',
noRuntime: true,
@ -216,7 +220,7 @@ function createConfig(options, entry, format, writeMeta) {
}
}
}),
buble({
!useTypescript && buble({
exclude: 'node_modules/**',
jsx: options.jsx || 'h',
objectAssign: options.assign || 'Object.assign',

View File

@ -1,3 +1,3 @@
export async function two(...args) {
return args.reduce( (total, value) => total + value, 0);
}
}

View File

@ -0,0 +1,3 @@
{
"name": "ts-demo"
}

9
test/ts-demo/src/car.ts Normal file
View File

@ -0,0 +1,9 @@
interface Driveable {
drive(distance: number): boolean;
}
export default class Car implements Driveable {
public drive(distance: number): boolean {
return true;
}
}

View File

@ -0,0 +1,5 @@
import Car from './car';
let Ferrari = new Car();
export default Ferrari;