Skip to content
Merged
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
17 changes: 13 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class VirtualModulePlugin {
contents = JSON.stringify(this.options.contents);
}
if (typeof this.options.contents === 'function') {
//call then function must be return string
// call then function must be return string
contents = this.options.contents();
}

Expand All @@ -39,10 +39,19 @@ class VirtualModulePlugin {
if (!modulePath) {
modulePath = this.join(compiler.context, moduleName);
}
VirtualModulePlugin.populateFilesystem({ fs, modulePath, contents, ctime });
if (cb) {
cb();

const resolve = (data) => {
VirtualModulePlugin.populateFilesystem({ fs, modulePath, contents: data, ctime });
};

if (!cb) {
resolve(contents);
return;
}

Promise.resolve(contents)
.then(resolve)
.then(cb);
}

if (!compiler.resolvers.normal) {
Expand Down
1 change: 1 addition & 0 deletions test/integration/cases/contents-async/expected/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a
4 changes: 4 additions & 0 deletions test/integration/cases/contents-async/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

// eslint-disable-next-line import/no-unresolved
require('./a.txt');
21 changes: 21 additions & 0 deletions test/integration/cases/contents-async/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const ExtractTextPlugin = require('extract-text-webpack-plugin');
const VirtualModulePlugin = require('../../../../index');

function contents() {
return Promise.resolve('a');
}

module.exports = function webpackConfig() {
return {
entry: './index',
plugins: [
new VirtualModulePlugin({
moduleName: './a.txt',
contents,
}),
new ExtractTextPlugin('file.txt'),
],
};
};