2017-10-19 61 views
0

我試圖在IIS上託管我的Angular應用程序,並閱讀了很多以使用cli命令ng構建。這給出了錯誤未找到模塊。當我更改組件中的templateUrl時,錯誤消失了,但是我的應用程序失敗。構建Angular應用程序並在IIS上發佈

templateUrl: 'app/account/login.component.html'   (not building) 
templateUrl: 'login.component.html'   (building, but app fails with unknown path) 

一開始我並沒有.angular-cli.json文件在我的應用程序,所以我只是手動添加一個。

{ 
"$schema": "./node_modules/@angular/cli/lib/config/schema.json", 
"project": { 
"name": "buildingprojects" 
}, 
"apps": [ 
{ 
    "root": "src", 
    "outDir": "dist", 
    "assets": [ 
    "assets", 
    "favicon.ico" 
    ], 
    "index": "index.html", 
    "main": "main.ts", 
    "polyfills": "polyfills.ts", 
    "test": "test.ts", 
    "tsconfig": "tsconfig.json", 
    "testTsconfig": "tsconfig.json", 
    "prefix": "app", 
    "styles": [ 
    "styles.css" 
    ], 
    "scripts": [], 
    "environmentSource": "environments/environment.ts", 
    "environments": { 
    "dev": "environments/environment.ts", 
    "prod": "environments/environment.prod.ts" 
    } 
} 
], 
"e2e": { 
"protractor": { 
    "config": "./protractor.conf.js" 
} 
}, 
"lint": [ 
{ 
    "project": "src/tsconfig.app.json", 
    "exclude": "**/node_modules/**" 
}, 
{ 
    "project": "src/tsconfig.spec.json", 
    "exclude": "**/node_modules/**" 
}, 
{ 
    "project": "e2e/tsconfig.e2e.json", 
    "exclude": "**/node_modules/**" 
} 
], 
"test": { 
"karma": { 
    "config": "./karma.conf.js" 
} 
}, 
"defaults": { 
"styleExt": "css", 
"component": {} 
} 
} 

的package.json

{ 
"name": "buildingprojects", 
"version": "1.0.0", 
"author": "Nick Ausloos", 
"description": "Building Projects", 
"main": "src/index.html", 
"scripts": { 
"start": "webpack --progress --watch --config src/webpack.config.js", 
"dev": "lite-server -c bs-config.json", 
"test": "echo \"Error: no test specified\" && exit 1" 
}, 
"license": "UNLICENSED", 
"devDependencies": { 
"@angular/animations": "^4.4.4", 
"@angular/cdk": "^2.0.0-beta.11", 
"@angular/cli": "^1.4.8", 
"@angular/common": "^4.4.4", 
"@angular/compiler": "^4.4.4", 
"@angular/compiler-cli": "^4.4.6", 
"@angular/core": "^4.4.4", 
"@angular/forms": "^4.4.4", 
"@angular/http": "^4.4.4", 
"@angular/material": "^2.0.0-beta.11", 
"@angular/platform-browser": "^4.4.4", 
"@angular/platform-browser-dynamic": "^4.4.4", 
"@angular/router": "^4.4.4", 
"@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5", 
"@types/adal": "^1.0.29", 
"@types/core-js": "^0.9.43", 
"@types/jquery": "^3.2.12", 
"@types/node": "^8.0.31", 
"adal-angular": "^1.0.15", 
"angular2-template-loader": "^0.6.2", 
"awesome-typescript-loader": "^3.2.3", 
"babel-core": "^6.26.0", 
"babel-helpers": "^6.24.1", 
"babel-loader": "^7.1.2", 
"babel-preset-env": "^1.6.0", 
"bootstrap": "^3.3.7", 
"bootstrap-sass": "^3.3.7", 
"concurrently": "^3.5.0", 
"core-js": "^2.5.1", 
"css-loader": "^0.28.7", 
"expose-loader": "^0.7.3", 
"extract-text-webpack-plugin": "^3.0.0", 
"file-loader": "^1.1.4", 
"free-jqgrid": "^4.14.1", 
"html-loader": "^0.5.1", 
"html-webpack-plugin": "^2.30.1", 
"jquery": "^3.2.1", 
"jsdo": "^4.3.12", 
"lite-server": "^2.3.0", 
"loader-utils": "^1.1.0", 
"node-sass": "^4.5.3", 
"postcss": "^6.0.12", 
"postcss-cssnext": "^3.0.2", 
"postcss-loader": "^2.0.6", 
"reflect-metadata": "^0.1.10", 
"rxjs": "^5.4.3", 
"sass-loader": "^6.0.6", 
"source-map-loader": "^0.2.2", 
"style-loader": "^0.18.2", 
"tslint": "^5.7.0", 
"typescript": "^2.5.3", 
"url-loader": "^0.5.9", 
"webpack": "^3.6.0", 
"webpack-dev-server": "^2.9.1", 
"webpack-merge": "^4.1.0", 
"zone.js": "^0.8.17" 
}, 
"dependencies": { 
"@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5", 
"adal-angular": "^1.0.15", 
"expose-loader": "^0.7.3" 
} 
} 

回答

0

我瘦應按照此GUID第一https://github.com/angular/angular-cli/wiki/stories-moving-into-the-cli它展示瞭如何進入角CLI。

JHON爸爸發表本指南說明了如何部署到蔚藍,是IIS https://johnpapa.net/deploy-angular-to-azure-vsts-angular-cli/

+0

沒有解決方案!在第一個轉換爲cli的指南結束後出現相同的錯誤。發佈到IIS與Azure不同。 – NiAu

+0

您必須從其所在的目錄angular-cli.json – Eliseo

+0

檢查我關於tsconfig和testTsconfig的回答 – Eliseo

0

你可以嘗試在您的index.html變「基地」標籤

<base href="./"/> 
+0

沒有解決方案,這個答案!繼續收到相同的錯誤。 – NiAu

0

你在同angular.json

"tsconfig": "tsconfig.json", 
"testTsconfig": "tsconfig.json", 

也許吧?

"tsconfig": "tsconfig.app.json", 
"testTsconfig": "tsconfig.spec.json", 
0

您寫道:

在開始的時候,我在我的應用程序沒有.angular-cli.json文件,所以我只是手動添加一個。

看起來您並未使用ng new創建應用程序。但你正在嘗試使用ng build。我建議你使用ng new從零開始創建一個Angular CLI應用程序,測試它的部署到IIS,而不是將自定義組件複製到它。

0

我解決了這個問題,只是用文件名替換路徑。這種方式構建成功,但這不是將其發佈到IIS的解決方案。使用webpack捆綁器,這些文件只需要被複制到IIS文件夾。唯一的問題就是組件的路由。

相關問題