Search code examples
javascriptlaravel-5typescriptgulplaravel-elixir

Laravel Elixir use Typescript instead of Javascript


I have a project that uses laravel 5.2 here I use laravel elixir for javascript pre-processors and I find that the typescript is easier to use because it is object-oriented and can also be compiled into Javascript, the question is can I combine Javascript and typescript using laravel Elixir? is there a library that can do that?

mix.script(['jquery.js', 'app.ts'], 'all.js']);

Thanks :)


Solution

  • Since it doesn't support TypeScript out of the box : https://laravel.com/docs/5.2/elixir#babel recommend just running tsc -w -p ./example/tsconfig.json and using the .js output as it is in mix.script.

    You can even use concurrently to run both tsc -w with other tasks : https://www.npmjs.com/package/concurrently