{"id":19578039,"url":"https://github.com/thelarkinn/virtual-dependency-loader","last_synced_at":"2025-09-27T20:30:54.577Z","repository":{"id":57392753,"uuid":"101679542","full_name":"TheLarkInn/virtual-dependency-loader","owner":"TheLarkInn","description":"webpack loader that takes a single file, and declare pieces of that file as \"dependencies\" as if it existed.","archived":false,"fork":false,"pushed_at":"2017-08-29T05:20:49.000Z","size":66,"stargazers_count":33,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-10T20:11:28.310Z","etag":null,"topics":["javascript","single-file-components","webpack","webpack-loader"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheLarkInn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-28T19:23:38.000Z","updated_at":"2019-09-19T04:54:38.000Z","dependencies_parsed_at":"2022-08-27T01:53:04.140Z","dependency_job_id":null,"html_url":"https://github.com/TheLarkInn/virtual-dependency-loader","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheLarkInn%2Fvirtual-dependency-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheLarkInn%2Fvirtual-dependency-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheLarkInn%2Fvirtual-dependency-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheLarkInn%2Fvirtual-dependency-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheLarkInn","download_url":"https://codeload.github.com/TheLarkInn/virtual-dependency-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234296514,"owners_count":18810009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","single-file-components","webpack","webpack-loader"],"created_at":"2024-11-11T07:09:28.687Z","updated_at":"2025-09-27T20:30:49.315Z","avatar_url":"https://github.com/TheLarkInn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# virtual-dependency-loader\nTake a single file, process pieces of that file as \"dependencies\" in loader chain. This is traditionally leveraged inside of other loaders.\n\n## Usage\n\n### Installation\n`npm install --save virtual-dependency-loader`\n\n### Inside of another loader implementation\n**loader.js**\n```javascript\nimport querystring from 'querystring';\nimport {stringifyRequest} from 'loader-utils';\n\nexport default function someLoader(source, map, ast) {\n  const [normalSource, virtualizedSource] = source.split(\"__virtual_dependency__\");\n  const {loadModule, resourcePath, async} = this;\n  const callback = async();\n  const dummyFilePath = path.resolve(__dirname, \"../dummy-file.js\");\n\n  const inlineLoaderOptions = queryString.stringify({\n    code: virtualizedSource,\n    filename: `${resourcePath}.script.js`\n  });\n\n  const resource = stringifyRequest(`virtual-dependency-loader?${inlineLoaderOptions}!${dummyFilePath}`)\n\n  const virtualizedSourceProcessedByOtherLoaders = loadModule(resource, (err, code, map) =\u003e {\n    const newSource = [normalSource, code].join(\"__virtual_dependency__\");\n\n    callback(null, newSource);\n  });\n};\n```\n\n**file-that-was-ran-through-loader.js**\n```javascript\nvar hello = \"hello\";\n\n/* __virtual_dependency__ */\nclass Bar {\n  constructor(foo) {\n    this.foo = foo;\n  };\n\n  print() {\n    console.log(this.foo);\n  }\n}\n\nconst baz = new Bar(hello);\n```\n\n## Credit\nHats off to Jason Miller for this idea while he was working on his (vue/polymer/sfc)=\u003epreact compiler/loader. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthelarkinn%2Fvirtual-dependency-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthelarkinn%2Fvirtual-dependency-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthelarkinn%2Fvirtual-dependency-loader/lists"}