Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option mimeTypesForce #349

Merged
merged 2 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,17 @@ Default: `null`

This property allows a user to register custom mime types or extension mappings.
eg. `{ 'text/html': [ 'phtml' ] }`. Please see the documentation for
[`node-mime`](https://github.com/broofa/node-mime#mimedefine) for more information.
[`node-mime`](https://github.com/broofa/node-mime#mimedefinetypemap-force--false) for more information.

### mimeTypesForce

Type: `Boolean`
Default: `false`

By default node-mime will throw an error if you try to map a type to an extension
that is already assigned to another type. Passing `true` will suppress this behavior
(overriding any previous mapping). Please see the documentation for
[`node-mime`](https://github.com/broofa/node-mime#mimedefinetypemap-force--false) for more information.

### publicPath

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const defaults = {
logTime: false,
logger: null,
mimeTypes: null,
mimeTypesForce: false,
reporter,
stats: {
colors: true,
Expand All @@ -38,7 +39,7 @@ module.exports = function wdm(compiler, opts) {

// defining custom MIME type
if (options.mimeTypes) {
mime.define(options.mimeTypes);
mime.define(options.mimeTypes, options.mimeTypesForce);
}

const context = createContext(compiler, options);
Expand Down
27 changes: 27 additions & 0 deletions test/tests/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,33 @@ describe('Server', () => {
});
});

describe('force option for custom mimeTypes', () => {
before((done) => {
app = express();
const compiler = webpack(webpackClientServerConfig);
instance = middleware(compiler, {
stats: 'errors-only',
logLevel,
index: 'Index.phtml',
mimeTypesForce: true,
mimeTypes: {
'text/html': ['phtml']
}
});
app.use(instance);
listen = listenShorthand(done);
instance.fileSystem.writeFileSync('/Index.phtml', 'welcome');
});
after(close);

it('request to Index.phtml', (done) => {
request(app).get('/')
.expect('welcome')
.expect('Content-Type', /text\/html/)
.expect(200, done);
});
});

describe('WebAssembly', () => {
before((done) => {
app = express();
Expand Down