Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grunt-typescript doesn't produce js files in specified `dest`

I have the following directory structure :

root
|
|_ package.json
|_ Gruntfile.js
|
|_ javascripts/
   |_ ts/file.ts

In the Gruntfile I have this:

//Project Config
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    typescript: {
        base: {
            src: ['./javascripts/ts/*.ts'],
            dest: './javascripts/'
        }
    }       
});

I expect the js files to be in javascripts/ directory. However when I run grunt typescript , it creates this weird directory structure:

root
|
|_ package.json
|_ Gruntfile.js
|
|_ javascripts/
   |_ ts/file.ts
   |_ javascripts/
      |_ ts/
         |_ file.js

I expect the compiled file.js to appear in the original javascripts/ directory. Why is this so? What should I write to get compiled .js files in desired folder?

like image 459
Jatin Avatar asked Oct 08 '13 11:10

Jatin


People also ask

How do I use typescript with grunt?

If you're a Grunt expert, follow these steps: Run npm install grunt-ts in your project directory; this will install grunt-ts, TypeScript, and GruntJS. Add the ts task in your Gruntfile.js (see below for a minimalist one). Run grunt at the command line in your project folder to compile your TypeScript code.

What is gruntjs?

GruntJS is a web task runner built on top of NodeJS. The grunt ecosystem has thousands of useful plugins that should automate just about every task you might have. Grunt has two plugins to bundle and minify CSS and JavaScript.

Why does typescript need definitions files?

Typescript is a typed language. It needs definitions files for the libraries you're using to be able to do its work. There is an opensource repository full of TypeScript definitions for known libraries. Meaning someone has already done the job for us!

Does grunt-ts support the gruntjs standard DEST target property?

Grunt-ts does not support the GruntJS standard dest target property. Instead, you should use files, out, or outDir. Grunt-ts supports use of the GruntJS-centric files property on a target as an alternative to the tsc -centric use of src and out / outDir. The fast grunt-ts option is not supported in this configuration.


2 Answers

Seeing the output I would assume the following will work:

typescript: {
    base: {
        src: ['./javascripts/ts/*.ts'],
        dest: '../../javascripts/'
    }
} 

Personally I authored and maintain grunt-ts : https://npmjs.org/package/grunt-ts

like image 155
basarat Avatar answered Oct 02 '22 11:10

basarat


Another option is to make use of the base_path config:

//Project Config
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    typescript: {
        base: {
            src: ['./javascripts/ts/*.ts'],
            dest: './javascripts/',
            options: {
                base_path: './javascripts/ts'
            }
        }
    }       
});
like image 23
Jacob Eggers Avatar answered Oct 02 '22 12:10

Jacob Eggers