Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into vwochnik-master
  • Loading branch information
btd committed Nov 17, 2017
2 parents 41d3dc2 + b263d19 commit 30235ab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ rollup({
// You can pass options to _.template(code, templateOptions)
templateOptions: {
variable: 'data' // default variable for template is 'data',
},

// You can enable HTML minification before the template is compiled
// by default turned off
minify: true,

// You can pass options to HTMLMinifier
// see github.com/kangax/html-minifier for documentation
minifyOptions: {
collapseWhitespace: true
}
}),
resolve({
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"README.md"
],
"dependencies": {
"html-minifier": "^3.5.6",
"lodash": "^4.9.0",
"rollup-pluginutils": "^2.0.1"
},
Expand Down
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { extname } = require("path");
const { createFilter } = require("rollup-pluginutils");

const template = require("lodash/template");
const htmlMinifier = require("html-minifier");

export default function(options = {}) {
const filter = createFilter(options.include, options.exclude);
Expand All @@ -10,6 +11,10 @@ export default function(options = {}) {

const templateOptions = options.templateOptions || { variable: "data" };

const minify = options.minify || false;

const minifyOptions = options.minifyOptions || {};

return {
transform(code, id) {
if (!filter(id)) {
Expand All @@ -20,6 +25,10 @@ export default function(options = {}) {
return null;
}

if (minify) {
code = htmlMinifier.minify(code, minifyOptions);
}

const tpl = template(code, templateOptions);

let hasEscape = false;
Expand Down
3 changes: 3 additions & 0 deletions test/sample/c.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div >
<p> <%= data %></p >
</div>
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ describe("rollup-plugin-jst", () => {
plugins: [jst()]
}).then(executeBundle);
});

it( 'compiles a component - htmlclean', () => {
return rollup({
entry: 'sample/c.ejs',
plugins: [ jst({ minify: true, minifyOptions: { collapseWhitespace: true } }) ]
}).then( executeBundle );
});
});

0 comments on commit 30235ab

Please sign in to comment.