Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(loader): pass emitFile to the child compilation (`loaderContext…
….emitFile`) (#177)
  • Loading branch information
piecyk authored and michael-ciniawsky committed Sep 18, 2018
1 parent 5304463 commit 18c066e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.js
Expand Up @@ -146,6 +146,7 @@ class MiniCssExtractPlugin {
)}`
);
}

const identifierCountMap = new Map();
for (const line of content) {
const count = identifierCountMap.get(line.identifier) || 0;
Expand Down
1 change: 1 addition & 0 deletions src/loader.js
Expand Up @@ -59,6 +59,7 @@ export function pitch(request) {
compilation.hooks.normalModuleLoader.tap(
`${pluginName} loader`,
(loaderContext, module) => {
loaderContext.emitFile = this.emitFile;
loaderContext[MODULE_TYPE] = false; // eslint-disable-line no-param-reassign
if (module.request === request) {
// eslint-disable-next-line no-param-reassign
Expand Down
39 changes: 39 additions & 0 deletions test/TestMemoryFS.test.js
@@ -0,0 +1,39 @@
import path from 'path';

import MemoryFS from 'memory-fs';
import webpack from 'webpack';

const assetsNames = (json) => json.assets.map((asset) => asset.name);

describe('TestMemoryFS', () => {
it('should preserve asset even if not emitted', (done) => {
const casesDirectory = path.resolve(__dirname, 'cases');
const directoryForCase = path.resolve(casesDirectory, 'simple-publicpath');
const webpackConfig = require(path.resolve(
directoryForCase,
'webpack.config.js'
));
const compiler = webpack({
...webpackConfig,
mode: 'development',
context: directoryForCase,
});
compiler.outputFileSystem = new MemoryFS();
compiler.run((err1, stats1) => {
if (err1) {
done(err1);
return;
}
compiler.run((err2, stats2) => {
if (err2) {
done(err2);
return;
}
expect(assetsNames(stats1.toJson())).toEqual(
assetsNames(stats2.toJson())
);
done();
});
});
});
});

0 comments on commit 18c066e

Please sign in to comment.