Ben typescript bir hayvan projesi dönüştürmek çalışıyorum ve kullanımı mümkün görünmüyor tscdosyalarımı izleyip derlemek yarar. Yardım kullanmalıyım diyor -wanahtarı, ama hepsi izlemek ve derleme olamaz gibi görünüyor *.tsyinelemeli bazı dizindeki dosyaları. Gibi bir şey bu görünüyor tscişlemek gerekir. Seçeneklerim nelerdir?
Nasıl izleyebilir ve tüm typescript kaynaklarını derlemek için?
Adlı bir dosya oluşturun tsconfig.jsonproje kök ve içinde hatları şunlardır:
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"module": "commonjs",
"target": "ES5",
"outDir": "ts-built",
"rootDir": "src"
}
}
Unutmayın o outDirderlenmiş JS dosyaları almak için dizinin yolu olmalıdır ve rootDirkaynak (ts) dosyalarını içeren dizinin yolu olmalıdır.
Bir terminal açın ve çalıştırın tsc -w, herhangi bir derleme olacak .tsdosyayı srciçine dizinde .jsve bunları saklamak ts-builtdizinde.
Typescript 1.5 beta tsconfig.json adlı bir yapılandırma dosyası için destek tanıttı. Bu dosyada, derleyici yapılandırabilirsiniz sizin için daha da önemlisi kod biçimlendirme kurallarını tanımlamak ve, projenizde TS dosyaları hakkında bilgileri sağlamak.
Bir kez doğru yapılandırılmış, sadece tsc komutunu çalıştırabilir ve projenizde tüm typescript kodunu derlemek var.
Eğer Değişikliklerimin dosyalarını izlemek olmasını istiyorsanız o zaman sadece tsc komutuna --watch ekleyebilir.
İşte bir örnek tsconfig.json dosyasıdır
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false
},
"include": [
"**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]}
Yukarıdaki örnekte, Projemde (yinelemeli) tüm ts dosyaları içerir. aynı zamanda bir dizi ile bir "dışlama" özelliğini kullanarak dosyaları hariç tutabilirsiniz unutmayın.
Daha fazla bilgi için belgelerine bakın: http://www.typescriptlang.org/docs/handbook/tsconfig-json.html
Teknik olarak burada birkaç seçenek vardır konuşan:
Eğer Sublime Text gibi bir IDE kullanarak ve typescript için MSN eklentisini entegre edilmesiyle: http://blogs.msdn.com/b/interoperability/archive/2012/10/01/sublime-text-vi-emacs-typescript-enabled. aspx Eğer derleme bir yapı sistemi oluşturabilir .tskaynağı için .jsotomatik. Burada bunu nasıl açıklamasıdır: typescript için Sublime Yapı Sistemi nasıl yapılandırılır .
Hedef için kaynak kodunu derlemek için bile tanımlayabilirsiniz .jstasarrufu dosyada dosyanın. : Github üzerinde barındırılan bir yüce paket var https://github.com/alexnj/SublimeOnSaveBuild sadece eklemek gerekir, bunu gerçekleştirmek tsuzantı SublimeOnSaveBuild.sublime-settingsdosyası.
Bir başka olasılık komut satırında her dosyayı derlemek olacaktır. Öyle gibi boşluklarla ayırarak seferde bile birden fazla dosya derlemek edebilirsiniz: tsc foo.ts bar.ts. Bu konuyu kontrol nasıl typescript derleyici birden kaynak dosyaları geçebilir? Ama ben ilk seçenek daha kullanışlı olduğunu düşünüyorum.
Orada bu otomatikleştirmek için homurtuyu kullanarak içine bakın sayısız öğreticiler etrafında, ama burada hızlı bir başlangıç.
bir klasör yapısı için benzer:
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
Sen izlemek ve örnek klasörle kolayca daktilo ile çalışabilir:
npm install
grunt
package.json ile:
{
"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"
}
}
Ve bir er dosyası:
module.exports = function (grunt) {
// Import dependencies
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: { // <--- Run a local server on :8089
options: {
port: 8089,
base: './'
}
}
},
ts: {
lib: { // <-- compile all the files in ../ to PROJECT.js
src: ['../*.ts'],
out: 'PROJECT.js',
options: {
target: 'es3',
sourceMaps: false,
declaration: true,
removeComments: false
}
},
example: { // <--- compile all the files in . to example.js
src: ['*.ts'],
out: 'example.js',
options: {
target: 'es3',
sourceMaps: false,
declaration: false,
removeComments: false
}
}
},
watch: {
lib: { // <-- Watch for changes on the library and rebuild both
files: '../*.ts',
tasks: ['ts:lib', 'ts:example']
},
example: { // <--- Watch for change on example and rebuild
files: ['*.ts', '!*.d.ts'],
tasks: ['ts:example']
}
},
open: { // <--- Launch index.html in browser when you run grunt
dev: {
path: 'http://localhost:8089/index.html'
}
}
});
// Register the default tasks to run when you run grunt
grunt.registerTask('default', ['ts', 'connect', 'open', 'watch']);
}
Tsc derleyici yalnızca komut satırında geçen bu dosyaları izleyecek. Bu olacak değil bir kullanarak dahil dosyaları izlemek /// <sourcefile>referansı. Senin bash ile çalışan varsa, ardışık tüm bulmakta kullanabilir olabilir *.tsdosya ve bunları derlemek:
find . -name "*.ts" | xargs tsc -w
Böyle tüm dosyaları izleyebilirsiniz
tsc *.ts --watch
tsc 0.9.1.1 Bir var görünmüyor izle özelliğini.
Bir kullanabilirsiniz PowerShell Bu karakola yapılan bir gibi komut:
Bugün sizinkiyle aynı sorun için bu Ant MacroDef tasarladık:
<!--
Recursively read a source directory for TypeScript files, generate a compile list in the
format needed by the TypeScript compiler adding every parameters it take.
-->
<macrodef name="TypeScriptCompileDir">
<!-- required attribute -->
<attribute name="src" />
<!-- optional attributes -->
<attribute name="out" default="" />
<attribute name="module" default="" />
<attribute name="comments" default="" />
<attribute name="declarations" default="" />
<attribute name="nolib" default="" />
<attribute name="target" default="" />
<sequential>
<!-- local properties -->
<local name="out.arg"/>
<local name="module.arg"/>
<local name="comments.arg"/>
<local name="declarations.arg"/>
<local name="nolib.arg"/>
<local name="target.arg"/>
<local name="typescript.file.list"/>
<local name="tsc.compile.file"/>
<property name="tsc.compile.file" value="@{src}compile.list" />
<!-- Optional arguments are not written to compile file when attributes not set -->
<condition property="out.arg" value="" else='--out "@{out}"'>
<equals arg1="@{out}" arg2="" />
</condition>
<condition property="module.arg" value="" else="--module @{module}">
<equals arg1="@{module}" arg2="" />
</condition>
<condition property="comments.arg" value="" else="--comments">
<equals arg1="@{comments}" arg2="" />
</condition>
<condition property="declarations.arg" value="" else="--declarations">
<equals arg1="@{declarations}" arg2="" />
</condition>
<condition property="nolib.arg" value="" else="--nolib">
<equals arg1="@{nolib}" arg2="" />
</condition>
<!-- Could have been defaulted to ES3 but let the compiler uses its own default is quite better -->
<condition property="target.arg" value="" else="--target @{target}">
<equals arg1="@{target}" arg2="" />
</condition>
<!-- Recursively read TypeScript source directory and generate a compile list -->
<pathconvert property="typescript.file.list" dirsep="\" pathsep="${line.separator}">
<fileset dir="@{src}">
<include name="**/*.ts" />
</fileset>
<!-- In case regexp doesn't work on your computer, comment <mapper /> and uncomment <regexpmapper /> -->
<mapper type="regexp" from="^(.*)$" to='"\1"' />
<!--regexpmapper from="^(.*)$" to='"\1"' /-->
</pathconvert>
<!-- Write to the file -->
<echo message="Writing tsc command line arguments to : ${tsc.compile.file}" />
<echo file="${tsc.compile.file}" message="${typescript.file.list}${line.separator}${out.arg}${line.separator}${module.arg}${line.separator}${comments.arg}${line.separator}${declarations.arg}${line.separator}${nolib.arg}${line.separator}${target.arg}" append="false" />
<!-- Compile using the generated compile file -->
<echo message="Calling ${typescript.compiler.path} with ${tsc.compile.file}" />
<exec dir="@{src}" executable="${typescript.compiler.path}">
<arg value="@${tsc.compile.file}"/>
</exec>
<!-- Finally delete the compile file -->
<echo message="${tsc.compile.file} deleted" />
<delete file="${tsc.compile.file}" />
</sequential>
</macrodef>
ile inşa dosyasında kullanın:
<!-- Compile a single JavaScript file in the bin dir for release -->
<TypeScriptCompileDir
src="${src-js.dir}"
out="${release-file-path}"
module="amd"
/>
Bu projede kullanılan typescript için PureMVC ben WebStorm kullanarak anda üzerinde çalışıyorum.













