grunt-typescript 不会在指定的“dest”中生成 js 文件

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

本文关键字:文件 js dest grunt-typescript      更新时间:2023-09-26

>我有以下目录结构:

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

在咕噜咕噜文件中,我有这个:

//Project Config
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    typescript: {
        base: {
            src: ['./javascripts/ts/*.ts'],
            dest: './javascripts/'
        }
    }       
});

我希望 js 文件位于javascripts/目录中。但是当我运行grunt typescript时,它会创建这个奇怪的目录结构:

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

我希望编译file.js出现在原始javascripts/目录中。为什么会这样?我应该写什么才能在所需文件夹中编译.js文件?

看到输出,我认为以下内容将起作用:

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

我个人创作并维护grunt-ts:https://npmjs.org/package/grunt-ts

另一种选择是使用 base_path 配置:

//Project Config
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    typescript: {
        base: {
            src: ['./javascripts/ts/*.ts'],
            dest: './javascripts/',
            options: {
                base_path: './javascripts/ts'
            }
        }
    }       
});