【问题标题】:Angular2/4: Include third party scripts and styles in .net frameworkAngular2/4:在 .net 框架中包含第三方脚本和样式
【发布时间】:2017-11-10 15:26:36
【问题描述】:

我正在 webpack 附带的 .net 框架中构建一个新的 angular 4 应用程序。以前当我使用 angular cli 时,我得到了 angular-cli.json,我可以在其中提供第三方脚本和 css。在这种情况下,我没有 angular-cli.json。我的项目结构如下。

我的 webpack 如下所示

当我尝试将第三方 css 文件添加到 nonTreeShakableModules 时,它不起作用。

应用程序生成的我的 index.cshtml 和 _layout.cshtml。

我的索引.cshtml

@{
    ViewData["Title"] = "Home Page";
}

<app>Loading...</app>

@*asp-prerender-module="ClientApp/dist/main-server"*@

<script src="~/dist/vendor.js" asp-append-version="true"></script>
@section scripts {
    <script src="~/dist/main-client.js" asp-append-version="true"></script>
}

我的布局.cshtml

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - CareTeamPortal</title>
    <base href="~/" />

    <link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
</head>
<body>
    @RenderBody()

    @RenderSection("scripts", required: false)
</body>
</html>

【问题讨论】:

    标签: angular angular2-template


    【解决方案1】:

    我假设应用程序在index.html 中有一个样式表style.css

    为各个样式表添加导入语句,如下所示

    @import url('.................'); // specify the path 
    

    【讨论】:

    • 用应用程序生成的 index.cshtml 和 _layout.cshtml 更新了问题。
    • 您要动态添加吗?
    • No.. 我想添加以下样式..
    • 我应该在哪里进行导入?
    • 为了清楚起见,我创建了一个新的 ASP.NET Core Web 应用程序项目并选择了角度模板。一切运行顺利,但我无法添加第三方 css。
    猜你喜欢
    • 2016-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    • 2017-08-11
    • 1970-01-01
    相关资源
    最近更新 更多