[英]Add bootstrap-toggle to JHipster (Angular 2+)
I would like to add a bootstrap add-on, namely Bootstrap Toggle to a JHipster Project. 我想添加一个Bootstrap附加组件,即Bootstrap Toggle到JHipster Project。 The project consists of a
.css
and .js
file and requires jquery. 该项目包含一个
.css
和.js
文件,并且需要使用jquery。
Simply adding this to index.html
works fine but feels hacky. 只需将其添加到
index.html
正常工作,但感觉很笨拙。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
I would like to take advantage of yarn and webpack. 我想利用yarn和webpack的优势。 I tried adding a
vendor.css
to the content folder which imports the toggle css file, but that didn't seem to do anything: 我尝试将
vendor.css
添加到内容文件夹中,该文件夹导入了切换css文件,但是似乎没有任何作用:
@import 'node_modules/boostrap-toggle/css/bootstrap-toggle.css';
How can I add Bootstrap Toggle (or similar libraries) from my node_modules
folder to the application? 如何从我的
node_modules
文件夹向应用程序添加Bootstrap Toggle(或类似的库)?
It is actually far simpler than both suggestions. 实际上,这比两个建议都简单得多。 All you need to do is mention the required resources in the
vendor.ts
. 您需要做的只是在
vendor.ts
提到所需的资源。 That includes javascript. 包括javascript。
import '../content/scss/vendor.scss';
import '../content/css/vendor.css';
import 'path to js'
The vendor.css
is similar to vendor.scss
, but the import path is a bit different. 该
vendor.css
类似于vendor.scss
,但进口路径是一个有点不同。 Tilde denotes the node_modules
folder, as far as I understand. 据我了解,Tilde表示
node_modules
文件夹。
@import "~github-markdown-css/github-markdown.css";
And that is all. 仅此而已。 No meddling with
.angular-cli.json
or anything required. 无需干预
.angular-cli.json
或任何必需的内容。
In angular 2+, If you create project using @angular/cli
, there is .angular-cli.json
file. 在angular 2+中,如果使用
@angular/cli
创建项目,则存在.angular-cli.json
文件。
In json file, within apps
you can add styles
and scripts
you want to load from node_modules
folder. 在json文件中,您可以在
apps
内添加要从node_modules
文件夹中加载的styles
和scripts
。
For example, in my project to add I have added font-awesome.scss
, bootstrap.scss
and scripts like jquery tether and bootstrap
like this. 例如,在要添加的项目中,我添加了
font-awesome.scss
, bootstrap.scss
以及诸如jquery tether and bootstrap
类的脚本。
"apps": [
{
"styles": [
"../node_modules/font-awesome/scss/font-awesome.scss",
"../node_modules/bootstrap/scss/bootstrap.scss",
"styles.scss"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/tether/dist/js/tether.js",
"../node_modules/bootstrap/dist/js/bootstrap.js"
],
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.