{"id":21352130,"url":"https://github.com/static-dev/source-loader","last_synced_at":"2025-07-12T20:32:05.637Z","repository":{"id":57366473,"uuid":"58774445","full_name":"static-dev/source-loader","owner":"static-dev","description":"Webpack loader that directly exports the source of whatever file it's passed","archived":false,"fork":false,"pushed_at":"2019-02-07T09:37:22.000Z","size":2613,"stargazers_count":4,"open_issues_count":7,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-09T15:49:13.172Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/static-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-13T21:49:15.000Z","updated_at":"2018-11-06T04:40:29.000Z","dependencies_parsed_at":"2022-08-23T19:50:19.280Z","dependency_job_id":null,"html_url":"https://github.com/static-dev/source-loader","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/static-dev%2Fsource-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/static-dev%2Fsource-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/static-dev%2Fsource-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/static-dev%2Fsource-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/static-dev","download_url":"https://codeload.github.com/static-dev/source-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225465308,"owners_count":17478520,"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":[],"created_at":"2024-11-22T03:12:45.303Z","updated_at":"2024-11-22T03:12:46.019Z","avatar_url":"https://github.com/static-dev.png","language":"JavaScript","readme":"# Webpack Source Loader\n\n[![npm](http://img.shields.io/npm/v/source-loader.svg?style=flat)](https://badge.fury.io/js/source-loader) [![tests](http://img.shields.io/travis/static-dev/source-loader/master.svg?style=flat)](https://travis-ci.org/static-dev/source-loader) [![dependencies](http://img.shields.io/david/static-dev/source-loader.svg?style=flat)](https://david-dm.org/static-dev/source-loader) [![coverage](http://img.shields.io/coveralls/static-dev/source-loader.svg?style=flat)](https://coveralls.io/github/static-dev/source-loader)\n\nWebpack loader that exports the source directly\n\n\u003e **Note:** This project is in early development, and versioning is a little different. [Read this](http://markup.im/#q4_cRZ1Q) for more details.\n\n### Why should you care?\n\nIf you need to load up a file's source directly and have it available within your javascript, this loader is what you're after. For example, you could load up a svg file, parse out a path you want, and manipulate that with your javascript somehow. Or you could load up a json or text file. Or some other type of file that you came up with yourself. Whatever it is, as long as it's contents would be ok after being run through `JSON.stringify` (read: text files, not images or binary files), it will work just great with the source loader. And if it is a binary file, it will work great as well, but you won't be able to require it in your client-side js, just manipulate it through a plugin.\n\n### Installation\n\n`npm install source-loader -S`\n\n### Usage\n\nJust load it up in your webpack config like this:\n\n```js\nmodule.exports = {\n  module: {\n    loaders: [\n      { test: /\\.foo$/, loader: 'source-loader' }\n    ]\n  }\n}\n```\n\nThen you can require it up in your main entry:\n\n```js\nconst fooFile = require('testing.foo')\nconsole.log(fooFile) // wow it's the contents!\n```\n\nAs an added bonus, this loader makes the buffered raw source available on the `loaderContext` object so that plugins can manipulate it in any way necessary.\n\nLet's break down how this could be done. Inside any plugin hook, you have a `compilation` object. You can get the `loaderContext` for any of the modules that webpack is processing through `compilation.modules` -- just find the one(s) you want by name. Now you have a large object which is an instance of the `DependenciesBlock` class, with a bunch of great information on it. You can find the raw buffered source under the `_src` property if the file was loaded with the source-loader.\n\nAdditionally, if you have a specific source that is valid javascript and you'd like this loader not to output it as a string that would need to be eval'd in order to use the javascript, there's a hack for that. Within a plugin or another loader, if you add `_jsSource` as a truthy property to the module, it will skip the extra stringification and output the source raw. Note that you will get an error if it's not valid javascript, so make sure you are only setting the `_jsSource` property if you are positive that what is coming out of your loader chain is going to be js. To set from a loader, `this._module._jsSource = true` will do it, and from a plugin, you can do the same as is described above with the `_src` property.\n\nWondering what sets this loader apart from [raw-loader](https://github.com/webpack/raw-loader)? This is it. Both loaders expose the file's contents to be required by webpack, but this loader also exposes the raw source for plugin processing, and allows raw js to be passed through conditionally. It also does not try to stringify binary files (which can cause bugs), has tests, and is actively maintained, as a bonus.\n\n### License \u0026 Contributing\n\n- Details on the license [can be found here](LICENSE.md)\n- Details on running tests and contributing [can be found here](contributing.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatic-dev%2Fsource-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatic-dev%2Fsource-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatic-dev%2Fsource-loader/lists"}