示例#1
0
        /// <summary>
        /// Gets a html script tag for the specified asset.
        /// </summary>
        /// <param name="bundle">The name of the Webpack bundle.</param>
        /// <param name="fallbackBundle">The name of the bundle to fallback to if main bundle does not exist.</param>
        /// <param name="load">Enum for modifying script load behavior.</param>
        /// <returns>An HtmlString containing the html script tag.</returns>
        public async Task <HtmlString> GetScriptTagAsync(string bundle, string?fallbackBundle, ScriptLoad load = ScriptLoad.Normal)
        {
            if (string.IsNullOrEmpty(bundle))
            {
                return(HtmlString.Empty);
            }

            bundle = TryFixJsBundleName(bundle);
            var file = await _manifestService.GetFromManifestAsync(bundle).ConfigureAwait(false);

            if (file == null)
            {
                if (string.IsNullOrEmpty(fallbackBundle))
                {
                    return(HtmlString.Empty);
                }

                fallbackBundle = TryFixJsBundleName(fallbackBundle);
                file           = await _manifestService.GetFromManifestAsync(fallbackBundle).ConfigureAwait(false);
            }

            return(file != null
                ? new HtmlString(_tagBuilder.BuildScriptTag(file, load))
                : HtmlString.Empty);
        }