我的應用程序的結構,像這樣:Angularjs 2打字稿進口問題(systemjs?)
app
- assets
- src
-- autogenerated
-- components
---- app
---- tabs
的「自動生成」文件夾中使用從組件文件夾相同的目錄結構包含打字稿產生編譯JavaScript文件。我使用gulp-tsc來創建它。 (我最終將其重命名爲「build」)
應用程序和選項卡是組件...應用程序是頂級組件。
在app.ts(在應用/組件/應用)是:
import {Component, bootstrap} from 'angular2/angular2';
import {Tabs} from '../Tabs/tabs';
@Component({
selector: 'my-app',
templateUrl: 'src/components/app/app.html',
directives: [Tabs]
})
class AppComponent { }
bootstrap(AppComponent);
當這種編譯,生成的js文件具有這樣的:
var tabs_1 = require('../Tabs/tabs');
不解決,並且導致一個404,因爲它被瀏覽器加載時沒有.js擴展名。
編輯...剛剛意識到「require」來自nodejs,而不是systemjs ......仍然不知道如何繼續。
**編輯2 **吞氣任務:
gulp.task('compile', function() {
// compile sass to css
gulp.src('./app/assets/sass/*.scss')
.pipe(sass.sync({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./app/assets/css'));
// compile typescript
// this ignores tsconfig.json, but ideally configuration in both places should match
gulp.src(['./app/src/**/*.ts'])
.pipe(typescript({ target: "ES5",
experimentalDecorators: true,
sourceMap: true,
emitDecoratorMetadata: true }))
.pipe(gulp.dest('./app/src/autogenerated/'));
});
吞氣的任務不應該使用tsconfig.json來......我添加它來消除視覺誤差Studio代碼....但這裏的tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
}
index.html的代碼什麼:
<html>
<head>
<title>Angular 2 QuickStart</title>
<script src="../../node_modules/systemjs/dist/system.src.js"></script>
<script src="../../node_modules/angular2/bundles/angular2.dev.js"></script>
<script>
System.config({
packages: {'app': {
defaultExtension: 'js'}
}
});
System.import('../src/components/app/app.js');
</script>
</head>
<body>
<my-app>Loading... please wait</my-app>
</body>
</html>
能告訴你更多的配置? Gulp文件爲例子? –
我已經添加了gulp任務。它使用gulp-tsc包。 –