Skip to content

Commit

Permalink
fix: mimic webpack cli for stats
Browse files Browse the repository at this point in the history
  • Loading branch information
daKmoR committed Dec 11, 2018
1 parent 8f08ba4 commit bf966f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
27 changes: 11 additions & 16 deletions lib/KarmaWebpackController.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ class KarmaSyncPlugin {

// webpack bundles are finished
compiler.hooks.done.tap('KarmaSyncPlugin', async (stats) => {
// show quiter output with colors
console.log(
stats.toString({
chunks: false,
colors: true,
})
);

// read generated file content and store for karma preprocessor
this.controller.bundlesContent = {};
stats.toJson().assets.forEach((webpackFileObj) => {
Expand All @@ -50,6 +42,10 @@ const defaultWebpackOptions = {
filename: '[name].js',
path: path.join(os.tmpdir(), '_karma_webpack_'),
},
stats: {
modules: false,
colors: true,
},
watch: false,
optimization: {
runtimeChunk: 'single',
Expand Down Expand Up @@ -107,21 +103,18 @@ class KarmaWebpackController {
}

get outputPath() {
return this.__webpackOptions.output.path;
return this.webpackOptions.output.path;
}

constructor() {
this.isActive = false;
this.bundlesContent = {};
this.__debounce = false;
this.__webpackOptions = defaultWebpackOptions;
this.webpackOptions = defaultWebpackOptions;
}

updateWebpackOptions(newOptions) {
this.__webpackOptions = merge(
this.__webpackOptions,
newOptions
);
this.webpackOptions = merge(this.webpackOptions, newOptions);
}

async bundle() {
Expand All @@ -135,9 +128,9 @@ class KarmaWebpackController {
async _bundle() {
this.isActive = true;
this.__debounce = true;
this.compiler = webpack(this.__webpackOptions);
this.compiler = webpack(this.webpackOptions);
return new Promise((resolve) => {
if (this.__webpackOptions.watch === true) {
if (this.webpackOptions.watch === true) {
console.log('Webpack starts watching...');
this.webpackFileWatcher = this.compiler.watch({}, (err, stats) =>
this.handleBuildResult(err, stats, resolve)
Expand Down Expand Up @@ -169,6 +162,8 @@ class KarmaWebpackController {

this.__debounce = setTimeout(() => (this.__debounce = false), 100);
this.isActive = false;

console.log(stats.toString(this.webpackOptions.stats));
resolve();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/karma-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function configToWebpackEntries(config) {
const { preprocessors } = config;

let files = [];
config.files.forEach(fileEntry => {
config.files.forEach((fileEntry) => {
files = [...files, ...glob.sync(fileEntry.pattern)];
});

Expand All @@ -53,7 +53,7 @@ function configToWebpackEntries(config) {
});

const filteredFiles = [];
files.forEach(filePath => {
files.forEach((filePath) => {
filteredPatterns.forEach((pattern) => {
if (minimatch(filePath, pattern)) {
filteredFiles.push(filePath);
Expand Down

0 comments on commit bf966f0

Please sign in to comment.