mirror of
https://github.com/developit/microbundle.git
synced 2026-01-18 13:56:35 +00:00
Merge pull request #16 from tymondesigns/feature/typescript
adding ts support
This commit is contained in:
commit
ffa65d07e2
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
node_modules
|
||||
.DS_Store
|
||||
*.log
|
||||
.rpt2_cache
|
||||
build
|
||||
dist
|
||||
package-lock.json
|
||||
|
||||
@ -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": {
|
||||
|
||||
10
src/index.js
10
src/index.js
@ -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',
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
export async function two(...args) {
|
||||
return args.reduce( (total, value) => total + value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
3
test/ts-demo/package.json
Normal file
3
test/ts-demo/package.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "ts-demo"
|
||||
}
|
||||
9
test/ts-demo/src/car.ts
Normal file
9
test/ts-demo/src/car.ts
Normal file
@ -0,0 +1,9 @@
|
||||
interface Driveable {
|
||||
drive(distance: number): boolean;
|
||||
}
|
||||
|
||||
export default class Car implements Driveable {
|
||||
public drive(distance: number): boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
5
test/ts-demo/src/index.ts
Normal file
5
test/ts-demo/src/index.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import Car from './car';
|
||||
|
||||
let Ferrari = new Car();
|
||||
|
||||
export default Ferrari;
|
||||
Loading…
x
Reference in New Issue
Block a user