simple-nunjucks-loader
Advanced tools
Comparing version 1.0.0-alpha.0 to 1.0.0-alpha.1
@@ -12,10 +12,6 @@ "use strict"; | ||
var _precompileTemplate = require("./precompile-template"); | ||
var _withDependencies = require("./precompile/with-dependencies"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function render(loader, source, options) { | ||
return (0, _precompileTemplate.precompileTemplate)(loader, source, options); | ||
} | ||
function nunjucksLoader(source) { | ||
@@ -37,10 +33,32 @@ const { | ||
}; | ||
render(this, source, options).then(precompiled => { | ||
(0, _withDependencies.withDependencies)(this.resourcePath, source, options).then(template => { | ||
const { | ||
dependencies, | ||
precompiled | ||
} = template; | ||
return { | ||
precompiled, | ||
dependencies: dependencies.reduce((imports, { | ||
fullPath | ||
}) => { | ||
this.addDependency(fullPath); | ||
const path = JSON.stringify(fullPath); | ||
return ` | ||
${imports}precompiledTemplates[${path}] = require(${path}).precompiled; | ||
`; | ||
}, '') | ||
}; | ||
}).then(template => { | ||
const { | ||
dependencies, | ||
precompiled | ||
} = template; | ||
const runtimeImport = `var runtime = require(${(0, _loaderUtils.stringifyRequest)(this, `${_path.default.resolve(_path.default.join(__dirname, 'runtime.js'))}`)});`; | ||
const resourcePathString = JSON.stringify(this.resourcePath); | ||
callback(null, ` | ||
var precompiledTemplates = {}; | ||
${runtimeImport} | ||
${dependencies} | ||
${precompiled} | ||
module.exports = function nunjucksTemplate(ctx) { | ||
${precompiled} | ||
var nunjucks = runtime( | ||
@@ -51,4 +69,7 @@ ${JSON.stringify(options)}, | ||
return nunjucks.render(${JSON.stringify(this.resourcePath)}, ctx); | ||
};`); | ||
return nunjucks.render(${resourcePathString}, ctx); | ||
}; | ||
module.exports.precompiled = precompiledTemplates[${resourcePathString}]; | ||
`); | ||
}, function (error) { | ||
@@ -55,0 +76,0 @@ callback(error); |
{ | ||
"name": "simple-nunjucks-loader", | ||
"version": "1.0.0-alpha.0", | ||
"version": "1.0.0-alpha.1", | ||
"description": "Webpack loader for Nunjucks", | ||
@@ -10,3 +10,6 @@ "main": "lib/loader.js", | ||
"test": "jest", | ||
"posttest": "rm -rf ./test/bundles/" | ||
"posttest": "rm -rf ./test/bundles/", | ||
"preversion": "npm test", | ||
"postversion": "git push && git push --tags", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
@@ -13,0 +16,0 @@ "repository": { |
@@ -1,2 +0,2 @@ | ||
# nunjucks-loader | ||
# Nunjucks templates loader for Webpack | ||
This Webpack loader compiles [Nunjucks](https://github.com/mozilla/nunjucks) templates. | ||
@@ -3,0 +3,0 @@ [`html-webpack-plugin`](https://github.com/jantimon/html-webpack-plugin) compatible. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13280
9
254
1