【发布时间】:2019-12-11 19:10:11
【问题描述】:
我正在开发一个 TypeScript 应用程序,其中我项目的每个模块都有 README.md 文件。项目结构如下:
- tsconfig
- src
- actions
- assignShop
- index.ts
- index.test.ts
- README.md
- assignStore
- index.ts
- index.test.ts
- README.md
我的 tsconfig 如下:
{
"compilerOptions": {
"allowJs": false,
"declaration": true, // enable this once all files are .ts and we can remove allowJs
"esModuleInterop": true,
"lib": ["es2015", "es2017"],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"pretty": true,
"noImplicitAny": true,
"outDir": "./lib",
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"sourceMap": true,
"target": "es5",
},
"include": [
"src/**/*"
],
"compileOnSave": false
}
每当我编译我的文件时,它们都会编译为 ./lib 目录中的 .js,但我无法为每个已编译的操作版本获取我的 README.md。
更新:1 所以我厌倦了实施 grunt 来执行以下任务,但我想我需要一些指导。 这是我的 Gruntfile.js:
module.exports = function (grunt) {
grunt.initConfig({
clean: ['./lib'],
ts: {
default: {
tsconfig: './tsconfig.json'
}
},
copy: {
main: {
expand: true,
cwd: 'src/',
src: '**/*.md',
dest: 'lib/**/*'
},
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-ts');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.registerTask('default', ['clean', 'ts']);
};
解决方案 - Gruntfile.js
module.exports = function (grunt) {
grunt.initConfig({
clean: ['./lib'],
ts: {
default: {
tsconfig: './tsconfig.json'
}
},
copy: {
main: {
expand: true,
cwd: 'src/',
src: '**/*.md',
dest: 'lib/'
},
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-ts');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.registerTask('default', ['clean', 'ts']);
}
【问题讨论】:
标签: typescript gruntjs tsconfig grunt-contrib-copy