Skip to content

Add extensions option to enable configurable file extension matching #8

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 15 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
'use strict';

let path = require('path');
const pluginName = "bower-resolve-webpack-plugin";
const path = require('path');
const pluginName = 'bower-resolve-webpack-plugin';

const defaultOptions = {
extensions: ['.js']
};

function matchModule(filename, extensions) {
const ext = path.extname(filename);
return extensions.includes(ext);
}

module.exports = class BowerResolvePlugin {
constructor(options) {
this.options = options;
}
this.options = Object.assign({}, defaultOptions, options);
}

apply(resolver) {
// Webpack 4
Expand All @@ -28,7 +37,7 @@ module.exports = class BowerResolvePlugin {
return callback();
}

mainModule = modules.find(module => module.endsWith('.js'));
mainModule = modules.find(module => matchModule(module, this.options.extensions));
}

if (!mainModule) {
Expand Down Expand Up @@ -60,7 +69,7 @@ module.exports = class BowerResolvePlugin {
return callback();
}

mainModule = modules.find(module => module.endsWith('.js') );
mainModule = modules.find(module => matchModule(module, this.options.extensions));
}

if (! mainModule) {
Expand Down