简体   繁体   English

如何在jhipster的角度应用程序中包含css和js文件等资源文件?

[英]How to include resource files like css and js files in jhipster's angular app?

I have been trying to include resource files in my jhipster angular 2 app but stuck in the issue for 3 days. 我一直试图在我的jhipster angular 2应用程序中包含资源文件,但在问题中停留了3天。 So far i have found, angular 2 is webpack based configured in this app. 到目前为止,我发现,角度2是基于webpack在此应用程序中配置。 i tried implementing through angular-cli.json and vendor.ts too. 我尝试通过angular-cli.json和vendor.ts实现。 i even tried to include the files in index.html file. 我甚至试图将文件包含在index.html文件中。 unfortunately, there's no any change in my dumb app. 不幸的是,我的愚蠢应用程序没有任何变化。 Responses are appreciable. 回应很明显。 Thanks! 谢谢!

Assuming you are running a working setup and launched hot reloader using yarn start , there are several use cases to include "assets", as CSS/JS 假设您正在运行工作设置并使用yarn start启动热重新加载器,有几个用例包含“资产”,如CSS / JS

a global stylesheet 全局样式表

All global stylesheets can be placed in the file global.(s)css and changes immediately trigger a hot reload. 所有全局样式表都可以放在global.(s)css文件中global.(s)css和更改会立即触发热重载。

a component stylesheet 组件样式表

You might want to give a certain angular component a stylesheet, which is encapsulated to that component. 您可能希望为某个角度组件提供样式表,该样式表封装在该组件中。 Then you add a some.component.css (or scss) next to some.component.ts and embed it this way: 然后添加一个some.component.css下一个(或SCSS),以some.component.ts和嵌入这样说:

@Component({
    selector: 'jhi-some-component',
    templateUrl: './some.component.html',
    styleUrls: [
        'some.component.scss'
    ]
})
export class SomeComponent
//...

as global styles, component styles trigger a hot reload on change. 作为全局样式,组件样式会在更改时触发热重载。

vendor stylesheets 供应商样式表

you can place them into vendor.(s)css . 你可以将它们放入vendor.(s)css To make changes to that file take effect, a restart of the yarn start is needed 要使对该文件的更改生效,需要重新启动yarn start

assets in general 资产一般

Webpack tries to resolve all mentioned assets relatively to their files to include them. Webpack尝试相对于其文件解析所有提到的资产以包含它们。 That way you can use any asset you want. 这样你就可以使用你想要的任何资产。 If Webpack will have problems to resolve any asset, it will let you know that. 如果Webpack在解决任何资产时遇到问题,它会告诉您。

You mentioned also JS, but I don't get the sense of using JS resource, as Typescript is used in the angular client. 你也提到了JS,但是我没有理解使用JS资源,因为在角客户端中使用了Typescript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM