Skip to content

Commit

Permalink
git push origin masterMerge branch 'vwochnik-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
btd committed Nov 17, 2017
2 parents 41d3dc2 + 53510e2 commit 02883f0
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 10 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
103 changes: 99 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
"name": "rollup-plugin-jst",
"version": "1.0.1",
"description": "",
"main": "dist/rollup-plugin-jst.cjs.js",
"scripts": {
"test": "mocha test/test.js"
},
"author": "Denis Bardadym <bardadymchik@gmail.com>",
"license": "MIT",
"jsnext:main": "src/index.js",
"main": "src/index.js",
"files": [
"src/",
"README.md"
],
"dependencies": {
"html-minifier": "^3.5.6",
"lodash": "^4.9.0",
"rollup-pluginutils": "^2.0.1"
},
Expand Down
13 changes: 11 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ const { extname } = require("path");
const { createFilter } = require("rollup-pluginutils");

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

export default function(options = {}) {
module.exports = function(options = {}) {
const filter = createFilter(options.include, options.exclude);

const extensions = options.extensions || [".html", ".ejs", ".jst"];

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 All @@ -36,4 +45,4 @@ export default function(options = {}) {
`;
}
};
}
};
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>
11 changes: 9 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ function executeBundle(bundle) {
}

describe("rollup-plugin-jst", () => {
it("compiles a component - escape", () => {
it("escape", () => {
return rollup({
input: "sample/a.ejs",
plugins: [jst()]
}).then(executeBundle);
});

it("compiles a component - noescape", () => {
it("noescape", () => {
return rollup({
input: "sample/b.ejs",
plugins: [jst()]
}).then(executeBundle);
});

it("htmlclean", () => {
return rollup({
input: "sample/c.ejs",
plugins: [jst({ minify: true, minifyOptions: { collapseWhitespace: true } })]
}).then(executeBundle);
});
});

0 comments on commit 02883f0

Please sign in to comment.