WearyMonkey / ngtemplate-loader

Include AngularJS templates in the Webpack bundle and preload the template cache.
MIT License
238 stars 78 forks source link

Doesn't works on windows #4

Closed andrey-skl closed 9 years ago

andrey-skl commented 9 years ago

As we know, the windows path separator is dramatic different from other systems. So shouldn't we handle it in this loader?

warrenrumak commented 9 years ago

I've run into this as well, but the problem isn't that the loader doesn't try to handle it -- it's that it's not doing it correctly. Two specific problems:

1) On line 11 where it reads:

    relativeTo.replace('/', path.sep);

this is only going to replace the first / with a \ on Windows. .replace() also returns a new string instead of updating the input. It needs to read:

    relativeTo = relativeTo.replace(/\//g, path.sep);

2) Since the file name is treated as a regular expression, converting / to \ won't work. In addition, other characters like a . in a path need to be escaped because . is a letter match. Because of this, paths should never be passed directly into .match() in JS. Instead, use a function like this:

    function escapeRegExp(string) {
        return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
    }

and then call .match() like so:

        var relativeToMatch = this.resource.match(new RegExp("^" + escapeRegExp(relativeTo), "g"));

This will (unfortunately?) prevent using regular expressions, but ngtemplate-loader is already going to break on any system (not just Windows) if there's a ., [, etc. in the path so this feature may need to be rethought....

epelc commented 9 years ago

Will there be a fix for this soon?

WearyMonkey commented 9 years ago

Hi @epelc, I will take a look tonight.

epelc commented 9 years ago

@WearyMonkey Thanks this looks like it will fix my directives loading issue

icfantv commented 8 years ago

I'm confused here. I have everything set up with nix style path separators and it works great. When I try to build on windows it barfs. I see this, but the way I'm reading the above comments, the build tool (aka, this library) should be properly handling my nix style paths but I don't think it is.

Can someone please explain what this fix is supposed to do? Is it supposed to make the build platform agnostic?

victordidenko commented 7 years ago

@WearyMonkey in version 2.0.0, while build on Windows, template path separators become "\\". In version 1.3.1 everything was working fine.

victordidenko commented 7 years ago

Fixed in version 2.0.1, thank you!