diff --git a/src/index.js b/src/index.js index c140846..6d678fe 100644 --- a/src/index.js +++ b/src/index.js @@ -40,6 +40,8 @@ module.exports = function(source, sourcemap) { filePath = path.join(relativeDir, filePath); } + filePath = utils.normalizeFilePath(filePath); + if (loader === 'system') { return utils.getSystemLoader(filePath, moduleName); } else { diff --git a/src/utils.js b/src/utils.js index 0b3ec08..acfbefe 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,6 +1,7 @@ +var os = require('os'); var path = require('path'); -function getRequireLoader(filePath, moduleName) { +module.exports.getRequireLoader = function(filePath, moduleName) { var result = [ 'loadChildren: () => new Promise(function (resolve) {\n', ' (require as any).ensure([], function (require) {\n', @@ -10,9 +11,9 @@ function getRequireLoader(filePath, moduleName) { ]; return result.join(''); -} +}; -function getSystemLoader(filePath, moduleName) { +module.exports.getSystemLoader = function(filePath, moduleName) { var result = [ 'loadChildren: () => System.import(\'' + filePath + '\')\n', ' .then(function(module) {\n', @@ -21,12 +22,18 @@ function getSystemLoader(filePath, moduleName) { ]; return result.join(''); -} +}; -function getFilename(resourcePath) { +module.exports.getFilename = function(resourcePath) { var filename = path.basename(resourcePath); return path.basename(resourcePath, path.extname(filename)); -} +}; -module.exports = { getRequireLoader, getSystemLoader, getFilename }; +module.exports.normalizeFilePath = function(filePath) { + if (os.platform() === 'win32') { + return newPath.replace(/\//g, '\\\\'); + } + + return filePath; +}