You've already forked angular2-template-loader
mirror of
https://github.com/encounter/angular2-template-loader.git
synced 2026-03-30 10:57:24 -07:00
Allow for absense of proper relative pathing
This commit is contained in:
@@ -4,7 +4,12 @@ var stylesRegex = /styleUrls:(\s*\[[^\]]*?\])/g;
|
||||
var stringRegex = /(['"])((?:[^\\]\\\1|.)*?)\1/g;
|
||||
|
||||
function replaceStringsWithRequires(string) {
|
||||
return string.replace(stringRegex, "require('$2')");
|
||||
return string.replace(stringRegex, function (match, quote, url) {
|
||||
if (url.charAt(0) !== ".") {
|
||||
url = "./" + url;
|
||||
}
|
||||
return "require('" + url + "')";
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function(source) {
|
||||
|
||||
Vendored
+2
@@ -1,8 +1,10 @@
|
||||
var sampleAngular2ComponentSimpleFixture = require('./sample_angular2_component_file_string_simple.js');
|
||||
var componentWithQuoteInUrls = require('./component_with_quote_in_urls.js');
|
||||
var componentWithMultipleStyles = require('./component_with_multiple_styles.js');
|
||||
var componentWithoutRelPeriodSlash = require('./component_without_relative_period_slash.js');
|
||||
|
||||
exports.simpleAngular2TestComponentFileStringSimple = sampleAngular2ComponentSimpleFixture;
|
||||
exports.componentWithQuoteInUrls = componentWithQuoteInUrls;
|
||||
exports.componentWithMultipleStyles = componentWithMultipleStyles;
|
||||
exports.componentWithoutRelPeriodSlash = componentWithoutRelPeriodSlash;
|
||||
|
||||
|
||||
@@ -78,5 +78,22 @@ describe("loader", function() {
|
||||
.eql(`template: require('./index/app.html')`);
|
||||
});
|
||||
|
||||
it("Should handle the absense of proper relative path notation", function() {
|
||||
loader.call({}, fixtures.componentWithoutRelPeriodSlash)
|
||||
.should
|
||||
.be
|
||||
.eql(`
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'test-component',
|
||||
template: require('./file.html'),
|
||||
styles: [require('./styles.css')]
|
||||
})
|
||||
export class TestComponent {}
|
||||
`
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user