Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(loader): pass emitFile to the child compilation (loaderContext.emitFile) #177

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
});
});
});