simple-nunjucks-loader
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -37,6 +37,12 @@ "use strict"; | ||
function nunjucksLoader(source) { | ||
const isWindows = process.platform === 'win32'; | ||
const callback = this.async(); | ||
const options = (0, _getLoaderOptions.getLoaderOptions)(this, callback); | ||
const normalizedSearchPaths = [].concat(options.searchPaths).map(_path.default.normalize); | ||
const resourcePathImport = (0, _getImportPath.getImportPath)(this.resourcePath, normalizedSearchPaths); | ||
let resourcePathImport = (0, _getImportPath.getImportPath)(this.resourcePath, normalizedSearchPaths); | ||
if (isWindows) { | ||
resourcePathImport = resourcePathImport.replace(/\\/g, '/'); | ||
} | ||
(0, _withDependencies.withDependencies)(resourcePathImport, source, { ...options, | ||
@@ -71,4 +77,5 @@ searchPaths: normalizedSearchPaths | ||
lstripBlocks: options.lstripBlocks, | ||
// Loader specific option | ||
jinjaCompat: options.jinjaCompat | ||
// Loader specific options | ||
jinjaCompat: options.jinjaCompat, | ||
isWindows | ||
}); | ||
@@ -75,0 +82,0 @@ callback(null, ` |
@@ -19,3 +19,3 @@ "use strict"; | ||
return require(${assetImport}); | ||
}` : `require('${assetImport}')`; | ||
}` : `require(${JSON.stringify(assetImport)})`; | ||
return `_templateAssets['${uuid}'] = ${importInvocation};`; | ||
@@ -22,0 +22,0 @@ }).join(''); |
@@ -11,3 +11,3 @@ "use strict"; | ||
return extensions.map(([name, importPath]) => ` | ||
var _extension_${name} = require('${importPath}'); | ||
var _extension_${name} = require(${JSON.stringify(importPath)}); | ||
__nunjucks_module_dependencies__.extensions['${name}'] = { | ||
@@ -14,0 +14,0 @@ module: _extension_${name} |
@@ -11,3 +11,3 @@ "use strict"; | ||
return filters.map(([filterName, importPath, filterInstance]) => ` | ||
var _filter_${filterName} = require('${importPath}'); | ||
var _filter_${filterName} = require(${JSON.stringify(importPath)}); | ||
__nunjucks_module_dependencies__.filters['${filterName}'] = { | ||
@@ -14,0 +14,0 @@ module: _filter_${filterName}, |
@@ -13,3 +13,3 @@ "use strict"; | ||
return globals.map(([globalImport, globalPath]) => ` | ||
var _global_${(0, _toVar.toVar)(globalImport)} = require('${globalPath}'); | ||
var _global_${(0, _toVar.toVar)(globalImport)} = require(${JSON.stringify(globalPath)}); | ||
__nunjucks_module_dependencies__.globals['${globalImport}'] = { | ||
@@ -16,0 +16,0 @@ module: _global_${(0, _toVar.toVar)(globalImport)} |
@@ -19,3 +19,5 @@ "use strict"; | ||
const env = new nunjucks.Environment(new WebpackPrecompiledLoader(precompiled), options); | ||
const env = new nunjucks.Environment(new WebpackPrecompiledLoader(precompiled, { | ||
isWindows: options.isWindows === true | ||
}), options); | ||
@@ -22,0 +24,0 @@ for (const globalName in globals) { |
@@ -8,8 +8,15 @@ "use strict"; | ||
function WebpackPrecompiledLoader(precompiled = {}) { | ||
function WebpackPrecompiledLoader(precompiled = {}, { | ||
isWindows | ||
} = {}) { | ||
this.precompiled = precompiled; | ||
this.isWindows = isWindows; | ||
} | ||
WebpackPrecompiledLoader.prototype.getSource = function getSource(name) { | ||
if (!(name in this.precompiled)) { | ||
// For some strange reason all precompiled templates get leading slashes | ||
// on Windows, while templates have it without it | ||
const windowsIdentifier = `/${name}`; | ||
if (!(name in this.precompiled) && this.isWindows && !(windowsIdentifier in this.precompiled)) { | ||
return null; | ||
@@ -21,3 +28,3 @@ } | ||
type: 'code', | ||
obj: this.precompiled[name] | ||
obj: this.precompiled[name] || this.isWindows && this.precompiled[windowsIdentifier] | ||
}, | ||
@@ -24,0 +31,0 @@ path: name |
{ | ||
"name": "simple-nunjucks-loader", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Webpack loader for Nunjucks", | ||
@@ -5,0 +5,0 @@ "main": "lib/loader.js", |
@@ -182,2 +182,6 @@ [![npm package][npm-image]][npm-url] | ||
> :warning: Dynamic assets is not working in Windows at that moment, since | ||
> i don't have machine to debug what is wrong with it. Feel free to send PRs to | ||
> fix support for dynamic assets on Windows. | ||
> :warning: I advocate against using dynamic assets, because: | ||
@@ -184,0 +188,0 @@ > |
51269
1036
471