diff --git a/lib/karma-webpack.js b/lib/karma-webpack.js index ed10f58..ea8221a 100644 --- a/lib/karma-webpack.js +++ b/lib/karma-webpack.js @@ -2,6 +2,7 @@ const path = require('path'); const fs = require('fs'); const glob = require('glob'); +const minimatch = require('minimatch'); const { KarmaWebpackController } = require('./KarmaWebpackController'); @@ -36,21 +37,35 @@ function registerExtraWebpackFiles(config, _controller) { }); } -function preprocessorsToWebpackEntries(preprocessors) { +function configToWebpackEntries(config) { const filteredPatterns = []; + const { preprocessors } = config; + + let files = []; + config.files.forEach(fileEntry => { + files = [...files, ...glob.sync(fileEntry.pattern)]; + }); + Object.keys(preprocessors).forEach((pattern) => { if (preprocessors[pattern].includes('webpack')) { filteredPatterns.push(pattern); } }); - const webpackEntries = {}; - filteredPatterns.forEach((pattern) => { - const files = glob.sync(pattern); - files.forEach((filePath) => { - webpackEntries[path.parse(filePath).name] = filePath; + const filteredFiles = []; + files.forEach(filePath => { + filteredPatterns.forEach((pattern) => { + if (minimatch(filePath, pattern)) { + filteredFiles.push(filePath); + } }); }); + + const webpackEntries = {}; + filteredFiles.forEach((filePath) => { + webpackEntries[path.parse(filePath).name] = filePath; + }); + return webpackEntries; } @@ -58,7 +73,7 @@ function preprocessorFactory(config, emitter) { // one time setup if (controller.isActive === false) { controller.updateWebpackOptions({ - entry: preprocessorsToWebpackEntries(config.preprocessors), + entry: configToWebpackEntries(config), watch: config.autoWatch, }); controller.updateWebpackOptions(config.webpack); @@ -80,4 +95,5 @@ module.exports = { 'preprocessor:webpack': ['factory', preprocessorFactory], 'framework:webpack': ['factory', registerExtraWebpackFiles], registerExtraWebpackFiles, + configToWebpackEntries, }; diff --git a/package-lock.json b/package-lock.json index f0c3d72..cfd94af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -923,7 +923,6 @@ "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", "integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=", "dev": true, - "optional": true, "requires": { "kind-of": "^3.0.2", "longest": "^1.0.1", @@ -1332,15 +1331,13 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-1.0.0.tgz", "integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA=", - "dev": true, - "optional": true + "dev": true }, "is-glob": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz", "integrity": "sha1-0Jb5JqPe1WAPP9/ZEZjLCIjC2GM=", "dev": true, - "optional": true, "requires": { "is-extglob": "^1.0.0" } @@ -6033,8 +6030,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -6055,14 +6051,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -6077,20 +6071,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -6207,8 +6198,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -6220,7 +6210,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -6235,7 +6224,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -6243,14 +6231,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -6269,7 +6255,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -6350,8 +6335,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -6363,7 +6347,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -6449,8 +6432,7 @@ "safe-buffer": { "version": "5.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -6486,7 +6468,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -6506,7 +6487,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -6550,14 +6530,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, @@ -10952,8 +10930,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=", - "dev": true, - "optional": true + "dev": true }, "loose-envify": { "version": "1.3.1", diff --git a/package.json b/package.json index fe74cbf..716f6e9 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ }, "dependencies": { "glob": "^7.1.3", + "minimatch": "^3.0.4", "webpack-merge": "^4.1.5" }, "devDependencies": {