This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace simple-nunjucks-loader with njk-loader
## Reason Simplification of working with assets (images, fonts, etc.): - simple-nunjucks-loader doesn't work with data attributes (srcset, data-src, etc) - njk-loader requires no additional function to load images ## Dependencies removed: - simple-nunjucks-loader ## Installed dependencies: - html-loader
- Loading branch information
1 parent
a4978da
commit b056076
Showing
9 changed files
with
77 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const path = require('path') | ||
const { Environment, FileSystemLoader } = require('nunjucks') | ||
const { SOURCE_DIR } = require('../../constants') | ||
|
||
|
||
/** | ||
* Transpiles nunjucks files into HTML files. | ||
* https://webpack.js.org/contribute/writing-a-loader | ||
* | ||
* @requires nunjucks | ||
* @requires html-loader | ||
* | ||
* @todo Handle errors | ||
* @todo Hide common code (njk config) | ||
* | ||
* @param {String} source - the contents of the raw resource | ||
* @returns {String} a valid HTML string | ||
*/ | ||
module.exports = function(source) { | ||
const callback = this.async() | ||
const { context, templates } = this.getOptions() | ||
|
||
const env = new Environment( | ||
new FileSystemLoader(path.resolve(SOURCE_DIR, templates)), | ||
{ | ||
autoescape: true | ||
} | ||
) | ||
env.on('load', (name, source, loader) => { | ||
this.addDependency(source.path) | ||
}) | ||
|
||
env.renderString(source, context, (error, HTMLString) => { | ||
callback(error ? error : null, HTMLString) | ||
}) | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters