File tree 3 files changed +39
-3
lines changed
3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -150,8 +150,15 @@ Type: `Object`
150
150
Default: ` null `
151
151
152
152
This property allows a user to register custom mime types or extension mappings.
153
- eg. ` { 'text/html': [ 'phtml' ] } ` . Please see the documentation for
154
- [ ` node-mime ` ] ( https://github.com/broofa/node-mime#mimedefine ) for more information.
153
+ eg. ` mimeTypes: { 'text/html': [ 'phtml' ] } ` .
154
+
155
+ By default node-mime will throw an error if you try to map a type to an extension
156
+ that is already assigned to another type. Passing ` force: true ` will suppress this behavior
157
+ (overriding any previous mapping).
158
+ eg. ` mimeTypes: { typeMap: { 'text/html': [ 'phtml' ] } }, force: true } ` .
159
+
160
+ Please see the documentation for
161
+ [ ` node-mime ` ] ( https://github.com/broofa/node-mime#mimedefinetypemap-force--false ) for more information.
155
162
156
163
### publicPath
157
164
Original file line number Diff line number Diff line change @@ -38,7 +38,9 @@ module.exports = function wdm(compiler, opts) {
38
38
39
39
// defining custom MIME type
40
40
if ( options . mimeTypes ) {
41
- mime . define ( options . mimeTypes ) ;
41
+ const typeMap = options . mimeTypes . typeMap || options . mimeTypes ;
42
+ const force = ! ! options . mimeTypes . force ;
43
+ mime . define ( typeMap , force ) ;
42
44
}
43
45
44
46
const context = createContext ( compiler , options ) ;
Original file line number Diff line number Diff line change @@ -245,6 +245,33 @@ describe('Server', () => {
245
245
} ) ;
246
246
} ) ;
247
247
248
+ describe ( 'force option for custom mimeTypes' , ( ) => {
249
+ before ( ( done ) => {
250
+ app = express ( ) ;
251
+ const compiler = webpack ( webpackClientServerConfig ) ;
252
+ instance = middleware ( compiler , {
253
+ stats : 'errors-only' ,
254
+ logLevel,
255
+ index : 'Index.phtml' ,
256
+ mimeTypes : {
257
+ typeMap : { 'text/html' : [ 'phtml' ] } ,
258
+ force : true
259
+ }
260
+ } ) ;
261
+ app . use ( instance ) ;
262
+ listen = listenShorthand ( done ) ;
263
+ instance . fileSystem . writeFileSync ( '/Index.phtml' , 'welcome' ) ;
264
+ } ) ;
265
+ after ( close ) ;
266
+
267
+ it ( 'request to Index.phtml' , ( done ) => {
268
+ request ( app ) . get ( '/' )
269
+ . expect ( 'welcome' )
270
+ . expect ( 'Content-Type' , / t e x t \/ h t m l / )
271
+ . expect ( 200 , done ) ;
272
+ } ) ;
273
+ } ) ;
274
+
248
275
describe ( 'WebAssembly' , ( ) => {
249
276
before ( ( done ) => {
250
277
app = express ( ) ;
You can’t perform that action at this time.
0 commit comments