Rich-Harris / rollup-plugin-typescript

Bundle TypeScript files with Rollup
2 stars 1 forks source link

Emit ES6 modules #1

Open Rich-Harris opened 9 years ago

Rich-Harris commented 9 years ago

Am totally new to TypeScript, so not entirely sure what combination of compiler options will generate ES5 code but with ES6 module imports/exports. Without that, this plugin won't do anything useful!

robwormald commented 9 years ago

The general theory here is likely to be a bit different than babel - they provide a comprehensive (if occasionally esoteric) Language Services API : https://github.com/Microsoft/TypeScript/wiki/Using-the-Language-Service-API

Specifically : https://github.com/Microsoft/TypeScript/wiki/Using-the-Language-Service-API#reference-resolution-in-the-language-service

I haven't yet wrapped my brain around the rollup pipeline, so I'm gonna have to tinker with this some! We wrap this service in Broccoli in Angular2 : https://github.com/angular/angular/blob/master/tools/broccoli/broccoli-typescript.ts (which may or may not help you grok this at all....)

Rich-Harris commented 9 years ago

Uh... wow. That's a little more complex than I was expecting! I was hoping that it'd be possible to do something along the lines of

ts.transpile( code, {
  module: ts.ModuleKind.ES6
});

but it looks like the available module kinds are CommonJS, AMD, UMD, System, and None (which means CommonJS). Hmm.

robwormald commented 9 years ago

Yeah, it's ... non trivial, but quite powerful (and nicely usable if you author in TS)

I've got the basic bootstrapping set up, but in your basic test I can't get any of the plugin methods to fire. Thoughts?

robwormald commented 9 years ago

scratch that, version mismatch on rollup :D

robwormald commented 9 years ago

bleeding edge TS gives us the option we want :+1: this is gonna need a lot more work, but step 1 is a go.

Victorystick commented 9 years ago

I've already created a TypeScript plugin, but didn't have the permissions to create it in the Rollup organization. How about a merge?

robwormald commented 9 years ago

works for me!

I think we've both discovered the fatal flaw that @Rich-Harris did - currently we can either emit ES6 with import/export syntax, or emit ES5 with cjs, but so far not both.

This might mean dropping into the language services API and getting our AST on, though I've dropped a line to the TS folks asking if they've got any hints.

Victorystick commented 9 years ago

I just realised that we can depend on prerelease versions from NPM! rollup-plugin-typescript supports both features as of version 0.2.0! :rocket:

Rich-Harris commented 9 years ago

@Victorystick Nice! Easiest thing is probably just to move your repo into the Rollup organisation – I've move this one out of the way so that that's possible

Victorystick commented 9 years ago

@Rich-Harris Go ahead! I'll move it in!

Victorystick commented 9 years ago

@Rich-Harris Apparently I need admin access to the organisation to transfer ownership. :expressionless:

Rich-Harris commented 9 years ago

@Victorystick fixed!