rollup-plugin-serve
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -24,4 +24,3 @@ 'use strict'; | ||
} | ||
options.contentBase = Array.isArray(options.contentBase) ? options.contentBase : [options.contentBase]; | ||
options.host = options.host || 'localhost'; | ||
options.contentBase = Array.isArray(options.contentBase) ? options.contentBase : [options.contentBase || '']; | ||
options.port = options.port || 10001; | ||
@@ -33,2 +32,6 @@ options.headers = options.headers || {}; | ||
if (options.mimeTypes) { | ||
mime.define(options.mimeTypes, true); | ||
} | ||
var requestListener = function (request, response) { | ||
@@ -75,2 +78,4 @@ // Remove querystring | ||
server.close(); | ||
} else { | ||
closeServerOnTermination(); | ||
} | ||
@@ -85,21 +90,25 @@ | ||
closeServerOnTermination(server); | ||
var first = true; | ||
var running = options.verbose === false; | ||
return { | ||
name: 'serve', | ||
generateBundle: function generateBundle () { | ||
if (!running) { | ||
running = true; | ||
if (first) { | ||
first = false; | ||
// Log which url to visit | ||
var url = (options.https ? 'https' : 'http') + '://' + options.host + ':' + options.port; | ||
options.contentBase.forEach(function (base) { | ||
console.log(green(url) + ' -> ' + path.resolve(base)); | ||
}); | ||
var url = (options.https ? 'https' : 'http') + '://' + (options.host || 'localhost') + ':' + options.port; | ||
if (options.verbose !== false) { | ||
options.contentBase.forEach(function (base) { | ||
console.log(green(url) + ' -> ' + path.resolve(base)); | ||
}); | ||
} | ||
// Open browser | ||
if (options.open) { | ||
opener(url + options.openPage); | ||
if (/https?:\/\/.+/.test(options.openPage)) { | ||
opener(options.openPage); | ||
} else { | ||
opener(url + options.openPage); | ||
} | ||
} | ||
@@ -146,8 +155,10 @@ } | ||
function closeServerOnTermination (server) { | ||
var terminationSignals = ['SIGINT', 'SIGTERM']; | ||
function closeServerOnTermination () { | ||
var terminationSignals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP']; | ||
terminationSignals.forEach(function (signal) { | ||
process.on(signal, function () { | ||
server.close(); | ||
process.exit(); | ||
if (server) { | ||
server.close(); | ||
process.exit(); | ||
} | ||
}); | ||
@@ -154,0 +165,0 @@ }); |
@@ -20,4 +20,3 @@ import { readFile } from 'fs'; | ||
} | ||
options.contentBase = Array.isArray(options.contentBase) ? options.contentBase : [options.contentBase]; | ||
options.host = options.host || 'localhost'; | ||
options.contentBase = Array.isArray(options.contentBase) ? options.contentBase : [options.contentBase || '']; | ||
options.port = options.port || 10001; | ||
@@ -29,2 +28,6 @@ options.headers = options.headers || {}; | ||
if (options.mimeTypes) { | ||
mime.define(options.mimeTypes, true); | ||
} | ||
var requestListener = function (request, response) { | ||
@@ -71,2 +74,4 @@ // Remove querystring | ||
server.close(); | ||
} else { | ||
closeServerOnTermination(); | ||
} | ||
@@ -81,21 +86,25 @@ | ||
closeServerOnTermination(server); | ||
var first = true; | ||
var running = options.verbose === false; | ||
return { | ||
name: 'serve', | ||
generateBundle: function generateBundle () { | ||
if (!running) { | ||
running = true; | ||
if (first) { | ||
first = false; | ||
// Log which url to visit | ||
var url = (options.https ? 'https' : 'http') + '://' + options.host + ':' + options.port; | ||
options.contentBase.forEach(function (base) { | ||
console.log(green(url) + ' -> ' + resolve(base)); | ||
}); | ||
var url = (options.https ? 'https' : 'http') + '://' + (options.host || 'localhost') + ':' + options.port; | ||
if (options.verbose !== false) { | ||
options.contentBase.forEach(function (base) { | ||
console.log(green(url) + ' -> ' + resolve(base)); | ||
}); | ||
} | ||
// Open browser | ||
if (options.open) { | ||
opener(url + options.openPage); | ||
if (/https?:\/\/.+/.test(options.openPage)) { | ||
opener(options.openPage); | ||
} else { | ||
opener(url + options.openPage); | ||
} | ||
} | ||
@@ -142,8 +151,10 @@ } | ||
function closeServerOnTermination (server) { | ||
var terminationSignals = ['SIGINT', 'SIGTERM']; | ||
function closeServerOnTermination () { | ||
var terminationSignals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP']; | ||
terminationSignals.forEach(function (signal) { | ||
process.on(signal, function () { | ||
server.close(); | ||
process.exit(); | ||
if (server) { | ||
server.close(); | ||
process.exit(); | ||
} | ||
}); | ||
@@ -150,0 +161,0 @@ }); |
{ | ||
"name": "rollup-plugin-serve", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Serve your rolled up bundle", | ||
@@ -13,3 +13,3 @@ "main": "dist/index.cjs.js", | ||
"prepare": "yarn lint && yarn build", | ||
"test": "cd test && rollup -c || cd .." | ||
"test": "cd test && rollup -cw || cd .." | ||
}, | ||
@@ -37,10 +37,10 @@ "keywords": [ | ||
"dependencies": { | ||
"mime": ">=2.0.3", | ||
"mime": ">=2.4.6", | ||
"opener": "1" | ||
}, | ||
"devDependencies": { | ||
"rollup": "1", | ||
"rollup-plugin-buble": "^0.15.0", | ||
"standard": "12" | ||
"@rollup/plugin-buble": "0.21.3", | ||
"rollup": "2", | ||
"standard": "14" | ||
} | ||
} |
@@ -91,2 +91,7 @@ # Rollup plugin to serve the bundle | ||
foo: 'bar' | ||
}, | ||
// set custom mime types, usage https://github.com/broofa/mime#mimedefinetypemap-force--false | ||
mimeTypes: { | ||
'application/javascript': ['js_commonjs-proxy'] | ||
} | ||
@@ -93,0 +98,0 @@ }) |
19554
314
127
Updatedmime@>=2.4.6