gpt4 book ai didi

angular - 如何在 Angular 4 上设置公共(public)路径

转载 作者:太空狗 更新时间:2023-10-29 18:20:22 25 4
gpt4 key购买 nike

所以我需要配置我的应用程序的公用文件夹,换句话说,我希望 Assets 在生成的索引文件上指向我自己的路径像 src="mypublicpath/assets/app.js"

我真的确定这是一个需要在 angular-cli.json 配置上设置的值。

这是我的文件

{
"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”

最佳答案

您可能正在寻找 deployUrl Angular CLI 中的选项.你的angular-cli.json看起来像这样。

{
"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 .

关于angular - 如何在 Angular 4 上设置公共(public)路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43497322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com