Skip to content

Commit

Permalink
Allow to use own module for escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
btd committed Nov 19, 2017
1 parent 376c4cc commit 05f9753
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# rollup-plugin-jst

Precompile lodash templates to javascript. It uses lodash-es/escapa for escaping capabilities. So it should be installed in dev dependencies.

Precompile lodash templates to javascript. It uses lodash-es/escapa for escaping capabilities. So it should be installed
in dev dependencies.

## Installation

Expand All @@ -10,7 +10,6 @@ npm i -S lodash-es # if you use <%- %> escaping
npm i -D rollup-plugin-jst rollup-plugin-node-resolve
```


## Usage Example

```js
Expand Down Expand Up @@ -42,10 +41,17 @@ rollup({
// see github.com/kangax/html-minifier for documentation
minifyOptions: {
collapseWhitespace: true
}
},

// if you do not want to use lodash-es/escape for some reason
// (e.g because it is quite huge for just escape function)
// you can set which module to use - it should have single default export
// you should care about correct resolving and handing of this file
// if it is not using modules
escapeModule: 'escape-html'
}),
resolve({
jsnext: true,
module: true,
main: true
})
]
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"rollup-pluginutils": "^2.0.1"
},
"devDependencies": {
"escape-html": "^1.0.3",
"eslint": "^4.11.0",
"lodash-es": "^4.17.4",
"mocha": "^4.0.1",
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module.exports = function(options = {}) {

const minifyOptions = options.minifyOptions || {};

const escapeModule = options.escapeModule || "lodash-es/escape";

return {
transform(code, id) {
if (!filter(id)) {
Expand All @@ -37,7 +39,7 @@ module.exports = function(options = {}) {
return "__e = escape";
});

const intro = hasEscape ? "import escape from 'lodash-es/escape'" : "";
const intro = hasEscape ? "import escape from " + JSON.stringify(escapeModule) + ";" : "";

return `
${intro}
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ describe("rollup-plugin-jst", () => {
plugins: [jst({ minify: true, minifyOptions: { collapseWhitespace: true } })]
}).then(executeBundle);
});

it("other escape module", () => {
return rollup({
input: "sample/a.ejs",
plugins: [jst({ escapeModule: "escape-html" })]
}).then(executeBundle);
});
});

0 comments on commit 05f9753

Please sign in to comment.