File tree Expand file tree Collapse file tree 4 files changed +35
-1
lines changed
Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,11 @@ app.use(webpackMiddleware(webpack({
7676 headers: { " X-Custom-Header" : " yes" },
7777 // custom headers
7878
79+ mimeTypes: { " text/html" : [ " phtml" ] },
80+ // Add custom mime/extension mappings
81+ // https://github.com/broofa/node-mime#mimedefine
82+ // https://github.com/webpack/webpack-dev-middleware/pull/150
83+
7984 stats: {
8085 colors: true
8186 },
Original file line number Diff line number Diff line change 1+ var mime = require ( "mime" ) ;
12var parseRange = require ( "range-parser" ) ;
23var pathIsAbsolute = require ( "path-is-absolute" ) ;
34var MemoryFileSystem = require ( "memory-fs" ) ;
@@ -28,6 +29,9 @@ module.exports = function Shared(context) {
2829 options . filename = new RegExp ( "^[\/]{0,1}" + str + "$" ) ;
2930 }
3031 }
32+ // defining custom MIME type
33+ if ( options . mimeTypes ) mime . define ( options . mimeTypes ) ;
34+
3135 context . options = options ;
3236 } ,
3337 defaultReporter : function ( reporterOptions ) {
Original file line number Diff line number Diff line change @@ -21,7 +21,6 @@ module.exports = function(compiler, options) {
2121 } ;
2222 var shared = Shared ( context ) ;
2323
24-
2524 // The middleware function
2625 function webpackDevMiddleware ( req , res , next ) {
2726 function goNext ( ) {
Original file line number Diff line number Diff line change @@ -143,6 +143,32 @@ describe("Server", function() {
143143 } ) ;
144144 } ) ;
145145
146+ describe ( "custom mimeTypes" , function ( ) {
147+ before ( function ( done ) {
148+ app = express ( ) ;
149+ var compiler = webpack ( webpackConfig ) ;
150+ var instance = middleware ( compiler , {
151+ stats : "errors-only" ,
152+ quiet : true ,
153+ index : "Index.phtml" ,
154+ mimeTypes : {
155+ "text/html" : [ "phtml" ]
156+ }
157+ } ) ;
158+ app . use ( instance ) ;
159+ listen = listenShorthand ( done ) ;
160+ instance . fileSystem . writeFileSync ( "/Index.phtml" , "welcome" ) ;
161+ } ) ;
162+ after ( close ) ;
163+
164+ it ( "request to Index.phtml" , function ( done ) {
165+ request ( app ) . get ( "/" )
166+ . expect ( "welcome" )
167+ . expect ( "Content-Type" , / t e x t \/ h t m l / )
168+ . expect ( 200 , done ) ;
169+ } ) ;
170+ } ) ;
171+
146172 describe ( "MultiCompiler" , function ( ) {
147173 before ( function ( done ) {
148174 app = express ( ) ;
You can’t perform that action at this time.
0 commit comments