Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,73 @@ serve({
// Multiple folders to serve from
contentBase: ['dist', 'static'],

// URL root path to serve the static content at
contentBasePublicPath: '/',

// Customize serving of static files, see https://expressjs.com/en/resources/middleware/serve-static.html
staticOptions: {},

// Set to true to enable the default compression, or to an object to customize the compression
// according to https://expressjs.com/en/resources/middleware/compression.html
compress: false,

// Set to true to enable directory indexes, or to an object to customize the index generation
// according to https://expressjs.com/en/resources/middleware/serve-index.html
serveIndex: false,

// Set to true to return index.html (200) instead of error page (404)
historyApiFallback: false,

// Path to fallback page
// Path to fallback page, see also https://github.com/bripkens/connect-history-api-fallback
historyApiFallback: '/200.html',

// Options used in setting up server
host: 'localhost',
port: 10001,

// Set to true to keep incrementing the value of port and trying to bind to it,
// until a free port is found.
autoPort: false,

// By default server will be served over HTTP (https: false). It can optionally be served over HTTPS
https: {
key: fs.readFileSync('/path/to/server.key'),
cert: fs.readFileSync('/path/to/server.crt'),
ca: fs.readFileSync('/path/to/ca.pem')
},

//set headers
// Set additional headers
headers: {
'Access-Control-Allow-Origin': '*',
foo: 'bar'
},

// set custom mime types, usage https://github.com/broofa/mime#mimedefinetypemap-force--false
// Set custom mime types, usage https://github.com/broofa/mime#mimedefinetypemap-force--false
mimeTypes: {
'application/javascript': ['js_commonjs-proxy']
}
},

// Let requests to /api/* be forwarded to http://localhost:3000/*
// See the full documentation at https://webpack.js.org/configuration/dev-server/#devserverproxy
proxy: [
{
context: ['/api'],
target: 'http://localhost:3000',
pathRewrite: { '^/api': '' },
},
],

// Customize the Express instance before all middlewares are installed
before: function(app) {
...
},

// Customize the Express instance after all middlewares are installed
after: function(app) {
...
},

// execute function after server has begun listening
// Execute function after server has begun listening
onListening: function (server) {
const address = server.address()
const host = address.address === '::' ? 'localhost' : address.address
Expand Down
47 changes: 47 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Plugin } from 'rollup'
import { IncomingHttpHeaders, OutgoingHttpHeaders, Server } from 'http'
import { ServerOptions } from 'https'
import { TypeMap } from 'mime'
import { Application } from 'express'

export interface RollupServeOptions {
/**
Expand All @@ -26,6 +27,29 @@ export interface RollupServeOptions {
*/
contentBase?: string | string[]

/**
* URL root path to serve the static content at (default: `'/'`)
*/
contentBasePublicPath?: string

/**
* Options to be passed to the serve-static middleware, see the documentation
* at https://expressjs.com/en/resources/middleware/serve-static.html.
*/
staticOptions?: object

/**
* Enable compression of the served content. If you want to customize the default
* settings, see https://expressjs.com/en/resources/middleware/compression.html.
*/
compress?: boolean | object

/**
* Enable directory indexes. If you want to customize the default
* settings, see https://expressjs.com/en/resources/middleware/serve-index.html.
*/
serveIndex?: boolean | object

/**
* Set to `true` to return index.html (200) instead of error page (404)
* or path to fallback page
Expand All @@ -42,6 +66,12 @@ export interface RollupServeOptions {
*/
port?: number | string

/**
* Automatically choose an available port if the specified port is already in use.
* If set to `true`, the meaning of `port` changes to the initial port to try. (default: `false`)
*/
autoPort?: boolean

/**
* By default server will be served over HTTP (https: `false`). It can optionally be served over HTTPS.
*/
Expand All @@ -63,6 +93,23 @@ export interface RollupServeOptions {
*/
mimeTypes?: TypeMap

/**
* Let some requests be forwarded to other servers by their URL path. For example,
* requests to /api/* be can be forwarded to http://localhost:3000/*. See the full
* documentation at https://webpack.js.org/configuration/dev-server/#devserverproxy.
*/
proxy?: object[]

/**
* Function to be called before all Express middlewares are installed.
*/
before?: (app: Application) => void

/**
* Function to be called after all Express middlewares are installed.
*/
after?: (app: Application) => void

/**
* Execute function after server has begun listening
*/
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@
],
"type": "module",
"dependencies": {
"compression": "^1.8.1",
"connect-history-api-fallback": "^2.0.0",
"express": "^5.2.1",
"http-proxy-middleware": "^3.0.5",
"killable": "^1.0.1",
"mime": "^4",
"opener": "1"
"opener": "1",
"serve-index": "^1.9.1"
},
"devDependencies": {
"@rollup/plugin-buble": "^1.0.0",
Expand Down
23 changes: 21 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ export default {
{ file: 'dist/index.cjs', format: 'cjs', exports: 'default' },
{ file: 'dist/index.mjs', format: 'esm' }
],
plugins: [buble()],
external: ['fs', 'https', 'http', 'path', 'mime', 'opener']
plugins: [
buble({
transforms: { forOf: false }
})
],
external: [
'fs',
'https',
'http',
'path',
'mime/lite',
'mime/types/standard.js',
'mime/types/other.js',
'opener',
'express',
'killable',
'compression',
'serve-index',
'connect-history-api-fallback',
'http-proxy-middleware'
]
}
Loading