/
userDepsLoader.ts
23 lines (20 loc) · 1.23 KB
/
userDepsLoader.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { detectCosmosConfig } from '../../../config';
import { DomRendererConfig } from '../../../shared/rendererConfig';
import { generateUserDepsModule } from '../../../shared/userDeps';
import { createDomCosmosConfig } from '../cosmosConfig/dom';
import { loader } from 'webpack';
module.exports = function injectUserDeps(this: loader.LoaderContext) {
const cosmosConfig = detectCosmosConfig();
// This ensures this loader is invalidated whenever a new file is added to or
// removed from user's project, which in turn triggers react-cosmos-voyager2
// to detect fixture files and finally update fixture list inside Playground.
// Note that while this may not be very performant, it's not the equivalent
// of require.context, which not only watches for file changes but also
// automatically bundles new files that match the watcher's query.
// https://github.com/webpack/webpack/issues/222#issuecomment-40691546
const watchDirs = cosmosConfig.watchDirs;
watchDirs.forEach(watchDir => this.addContextDependency(watchDir));
const { containerQuerySelector } = createDomCosmosConfig(cosmosConfig);
const rendererConfig: DomRendererConfig = { containerQuerySelector };
return generateUserDepsModule(cosmosConfig, rendererConfig);
};