@@ -2,8 +2,11 @@ import { readFile } from 'fs'
22import  {  createServer  as  createHttpsServer  }  from  'https' 
33import  {  createServer  }  from  'http' 
44import  {  resolve ,  posix  }  from  'path' 
5+ import  {  Mime  }  from  'mime/lite' 
6+ 
7+ import  standardTypes  from  'mime/types/standard.js' 
8+ import  otherTypes  from  'mime/types/other.js' 
59
6- import  mime  from  'mime' 
710import  opener  from  'opener' 
811
912let  server 
@@ -13,6 +16,7 @@ let server
1316 * @param  {import('..').RollupServeOptions } options 
1417 */ 
1518function  serve  ( options  =  {  contentBase : ''  } )  { 
19+   const  mime  =  new  Mime ( standardTypes ,  otherTypes ) 
1620  if  ( Array . isArray ( options )  ||  typeof  options  ===  'string' )  { 
1721    options  =  {  contentBase : options  } 
1822  } 
@@ -22,7 +26,6 @@ function serve (options = { contentBase: '' }) {
2226  options . https  =  options . https  ||  false 
2327  options . openPage  =  options . openPage  ||  '' 
2428  options . onListening  =  options . onListening  ||  function  noop  ( )  {  } 
25-   mime . default_type  =  'text/plain' 
2629
2730  if  ( options . mimeTypes )  { 
2831    mime . define ( options . mimeTypes ,  true ) 
@@ -41,7 +44,7 @@ function serve (options = { contentBase: '' }) {
4144
4245    readFileFromContentBase ( options . contentBase ,  urlPath ,  function  ( error ,  content ,  filePath )  { 
4346      if  ( ! error )  { 
44-         return  found ( response ,  filePath ,  content ) 
47+         return  found ( response ,  mime . getType ( filePath ) ,  content ) 
4548      } 
4649      if  ( error . code  !==  'ENOENT' )  { 
4750        response . writeHead ( 500 ) 
@@ -57,7 +60,7 @@ function serve (options = { contentBase: '' }) {
5760          if  ( error )  { 
5861            notFound ( response ,  filePath ) 
5962          }  else  { 
60-             found ( response ,  filePath ,  content ) 
63+             found ( response ,  mime . getType ( filePath ) ,  content ) 
6164          } 
6265        } ) 
6366      }  else  { 
@@ -146,8 +149,8 @@ function notFound (response, filePath) {
146149    '\n\n(rollup-plugin-serve)' ,  'utf-8' ) 
147150} 
148151
149- function  found  ( response ,  filePath ,  content )  { 
150-   response . writeHead ( 200 ,  {  'Content-Type' : mime . getType ( filePath )  } ) 
152+ function  found  ( response ,  mimeType ,  content )  { 
153+   response . writeHead ( 200 ,  {  'Content-Type' : mimeType   ||   'text/plain'  } ) 
151154  response . end ( content ,  'utf-8' ) 
152155} 
153156
0 commit comments