在块中设置路径ASP.NET CORE MVC 2.2 WEBPACK 4 HtmlWebpackPlugin

时间:2019-02-12 05:13:34

标签: c# asp.net asp.net-mvc webpack

ASP.NET CORE 2.2 WEBPACK 4 HtmlWebpackPlugin

如何设置正确的路径?

problem src="../../wwwroot/public
to src="./public

webpack.config.js

        new HtmlWebpackPlugin({
            inject: false,
            hash: true,
            template: './Views/_BundledScriptsTemplate.cshtml',
            filename: '../../Views/Shared/_BundledScripts.cshtml'
        }),

\ Views_BundledScriptsTemplate.cshtml

<% for (var item in htmlWebpackPlugin.files.chunks) { %><script src="<%= htmlWebpackPlugin.files.chunks[item].entry %>"></script><% } %>
<% for (var css in htmlWebpackPlugin.files.css) { %><link href="<%= htmlWebpackPlugin.files.css[css] %>" rel="stylesheet"><% } %>

\ Views \ Shared_BundledScripts.cshtml

<script src="../../wwwroot/public/js/app.production.bundle.92a519909b5dceede661.js?e345faf977c3f42e2bc1"></script>
<link href="../../wwwroot/public/css/app.production.bundle.95b81d019e75eb4d5400.css?e345faf977c3f42e2bc1" rel="stylesheet">

1 个答案:

答案 0 :(得分:0)

制造kostil

_BundledScriptsTemplate.cshtml

@{
    StringBuilder jsUrl = new StringBuilder();
    StringBuilder cssUrl = new StringBuilder();
}

<!--CSS-->
<% for (var css in htmlWebpackPlugin.files.css) { %>
@{
    cssUrl = new StringBuilder("<%= htmlWebpackPlugin.files.css[css] %>");
    cssUrl.Replace("../../wwwroot", ".");
    <link href=@cssUrl rel="stylesheet">
}
<% } %>
<!--JS-->
<% for (var item in htmlWebpackPlugin.files.chunks) { %>
@{
    jsUrl = new StringBuilder("<%= htmlWebpackPlugin.files.chunks[item].entry %>");
    jsUrl.Replace("../../wwwroot", ".");
    <script src=@jsUrl></script>
}
<% } %>