{"id":13801895,"url":"https://github.com/digitalie/one-loader","last_synced_at":"2025-05-13T12:32:06.739Z","repository":{"id":22823484,"uuid":"97169536","full_name":"digitalie/one-loader","owner":"digitalie","description":"Single-file components for React","archived":false,"fork":false,"pushed_at":"2023-01-06T01:31:59.000Z","size":2697,"stargazers_count":236,"open_issues_count":52,"forks_count":20,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-15T08:05:51.446Z","etag":null,"topics":["components","react","single-file-component","webpack","webpack-loader"],"latest_commit_sha":null,"homepage":"","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/digitalie.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-07-13T22:25:01.000Z","updated_at":"2024-02-23T19:57:53.000Z","dependencies_parsed_at":"2023-01-13T22:17:05.987Z","dependency_job_id":null,"html_url":"https://github.com/digitalie/one-loader","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalie%2Fone-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalie%2Fone-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalie%2Fone-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalie%2Fone-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digitalie","download_url":"https://codeload.github.com/digitalie/one-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225217889,"owners_count":17439712,"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":["components","react","single-file-component","webpack","webpack-loader"],"created_at":"2024-08-04T00:01:29.441Z","updated_at":"2024-11-18T17:30:31.106Z","avatar_url":"https://github.com/digitalie.png","language":"JavaScript","readme":"[![npm][npm]][npm-url]\r\n[![build][build]][build-url]\r\n\r\n\u003cdiv align=\"center\"\u003e\r\n  \u003ca href=\"https://github.com/webpack/webpack\"\u003e\r\n    \u003cimg width=\"200\" height=\"200\"\r\n      src=\"https://webpack.js.org/assets/icon-square-big.svg\"\u003e\r\n  \u003c/a\u003e\r\n\u003c/div\u003e\r\n\r\n# One Loader\r\n\r\nA webpack loader to enable single-file React components.\r\nInspired by `vue-loader`.\r\n\r\n## Features\r\n\r\n* CSS and JavaScript code co-located in a single `.one` file (extension is configurable)\r\n* Configurable loaders for JavaScript and CSS\r\n* Support for scoped styles through CSS Modules (using `css-loader`)\r\n\r\n## Installation\r\n\r\n```bash\r\n$ npm i --save-dev one-loader\r\n```\r\n\r\n## Example\r\n\r\nIn `webpack.config.js`:\r\n\r\n```javascript\r\n{\r\n    module: {\r\n        loaders: [\r\n            {\r\n                test: /\\.one$/,\r\n                loader: 'one-loader',\r\n                options: {\r\n                    map: {\r\n                        'text/css': ['style-loader', 'css-loader'],\r\n                        'javascript': 'babel-loader'\r\n                    }\r\n                }\r\n            }\r\n        ]\r\n    }\r\n}\r\n```\r\n\r\nIn `ExampleComponent.one`:\r\n\r\n```html\r\n\u003cstyle\u003e\r\n    html {\r\n        background-color: green;\r\n    }\r\n\r\n    .basicExample {\r\n        color: white;\r\n    }\r\n\u003c/style\u003e\r\n\r\n\u003cscript\u003e\r\n    export default () =\u003e {\r\n        return \u003cdiv className=\"basicExample\"\u003e\r\n            Hello World\r\n        \u003c/div\u003e\r\n    }\r\n\u003c/script\u003e\r\n```\r\n\r\nMore examples are available in [examples](examples) directory:\r\n\r\n* [Simple Counter](examples/01_counter)\r\n* [Redux Todo List with extracted CSS file](examples/02_redux-todos)\r\n* [Redux Todo List with scoped CSS](examples/03_redux-todos-scoped)\r\n\r\n## Configuration\r\n\r\nThe `map` object in `one-loader` options is responsible for assigning loaders to code types in your single-file components.\r\n\r\nIf no mapping is provided `\u003cstyle\u003e` contents will be processed with `css-loader` and `\u003cscript\u003e` contents will remain unchanged.\r\nThese default values are defined in `options.js` file.\r\n\r\nThe `type` property can be used to assign custom types to `\u003cstyle\u003e` and `\u003cscript\u003e` tags:\r\n\r\n```html\r\n\u003cstyle type=\"text/less\"\u003e\r\n  .component {\r\n    text-align: center;\r\n  }\r\n\u003c/style\u003e\r\n\u003cscript type=\"es6\"\u003e\r\n\r\n\u003c/script\u003e\r\n```\r\n\r\nThere are no restrictions on type naming, so any string will work, however descriptive values are recommended.\r\n\r\n## Known issues\r\n\r\nThe internal architecture of the loader requires passing the options object to sub-loaders through a `require` string.\r\nThis is currently causing issues when defining `map` object loaders in strings with a `!` separator.\r\nThus array syntax is recommended for defining mapped loaders.\r\n\r\nThis will **NOT** work:\r\n\r\n```javascript\r\n{\r\n    module: {\r\n        loaders: [\r\n            {\r\n                test: /\\.one$/,\r\n                loader: 'one-loader',\r\n                options: {\r\n                    map: {\r\n                        'text/css': 'style-loader!css-loader',\r\n                        'javascript': 'babel-loader'\r\n                    }\r\n                }\r\n            }\r\n        ]\r\n    }\r\n}\r\n```\r\n\r\nThis will work:\r\n\r\n```javascript\r\n{\r\n    module: {\r\n        loaders: [\r\n            {\r\n                test: /\\.one$/,\r\n                loader: 'one-loader',\r\n                options: {\r\n                    map: {\r\n                        'text/css': ['style-loader', 'css-loader'],\r\n                        'javascript': 'babel-loader'\r\n                    }\r\n                }\r\n            }\r\n        ]\r\n    }\r\n}\r\n```\r\n\r\n\r\n## License\r\n\r\nMIT\r\n\r\n[npm]: https://img.shields.io/npm/v/one-loader.svg\r\n[npm-url]: https://npmjs.com/package/one-loader\r\n\r\n[build]: https://travis-ci.org/digitalie/one-loader.svg?branch=master\r\n[build-url]: https://travis-ci.org/digitalie/one-loader\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalie%2Fone-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigitalie%2Fone-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalie%2Fone-loader/lists"}