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?
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.
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.
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!
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.
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
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'
}
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With