Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExpandGlobs add prefix '/' #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dean-shanghai
Copy link

following inputFiles + debug mode (no bundling and minification), the output js paths missing prefix "/"!
{
"outputFileName": "/lang.min.js",
"inputFiles": [
"/i18n/**/*.js"
],
"minify": {
"enabled": false
}
},

@madskristensen
Copy link
Member

Does this mean that all href and src attributes will always be rooted with a / at the beginning? Are there any consequences to that?

@skimedic
Copy link
Collaborator

What problem is this trying to solve?

@dean-shanghai
Copy link
Author

Does this mean that all href and src attributes will always be rooted with a / at the beginning? Are there any consequences to that?

  1. in release mode (bundle + minify), there is no problem, because the outputFileName path will be used;
  2. while in debug mode (NO bundling + NO minification)
  • without the prefix '/': those unbundled css/js files' path will be relative to the current page Url, which will cause 404!
  • and all the css/js resource files are in the wwwroot folder, so rooted with a '/' is OK.

@dean-shanghai
Copy link
Author

dean-shanghai commented Feb 22, 2020

What problem is this trying to solve?

Trying to fix the path problems in DEBUG mode when using wildcards inputFiles like the following:
"inputFiles": [
"/jsfolder/**/*.js"
]

@skimedic
Copy link
Collaborator

Aren't you using services.AddWebOptimizer(false, false); in development mode?

@dean-shanghai
Copy link
Author

dean-shanghai commented Feb 22, 2020

Aren't you using services.AddWebOptimizer(false, false); in development mode?

No, i'm not specifying the minify flag, just let the running mode decide to minify or not.

I'm USING WebOptimizer.Core and WebOptimizer.Core.Sass Source Code from github;
NOT using nuget packages (because of the path problem);

Code using:

        services.AddWebOptimizer(pipeline =>
        {
            var bundles = BundleHandler.GetBundles(Configuration["SiteSettings:BundleConfig"]); //using nuget package: BundlerMinifier.Core
            foreach (var bundle in bundles)
            {
                if (bundle.OutputFileName.EndsWith(".css"))
                {
                    pipeline.AddScssBundle(bundle.OutputFileName, bundle.InputFiles.ToArray());
                }
                else if (bundle.OutputFileName.EndsWith(".js"))
                {
                    pipeline.AddJavaScriptBundle(bundle.OutputFileName, bundle.InputFiles.ToArray());
                }
            }
        });

@mrdnote
Copy link

mrdnote commented Jun 3, 2021

This PR fixes the problem by always prefixing a slash, but what if you DO want the bundle to be on a relative path? The fix should check if the globbing pattern contains the prefix, and only prepend it when that's the case.

@dean-shanghai
Copy link
Author

This PR fixes the problem by always prefixing a slash, but what if you DO want the bundle to be on a relative path? The fix should check if the globbing pattern contains the prefix, and only prepend it when that's the case.

check on what standard? there is no extra info for you to know whether to add the slash or not.

you can use the bundle (release or dev mode) on root level pages (www.domain.com/aaa), or pages in subfolders (www.domain.com/aaa/bbb), so relative path will cause problems.

I can think of two ways to solve this problem:

  1. always generate relative paths to the root directory (not to the current directory), which is the easiest way, everyone follow this rule and it's ok;
  2. add flags (indicating whether or not to add this prefix slash) to every config node in the bundleconfig.json file?

@mrdnote
Copy link

mrdnote commented Jun 4, 2021

Check on whether the globbing pattern is relative or not. If it contains a forward slash, also apply this slash to the output files, if not, then don't apply it. I think this can be achieved inside Asset.ExpandGlobs.

@Nouwan
Copy link

Nouwan commented Nov 12, 2021

Seems quite possible that this fixes #199 Is there anything I can do to help get this pr merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants