2.0.0 • Published 8 months ago

virtual-resource-loader v2.0.0

Weekly downloads
1,706
License
MIT
Repository
github
Last release
8 months ago

virtual-resource-loader

virtual-resource-loader allows you to create new modules inside a webpack compilation, without a file existing on disk. This is achieved in combination with webpack's matchResource feature.

Usage

// example-loader.js
export default function exampleLoader() {
  const virtualModuleSourceCode = '...';

  const base64Source = Buffer.from(
    JSON.stringify(virtualModuleSourceCode),
    'utf-8'
  ).toString('base64');

  const request = `./my-virtual-file!=!virtual-resource-loader?source=${base64Source}!${loader.resourcePath}`;

  return `
    import ${request};
  `;
}