2016-12-04 66 views
-1

我有一個小的Angular 2.0應用程序。它在我的機器上運行良好;-)它使用SystemJS,我爲它建立了一個gulp版本。問題是,當我將它部署到一個子目錄時,它將查看節點模塊的根目錄。它應該看:帶角度的路徑問題2,SystemJS,node_modules

example.com/myapp/node_modules 

但看着

example.com/node_modules 

代替。

tsconfig.json

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node",? 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": true, 
    "suppressImplicitAnyIndexErrors": true 
    } 
} 

systemjs.config.js

(function (global) { 
    System.config({ 
    paths: { 
     // paths serve as alias 
     'npm:': 'node_modules/' 
    }, 
    // map tells the System loader where to look for things 
    map: { 
     // our app is within the app folder 
     app: 'app', 

     // angular bundles 
     '@angular/core': 'npm:@angular/core/bundles/core.umd.js', 
     '@angular/common': 'npm:@angular/common/bundles/common.umd.js', 
     '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', 
     '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', 
     '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', 
     '@angular/http': 'npm:@angular/http/bundles/http.umd.js', 
     '@angular/router': 'npm:@angular/router/bundles/router.umd.js', 
     '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', 

     // other libraries 
     'rxjs': 'npm:rxjs' 
    }, 
    // packages tells the System loader how to load when no filename and/or  no extension 
    packages: { 
     app: { 
     main: './main.js', 
     defaultExtension: 'js' 
     }, 
     rxjs: { 
     defaultExtension: 'js' 
     } 
    } 
    }); 
})(this); 

gulpfile.js

const gulp = require('gulp'); 
const del = require('del'); 
const typescript = require('gulp-typescript'); 
const tscConfig = require('./tsconfig.json'); 
const sourcemaps = require('gulp-sourcemaps'); 

// clean the contents of the distribution directory 
gulp.task('clean', function() { 
    return del('dist/**/*'); 
}); 

// TypeScript compile 
gulp.task('compile', ['clean', 'copy:libs', 'copy:assets'], function() { 
    return gulp 
     .src('app/**/*.ts') 
     .pipe(sourcemaps.init()) 
     .pipe(typescript(tscConfig.compilerOptions)) 
     .pipe(sourcemaps.write('.')) 
     .pipe(gulp.dest('dist/app')); 
}); 

// copy dependencies 
gulp.task('copy:libs', ['clean'], function() { 
    return gulp.src([ 
     'node_modules/angular2/bundles/angular2-polyfills.js', 
     'node_modules/systemjs/dist/system.src.js', 
     'node_modules/rxjs/bundles/Rx.js', 
     'node_modules/angular2/bundles/angular2.dev.js', 
     'node_modules/angular2/bundles/router.dev.js', 
     'node_modules/**/*.js', 
     'node_modules/**/*.css' 
    ]) 
     .pipe(gulp.dest('dist/node_modules')) 
}); 

// copy static assets - i.e. non TypeScript compiled source 
gulp.task('copy:assets', ['clean'], function() { 
    return gulp.src(['app/**/*', 'index.html', 'systemjs.config.js',   '!app/**/*.ts'], { base : './' }) 
     .pipe(gulp.dest('dist')) 
}); 

gulp.task('build', ['compile']); 
gulp.task('default', ['build']); 

回答

0

你應該PU t sourceRoot="myapp/"添加到tsconfig.json。此選項

指定調試器應找到TypeScript文件 而不是源位置的位置。如果源設置爲 ,則在運行時位於與設計時不同的位置。 指定的位置將被嵌入到sourceMap中,以指導 調試器將源文件放在哪裏。