Angular2 + webpack 不部署 robots.txt
Angular2 + webpack do not deploy robots.txt
我正在使用 Angular2@2.1.2 创建一个网站。
我正在使用具有默认设置的 Webpack(作为依赖项)。
这是我的package.json
"dependencies": {
"@angular/common": "2.1.2",
"@angular/compiler": "2.1.2",
"@angular/core": "2.1.2",
"@angular/forms": "2.1.2",
"@angular/http": "2.1.2",
"@angular/platform-browser": "2.1.2",
"@angular/platform-browser-dynamic": "2.1.2",
"@angular/platform-server": "2.1.2",
"@angular/router": "3.1.2",
"@ngrx/core": "1.2.0",
"@ngrx/effects": "2.0.0",
"@ngrx/store": "2.2.1",
"angular2-toaster": "^1.0.1",
"awesome-typescript-loader": "2.2.1",
"bootstrap": "3.3.7",
"bootstrap-select": "1.11.2",
"eonasdan-bootstrap-datetimepicker": "4.17.42",
"es5-shim": "4.5.9",
"intl": "1.2.5",
"jquery": "3.1.0",
"moment": "2.15.1",
"ng2-modal": "0.0.21",
"ng2-pagination": "^0.4.1",
"ngrx-store-logger": "^0.1.7",
"npm": "3.9.3",
"reflect-metadata": "0.1.8",
"rxjs": "5.0.0-beta.12",
"ts-helpers": "1.1.1",
"zone.js": "0.6.25"
},
"devDependencies": {
"@types/jasmine": "2.2.34",
"angular-cli": "1.0.0-beta.19-3",
"codelyzer": "~0.0.26",
"core-js": "2.4.1",
"jasmine-core": "2.5.0",
"jasmine-spec-reporter": "2.7.0",
"karma": "1.3.0",
"karma-chrome-launcher": "2.0.0",
"karma-coverage": "1.1.1",
"karma-jasmine": "1.0.2",
"karma-phantomjs-launcher": "1.0.2",
"karma-remap-istanbul": "0.2.1",
"karma-verbose-reporter": "0.0.3",
"node-sass": "3.10.3",
"protractor": "4.0.5",
"ts-node": "1.3.0",
"tslint": "3.15.1",
"typescript": "2.0.2"
}
我在 assets/ 目录中添加了一个 robots.txt 文件。我在想构建器(npm build)识别这个文件并将它放在应用程序的根目录下,但它没有,它仍然在 assets 目录中。
我错过了什么吗?
谢谢。
我找到了这个问题的解决方案:https://github.com/angular/angular-cli/issues/1942
robots.txt在src/目录
修改angular-cli.json
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": ["assets", "robots.txt"],
....
使用 assets 数组声明要放置在 dist/ 根目录中的文件
我用 Angular6 完成了这项工作。
将您的 robots.txt 放在与 favicon.ico 相同的文件夹中的 src 文件夹中。
在您的 angular.json 文件中
"assets": [
"src/favicon.ico",
"src/assets",
"src/robots.txt"
],
你可能需要再次 ng serve,然后指向 http://localhost:4200/robots.txt
我希望我的 robots.txt
位于我的 src/assets
文件夹中,而不仅仅是 src
。我发现在 assets
数组中添加到我的 angular.json
中的以下内容起到了作用:
"assets": [
"src/favicon.ico",
"src/assets",
{
"glob": "robots.txt",
"input": "src/assets",
"output": "./"
}
],
使用 Angular Universal/SSR 在 Angular 10 中工作。
我正在使用 Angular2@2.1.2 创建一个网站。 我正在使用具有默认设置的 Webpack(作为依赖项)。
这是我的package.json
"dependencies": {
"@angular/common": "2.1.2",
"@angular/compiler": "2.1.2",
"@angular/core": "2.1.2",
"@angular/forms": "2.1.2",
"@angular/http": "2.1.2",
"@angular/platform-browser": "2.1.2",
"@angular/platform-browser-dynamic": "2.1.2",
"@angular/platform-server": "2.1.2",
"@angular/router": "3.1.2",
"@ngrx/core": "1.2.0",
"@ngrx/effects": "2.0.0",
"@ngrx/store": "2.2.1",
"angular2-toaster": "^1.0.1",
"awesome-typescript-loader": "2.2.1",
"bootstrap": "3.3.7",
"bootstrap-select": "1.11.2",
"eonasdan-bootstrap-datetimepicker": "4.17.42",
"es5-shim": "4.5.9",
"intl": "1.2.5",
"jquery": "3.1.0",
"moment": "2.15.1",
"ng2-modal": "0.0.21",
"ng2-pagination": "^0.4.1",
"ngrx-store-logger": "^0.1.7",
"npm": "3.9.3",
"reflect-metadata": "0.1.8",
"rxjs": "5.0.0-beta.12",
"ts-helpers": "1.1.1",
"zone.js": "0.6.25"
},
"devDependencies": {
"@types/jasmine": "2.2.34",
"angular-cli": "1.0.0-beta.19-3",
"codelyzer": "~0.0.26",
"core-js": "2.4.1",
"jasmine-core": "2.5.0",
"jasmine-spec-reporter": "2.7.0",
"karma": "1.3.0",
"karma-chrome-launcher": "2.0.0",
"karma-coverage": "1.1.1",
"karma-jasmine": "1.0.2",
"karma-phantomjs-launcher": "1.0.2",
"karma-remap-istanbul": "0.2.1",
"karma-verbose-reporter": "0.0.3",
"node-sass": "3.10.3",
"protractor": "4.0.5",
"ts-node": "1.3.0",
"tslint": "3.15.1",
"typescript": "2.0.2"
}
我在 assets/ 目录中添加了一个 robots.txt 文件。我在想构建器(npm build)识别这个文件并将它放在应用程序的根目录下,但它没有,它仍然在 assets 目录中。
我错过了什么吗?
谢谢。
我找到了这个问题的解决方案:https://github.com/angular/angular-cli/issues/1942
robots.txt在src/目录
修改angular-cli.json
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": ["assets", "robots.txt"],
....
使用 assets 数组声明要放置在 dist/ 根目录中的文件
我用 Angular6 完成了这项工作。
将您的 robots.txt 放在与 favicon.ico 相同的文件夹中的 src 文件夹中。
在您的 angular.json 文件中
"assets": [
"src/favicon.ico",
"src/assets",
"src/robots.txt"
],
你可能需要再次 ng serve,然后指向 http://localhost:4200/robots.txt
我希望我的 robots.txt
位于我的 src/assets
文件夹中,而不仅仅是 src
。我发现在 assets
数组中添加到我的 angular.json
中的以下内容起到了作用:
"assets": [
"src/favicon.ico",
"src/assets",
{
"glob": "robots.txt",
"input": "src/assets",
"output": "./"
}
],
使用 Angular Universal/SSR 在 Angular 10 中工作。