[英]How to integrate Bootstrap into an angular CLI project
I'm relatively new to integrating bootstrap into angular and I started by running the npm i --save bootstrap@3
command which downloaded the required files into the node_modules folder of my angular project.我对将 bootstrap 集成到 angular 比较陌生,我首先运行
npm i --save bootstrap@3
命令,该命令将所需文件下载到我的 angular 项目的 node_modules 文件夹中。
However, when I went to the angular.json file to input the relative path into the "styles" section, I got the following error:但是,当我去 angular.json 文件的“样式”部分输入相对路径时,出现以下错误:
"styles": [
"src/node_modules/boostrap/dist/css"
],
ERROR in multi./src/node_modules/boostrap/dist/css Module not found: Error: Can't resolve 'C:\Users\User\Desktop\ShoppingOnline\client\yoavonlineshop\src\node_modules\boostrap\dist\css' in 'C:\Users\User\Desktop\ShoppingOnline\client\yoavonlineshop'
multi./src/node_modules/boostrap/dist/css 中的错误未找到模块:错误:无法解析 'C:\Users\User\Desktop\ShoppingOnline\client\yoavonlineshop\src\node_modules\boostrap\dist\css'在 'C:\Users\User\Desktop\ShoppingOnline\client\yoavonlineshop'
I made sure to use backslash.我确保使用反斜杠。 The angular node modules folder is outside the src folder.
angular 节点模块文件夹位于 src 文件夹之外。 Do I need to go up one tier?
我需要上一层 go 吗? ../?
../? The output path is:
output路径为:
"outputPath": "dist/YoavOnlineShop",
edit: Thank you guys, it doesn't produce an error now.编辑:谢谢你们,它现在不会产生错误。 However, the styles of bootstrap aren't being applied.
但是,未应用引导程序的 styles。 Do I need to add anything into the app.module or the specific components?
我是否需要在 app.module 或特定组件中添加任何内容?
Before integrating bootstrap like above, I used CDN and it worked fine but now I think I broke it.在像上面那样集成 bootstrap 之前,我使用了 CDN,它运行良好,但现在我想我破坏了它。
change the path like this像这样改变路径
"styles": [
"src/styles.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/font-awesome/css/font-awesome.css",
"node_modules/toastr/build/toastr.min.css"
],
why node_modules/bootstrap not src/node_modules/bootstrap because the angular path from current angular.json file is nodue_models which CLI will take care.为什么 node_modules/bootstrap 不是 src/node_modules/bootstrap 因为当前 angular.json 文件中的角度路径是 nodue_models,CLI 会处理它。 And remember dist path formation and minimization is also taken care by cli not your code explicitly.
并记住 dist 路径的形成和最小化也由 cli 处理,而不是您的代码。
Try this:尝试这个:
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
]
It is outside the src folder but inside the angular project, so you can access it as shown above.它在 src 文件夹之外,但在 angular 项目内,因此您可以如上所示访问它。
Check this guy here if you want to load a specific version locally and on how to use it.如果您想在本地加载特定版本以及如何使用它,请在此处查看此人。
to install bootstrap jquery popper.js and font-awesome we need to tape this request要安装 bootstrap jquery popper.js 和 font-awesome 我们需要记录这个请求
npm install bootstrap jquery popper.js and font-awesome
and in angular.json we put the relative path of all our elements在 angular.json 中,我们放置所有元素的相对路径
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/salam-angular",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css",
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"./node_modules/font-awesome/css/font-awesome.min.css"
],
"scripts": [
"./node_modules/bootstrap/dist/js/bootstrap.min.js",
"./node_modules/jquery/dist/jquery.min.js",
"./node_modules/popper.js/dist/popper.min.js"
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.