如何在角度4上设置公共路径 [英] How to set the public path on angular 4
问题描述
因此,我需要配置应用程序的公用文件夹,换句话说, 我希望资产指向生成的索引文件上的我自己的路径 像src ="mypublicpath/assets/app.js"
So I need to configure the public folder of my application, in other words, I want the assets to point to my own path on the generated index file like src="mypublicpath/assets/app.js"
我真的确定这是需要在angular-cli.json配置上设置的值.
I'm really sure this is a value that needs to be set on the angular-cli.json configuration.
这是我的文件
{
"project": {
"version": "1.0.0-beta.28.3",
"name": "ng-app-manager"
},
"apps": [
{
"root": "src",
"outDir": "../bundles/ng-app-manager",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"files": "src/**/*.ts",
"project": "src/tsconfig.json"
},
{
"files": "e2e/**/*.ts",
"project": "e2e/tsconfig.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
我只需要相当于webpacks"publicPath"
I just need the equivalent to webpacks "publicPath"
推荐答案
You're probably looking for the deployUrl
option in Angular CLI. Your angular-cli.json
would look like this.
{
"project": {
"version": "1.0.0-beta.28.3",
"name": "ng-app-manager"
},
"apps": [
{
"root": "src",
"outDir": "..\/bundles\/ng-app-manager",
"deployUrl": "http://my.cdn.host.com/assets",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [
],
"environments": {
"source": "environments\/environment.ts",
"dev": "environments\/environment.ts",
"prod": "environments\/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": ".\/protractor.conf.js"
}
},
"lint": [
{
"files": "src\/**\/*.ts",
"project": "src\/tsconfig.json"
},
{
"files": "e2e\/**\/*.ts",
"project": "e2e\/tsconfig.json"
}
],
"test": {
"karma": {
"config": ".\/karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
运行ng build
然后将在dist
文件夹中使用http://my.cdn.host.com/assets
自动为资源引用添加前缀.例如,对app.js
的引用将进入http://my.cdn.host.com/assets/app.js
.
Running ng build
will then automatically prefix resource references in the dist
folder, with http://my.cdn.host.com/assets
. For example, the reference for app.js
will into http://my.cdn.host.com/assets/app.js
.
这篇关于如何在角度4上设置公共路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!