Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Packages can now be excluded with excludePackages #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ The plugin takes options object as its single argument.

* `excludes` {`RegExp[]` or `RegExp`} - the plugin will match files contained in a manifest, and will exclude all files, which match any of the expressions.

* `excludePackages` {`string[]` or `string`} - the plugin will match packages names contained in a manifest, and will exclude all packages with the same name.

* `searchResolveModulesDirectories` {`boolean`} - if `false`, the plugin will not search [`resolve.modulesDirectories`](http://webpack.github.io/docs/configuration.html#resolve-modulesdirectories) for bower components.

Using the plugin, without specifying the configuration is equivalent to following:
Expand All @@ -50,6 +52,7 @@ plugins: [
manifestFiles: "bower.json",
includes: /.*/,
excludes: [],
excludePackages: [],
searchResolveModulesDirectories: true
})
]
Expand Down
4 changes: 3 additions & 1 deletion lib/bower-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function BowerWebpackPlugin(options) {
this.manifestFiles = opt.manifestFiles ? [].concat(opt.manifestFiles) : ["bower.json"];
this.includes = opt.includes ? [].concat(opt.includes) : [/.*/];
this.excludes = opt.excludes ? [].concat(opt.excludes) : [];
this.excludePackages = opt.excludePackages ? [].concat(opt.excludePackages) : [];
this.searchResolveModulesDirectories = opt.searchResolveModulesDirectories === false ? false : true;
}

Expand All @@ -65,6 +66,7 @@ BowerWebpackPlugin.prototype.apply = function (compiler) {
manifestFiles = this.manifestFiles,
includes = this.includes,
excludes = this.excludes,
excludePackages = this.excludePackages,
manifestMainFiles = {};

compiler.resolvers.normal.plugin('module', function (request, finalCallback) {
Expand All @@ -75,7 +77,7 @@ BowerWebpackPlugin.prototype.apply = function (compiler) {

// the plugin does not support modules with slashes - no nesting here...
// e.g. require('some-module/whatever'); will not be resolved
if (request.request.indexOf('/') >= 0) {
if (request.request.indexOf('/') >= 0 || excludePackages.indexOf(request.request) >= 0) {
return finalCallback();
}

Expand Down
61 changes: 61 additions & 0 deletions test/package-exclusions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Lukasz Piepiora <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

var testUtils = require('./test-utils');

var BowerWebpackPlugin = require("../");

testUtils.describe("resolving of modules, with exclusion of unwanted packages", function () {
var config = testUtils.config;
var testBowerPlugin = testUtils.testBowerPlugin;

it("should exclude unwanted packages based on the package name (string test)", function (done) {
var expectations = {
js: [],
css: []
};

var cfg = config("module-single-array");
cfg.plugins = [
new BowerWebpackPlugin({excludePackage: "module-single-array"})
];

testBowerPlugin(cfg, expectations, done);
});

it("should exclude unwanted files based on the package name (array test)", function (done) {
var expectations = {
js: [],
css: []
};

var cfg = config("module-single-array");
cfg.plugins = [
new BowerWebpackPlugin({excludePackage: ["module-single-array", "module-multiple-js"]})
];

testBowerPlugin(cfg, expectations, done);
});

});