diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..eaa8b3f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +# Changelog + +## 0.1.0 - Init loader + +* loader-utils > `^2.0.0` +* nunjucks > `^3.2.2` \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..db7ea9f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 Eryomin Nickolay + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5d1afb5 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +Nunjucks webpack loader +============================== + +[![NPM version][npm-image]][npm-url] + +[npm-url]: https://www.npmjs.com/package/nunjucks-template-loader +[npm-image]: https://img.shields.io/badge/npm-v0.1.0-blue \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..9bea07f --- /dev/null +++ b/index.js @@ -0,0 +1,67 @@ +const fs = require('fs'); +const path = require('path'); +const utils = require('loader-utils'); +const nunjucks = require('nunjucks'); + +const NunjucksLoader = nunjucks.Loader.extend({ + init: function(searchPaths, sourceFoundCallback) { + this.sourceFoundCallback = sourceFoundCallback; + if(searchPaths) { + searchPaths = Array.isArray(searchPaths) ? searchPaths : [searchPaths]; + + this.searchPaths = searchPaths.map(path.normalize); + } + else { + this.searchPaths = ['.']; + } + }, + + getSource: function(name) { + let fullpath = null; + let paths = this.searchPaths; + + for(let i=0; i