2016-11-22 25 views
1

每次運行angular2項目時,很多文件都與unpkg.com/plugin-typescript/lib/plugin.js中的'ts'庫一起加載。我想擺脫從另一臺服務器的文件加載。我已經在本地安裝了,但是當我將本地路徑設置爲其他地址時,出現錯誤「404(Not Found)」的狀態爲: 從Angular2的本地主機運行plugin-typescript庫

無法加載資源:服務器響應狀態爲404 (未找到) http://localhost:6240/node_modules/plugin-typescript/lib/logger

未能加載資源:服務器與404狀態(未找到)作出迴應 http://localhost:6240/node_modules/plugin-typescript/lib/factory

未能加載資源:服務器用的狀態響應404(未找到) http://localhost:6240/node_modules/plugin-typescript/lib/format-errors

未能加載資源:服務器用的404(未找到)狀態回答 http://localhost:6240/node_modules/plugin-typescript/lib/utils

未能加載資源:18錯誤:服務器404(未找到) index.html的一個狀態響應:錯誤:錯誤XHR(404未找到)裝載http://localhost:6240/node_modules/plugin-typescript/lib/logger(...)

我systemjs.config.js是:

(函數(全球){

System.config({

transpiler: 'ts', 

typescriptOptions: { 

    tsconfig: true 

}, 

meta: { 
    'typescript': { 
    "exports": "ts" 
    } 
}, 
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', 
    'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api', 
    'ts':       'npm:plugin-typescript/lib/plugin.js', 
    //'ts':      'https://unpkg.com/plugin-typescript/lib/plugin.js', 
    'typescript':     'npm:typescript/lib/typescript.js' 

}, 
// packages tells the System loader how to load when no filename and/or no extension 
packages: { 
    app: { 
    main: './main.ts', 
    defaultExtension: 'ts' 
    }, 
    rxjs: { 
    defaultExtension: 'js' 
    }, 
    'angular2-in-memory-web-api': { 
    main: './index.js', 
    defaultExtension: 'js' 
    } 
} 

}); })(this);

而且我的package.json

{

"name": "angular2-quickstart", 

"version": "1.0.0", 

"scripts": { 

    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ", 

    "lite": "lite-server", 

    "postinstall": "typings install", 

    "tsc": "tsc", 

    "tsc:w": "tsc -w", 

    "typings": "typings" 

}, 

"license": "ISC", 

"dependencies": { 

    "@angular/common": "2.0.0-rc.6", 

    "@angular/compiler": "2.0.0-rc.6", 

    "@angular/compiler-cli": "0.6.0", 

    "@angular/core": "2.0.0-rc.6", 

    "@angular/forms": "2.0.0-rc.6", 

    "@angular/http": "2.0.0-rc.6", 

    "@angular/platform-browser": "2.0.0-rc.6", 

    "@angular/platform-browser-dynamic": "2.0.0-rc.6", 

    "@angular/router": "3.0.0-rc.2", 

    "@angular/upgrade": "2.0.0-rc.6", 

    "core-js": "^2.4.1", 

    "reflect-metadata": "^0.1.3", 

    "rxjs": "5.0.0-beta.11", 

    "systemjs": "0.19.27", 

    "zone.js": "^0.6.17", 

    "angular2-in-memory-web-api": "0.0.18", 

    "bootstrap": "^3.3.6" 

}, 

"devDependencies": { 

    "concurrently": "^2.2.0", 

    "lite-server": "^2.2.2", 

    "typescript": "^1.8.10", 

    "typings": "^1.3.2" 

} 

}

由於我是新來angular2和NPM而言,我的想法來解決這個問題。任何建議或解決方案都非常值得讚賞。在此先感謝

回答

0

我在IIS中託管我的Angular2應用程序,所以我添加了一個URL重寫到Web.Config,它將URL「/ plugin-typescript/lib/logger/logger」重定向到「/ plugin-typescript/lib/logger/logger .js文件「:

<system.webServer> 
    <rewrite> 
     <rules> 
     <rule name="rewrite directories to .js" stopProcessing="true"> 
      <match url="(.*[^/])$" /> 
      <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
      <add input="{REQUEST_FILENAME}" pattern="(.*?)\.[a-zA-Z]{1,4}$" negate="true" /> 
      </conditions> 
      <action type="Rewrite" url="{R:1}.js" /> 
     </rule> 
     </rules> 
    </rewrite> 
    </system.webServer> 

史蒂夫

0

這是因爲所有這些庫位於/ node_modules /文件夾中,並且此文件夾無法訪問您的瀏覽器。 將它們複製到應用程序的靜態內容所在的文件夾(在我的情況下,它是wwwroot/js)。