Hãy xem xét việc sử dụng grunt để tự động hóa việc này, có rất nhiều hướng dẫn xung quanh, nhưng đây là cách bắt đầu nhanh.
Đối với cấu trúc thư mục như:
blah/
blah/one.ts
blah/two.ts
blah/example/
blah/example/example.ts
blah/example/package.json
blah/example/Gruntfile.js
blah/example/index.html
Bạn có thể xem và làm việc với bảng chữ dễ dàng từ thư mục mẫu với:
npm install
grunt
Với package.json:
{
"name": "PROJECT",
"version": "0.0.1",
"author": "",
"description": "",
"homepage": "",
"private": true,
"devDependencies": {
"typescript": "~0.9.5",
"connect": "~2.12.0",
"grunt-ts": "~1.6.4",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-connect": "~0.6.0",
"grunt-open": "~0.2.3"
}
}
Và một tập tin càu nhàu:
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('grunt-ts');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
connect: {
server: {
options: {
port: 8089,
base: './'
}
}
},
ts: {
lib: {
src: ['../*.ts'],
out: 'PROJECT.js',
options: {
target: 'es3',
sourceMaps: false,
declaration: true,
removeComments: false
}
},
example: {
src: ['*.ts'],
out: 'example.js',
options: {
target: 'es3',
sourceMaps: false,
declaration: false,
removeComments: false
}
}
},
watch: {
lib: {
files: '../*.ts',
tasks: ['ts:lib', 'ts:example']
},
example: {
files: ['*.ts', '!*.d.ts'],
tasks: ['ts:example']
}
},
open: {
dev: {
path: 'http://localhost:8089/index.html'
}
}
});
grunt.registerTask('default', ['ts', 'connect', 'open', 'watch']);
}
tsc
đưa ra một lỗi,error TS6050: Unable to open file 'tsconfig.json'.
cho đến khi tôi loại bỏ những ý kiến