bs-compile-middleware
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -20,2 +20,6 @@ 'use strict'; | ||
var _mime = require('mime'); | ||
var _mime2 = _interopRequireDefault(_mime); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -37,3 +41,3 @@ | ||
return function (req, res, done) { | ||
return function (req, res, next) { | ||
var pathname = normalizePathname(_url2.default.parse(req.url).pathname || ''); | ||
@@ -49,4 +53,3 @@ | ||
if (error) { | ||
res.end(formatError(error)); | ||
return next(true); | ||
return res.end(formatError(error)); | ||
} | ||
@@ -57,2 +60,3 @@ | ||
out = compiler.compile(data, srcPath); | ||
res.setHeader('Content-Type', _mime2.default.lookup(pathname)); | ||
} catch (error) { | ||
@@ -63,5 +67,4 @@ out = formatError(error); | ||
res.end(out); | ||
next(true); | ||
}); | ||
}, done); | ||
}, next); | ||
}; | ||
@@ -84,5 +87,4 @@ } | ||
f(head, function (isEnd) { | ||
if (isEnd) return done(); | ||
forEachAsync(tail, f, done); | ||
f(head, function () { | ||
return forEachAsync(tail, f, done); | ||
}); | ||
@@ -89,0 +91,0 @@ } |
{ | ||
"name": "bs-compile-middleware", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "katashin", | ||
@@ -26,2 +26,3 @@ "description": "Compilation middleware for Browsersync", | ||
"dev": "npm run test:unit -- -w", | ||
"example": "npm run build && node example/server.js", | ||
"build": "babel src --out-dir lib", | ||
@@ -43,2 +44,4 @@ "build:prod": "cross-env NODE_ENV=production npm run build", | ||
"babel-preset-power-assert": "^1.0.0", | ||
"browser-sync": "^2.18.2", | ||
"buble": "^0.14.2", | ||
"cross-env": "^3.0.0", | ||
@@ -50,6 +53,10 @@ "eslint": "^3.0.0", | ||
"mocha": "^3.2.0", | ||
"node-sass": "^3.13.0", | ||
"power-assert": "^1.3.1", | ||
"pug": "^2.0.0-beta6", | ||
"rimraf": "^2.5.4" | ||
}, | ||
"dependencies": { | ||
"mime": "^1.3.4" | ||
} | ||
} |
@@ -5,4 +5,51 @@ # bs-compile-middleware | ||
## Installation | ||
```bash | ||
npm install --save-dev bs-compile-middleware | ||
``` | ||
## Usage | ||
In case of the following configuration, if you request to `http://localhost:3000/index.html`, bs-compile-middleware get `path/to/src/index.pug` and compile it. Finally, the compiled html is returned from the Browsersync server. | ||
```js | ||
const browserSync = require('browser-sync').create() | ||
const compileMiddleware = require('bs-compile-middleware').compileMiddleware | ||
// any preprocessor you want to use | ||
const pug = require('pug') | ||
browserSync({ | ||
middleware: compileMiddleware({ | ||
srcDir: 'path/to/src', | ||
compilers: [ | ||
{ | ||
// a requested extention you want to hook some compilations | ||
reqExt: 'html', | ||
// source file extention | ||
srcExt: 'pug', | ||
// you can compile a requested source file in compile hook | ||
// It expects compiled data as return value | ||
// src - Buffer of the source file | ||
// filename - file name of the source | ||
compile: (src, filename) => { | ||
// example compiling pug | ||
return pug.render(src.toString(), { filename }) | ||
} | ||
} | ||
] | ||
}) | ||
}) | ||
``` | ||
## Contribution | ||
Feel free to open issues and pull requests if you find any bugs, want to add any features or so on. | ||
## License | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6315
55
1
18
+ Addedmime@^1.3.4
+ Addedmime@1.6.0(transitive)