Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace grunt-babel with a more TypeScript friendly solution #4

Open
enlight opened this issue Nov 15, 2015 · 5 comments
Open

Replace grunt-babel with a more TypeScript friendly solution #4

enlight opened this issue Nov 15, 2015 · 5 comments

Comments

@enlight
Copy link
Collaborator

enlight commented Nov 15, 2015

grunt-babel doesn't pass in source maps to Babel, so the source maps generated by TypeScript will not match the .js source output by Babel. Babel itself accepts source maps as input, so presumably it knows how to transform them along with the .js source files. Another problem with grunt-babel is that TypeScript writes out .js files, and then Babel overwrites them, it'd be better if the .js files were only written out to disk once. I haven't found an existing Grunt task that handles this sort of TypeScript->Babel workflow, so it looks like I'll have to write it myself.

grunt-babel is a good reference on how to use the Babel API, as for TypeScript, the following references will be useful:

  • Using the TypeScript Compiler API
  • dts-generator makes use of the Compiler API, and I've previously messed around with it in my fork.
  • ts-node uses the TypeScript Language Service API, I may end up using this API for the "watch" feature (if I decide to implement it at some point).
@enlight
Copy link
Collaborator Author

enlight commented Dec 24, 2015

Resolved in d1b5e20

I ended up going with a different solution to the one I originally described. The .ts files are compiled as usual except that the generated .js files now end up in the intermediate dir, then everything in that directory is fed to Babel and the output is written out to the lib dir. Using separate directories makes it easier to debug any issues with TypeScript code gen and Babel transforms, and means I don't have to mess around with the TypeScript compiler API right now (though it'd still be nice to get that done at some point).

Work is also underway to implement a watch task so that files in the intermediate dir are automatically transformed with Babel after they're output by the TypeScript compiler.

@enlight enlight closed this as completed Dec 24, 2015
@enlight
Copy link
Collaborator Author

enlight commented Dec 26, 2015

OK, juggling multiple Grunt watch tasks to get the TypeScript + Babel build working is too flaky, TypeScript Language Services it is, a single Grunt task will watch multiple projects and rebuild them as needed (including applying Babel transforms).

@enlight enlight reopened this Dec 26, 2015
@enlight
Copy link
Collaborator Author

enlight commented Jan 18, 2016

TypeScript + Babel compilation is now handled by ibsforts, watching/incremental rebuilding kinda sorta works, but I need add some sort of dependency resolution to ensure projects are built/rebuilt in the correct order.

@enlight
Copy link
Collaborator Author

enlight commented May 15, 2016

I can't be bothered maintaining ibsforts anymore, it still needs a bunch of work and I don't have the time to do it. Since Electron 1.1.0 comes with Node 6.1.0 which has 96% coverage of ES2015 I will be removing Babel from the build process after upgrading to Electron 1.1.0. As part of the streamlining of the build process I will also merge the common, main and renderer tsconfigs back into a single one (the disadvantages of having separate configs far outweigh the advantages at this point). And soon after that I'll probably ditch Grunt in favor of plain NPM scripts because Grunt takes too damn long to load up its tasks.

@enlight
Copy link
Collaborator Author

enlight commented Jun 3, 2016

Only thing left to do here is to replace the grunt sync task, which is unfortunately a bit tricky since I haven't yet found an NPM package that does what grunt-sync does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant