Skip to content

Commit

Permalink
Add basename var to nunjucks (#12)
Browse files Browse the repository at this point in the history
* Add basename var to nunjucks

* Change variable name
  • Loading branch information
erxclau authored Aug 12, 2022
1 parent 18874c5 commit c11a4b8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { basename } from "path";
import { Transformer } from "@parcel/plugin";
import { renderString, configure } from "nunjucks";

Expand Down Expand Up @@ -29,7 +30,10 @@ export default new Transformer({
async transform({ asset, config }) {
configure({ autoescape: false });
let code = await asset.getCode();
let result = renderString(code, config);
let result = renderString(code, {
...config,
filename: basename(asset.filePath),
});
asset.setCode(result);
return [asset];
},
Expand Down

0 comments on commit c11a4b8

Please sign in to comment.