index.js 580 B

12345678910111213141516171819202122
  1. const {
  2. NodeJsInputFileSystem,
  3. CachedInputFileSystem,
  4. ResolverFactory
  5. } = require('enhanced-resolve')
  6. module.exports = (config = {}) => {
  7. const defaultConfig = {
  8. extensions: ['.css'],
  9. mainFields: ['style', 'main'],
  10. modules: ['node_modules'],
  11. fileSystem: config.fileSystem
  12. ? null
  13. : new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000),
  14. useSyncFileSystemCalls: true
  15. }
  16. const resolver = ResolverFactory.createResolver(
  17. Object.assign(defaultConfig, config)
  18. )
  19. return (id, basedir) => resolver.resolveSync({}, basedir, id)
  20. }