{"id":19125135,"url":"https://github.com/shoonia/parcel-transformer-css-to-string","last_synced_at":"2025-07-24T06:07:06.070Z","repository":{"id":38017797,"uuid":"398054466","full_name":"shoonia/parcel-transformer-css-to-string","owner":"shoonia","description":"Importing CSS files as a string to JavaScript (Support Parcel v2)","archived":false,"fork":false,"pushed_at":"2024-02-12T15:14:36.000Z","size":254,"stargazers_count":3,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-05T20:14:26.896Z","etag":null,"topics":["css","parcel-plugin","parcel-transformer","parcelv2","postcss"],"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/shoonia.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-19T19:32:35.000Z","updated_at":"2023-12-18T19:08:11.000Z","dependencies_parsed_at":"2024-11-09T05:34:44.060Z","dependency_job_id":"38295263-b3d1-4931-b26e-8d6c08cff197","html_url":"https://github.com/shoonia/parcel-transformer-css-to-string","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shoonia/parcel-transformer-css-to-string","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoonia%2Fparcel-transformer-css-to-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoonia%2Fparcel-transformer-css-to-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoonia%2Fparcel-transformer-css-to-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoonia%2Fparcel-transformer-css-to-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shoonia","download_url":"https://codeload.github.com/shoonia/parcel-transformer-css-to-string/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoonia%2Fparcel-transformer-css-to-string/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266801538,"owners_count":23986372,"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","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["css","parcel-plugin","parcel-transformer","parcelv2","postcss"],"created_at":"2024-11-09T05:34:40.165Z","updated_at":"2025-07-24T06:07:06.049Z","avatar_url":"https://github.com/shoonia.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parcel-transformer-css-to-string\n\n[![support parcel v2](https://img.shields.io/badge/Parcel-v2-3638f4)](https://github.com/parcel-bundler/parcel)\n[![ci status](https://github.com/shoonia/parcel-transformer-css-to-string/actions/workflows/ci.yml/badge.svg)](https://github.com/shoonia/parcel-transformer-css-to-string/actions/workflows/ci.yml)\n[![npm version](https://img.shields.io/npm/v/parcel-transformer-css-to-string.svg)](https://www.npmjs.com/package/parcel-transformer-css-to-string)\n\nImporting CSS files as a string to JavaScript.\n\nTransform plugin for **Parcel v2**\n\n\u003e Support **Parcel v1**: [parcel-plugin-css-to-string](https://github.com/shoonia/parcel-plugin-css-to-string)\n\n## Example\n\n**styles.inline.css**\n\n```css\n.text {\n  color: #000000;\n}\n```\n\n**index.js**\n\n```js\nimport styles from './styles.inline.css';\n\ndocument.body.insertAdjacentHTML('beforeend', `\u003cstyle\u003e${styles}\u003c/style\u003e`);\n```\n\n**Result:**\n\n```js\ndocument.body.insertAdjacentHTML(\"beforeend\",\"\u003cstyle\u003e.text{color:#000}\u003c/style\u003e\");\n//# sourceMappingURL=index.js.map\n```\n\n## Install\n\n```bash\nnpm i parcel-transformer-css-to-string\n# or\nyarn add -D parcel-transformer-css-to-string\n```\n\n## How to use\n\nAdd the plugin to `transformers` section in your `.parcelrc`.\n\nIn example use a [Glob](https://en.wikipedia.org/wiki/Glob_(programming)) pattern for `*.inline.css` files that will be inlined as a string into JavaScript.\n\n**.parcelrc**\n\n```json\n{\n  \"extends\": \"@parcel/config-default\",\n  \"transformers\": {\n    \"*.inline.css\": [\n      \"parcel-transformer-css-to-string\"\n    ]\n  }\n}\n```\n\n## Minify config\n\nYou can configure minify CSS in production build, where custom configuration can be set by creating `cssnano.config.js` file\n\n**cssnano.config.js**\n\n```js\nmodule.exports = {\n  preset: [\n    \"default\",\n    {\n      calc: false,\n      discardComments: {\n        removeAll: true,\n      },\n    },\n  ],\n}\n```\n\n## PostCSS\n\nYou can configure CSS transforming with PostCSS creating a configuration file using one of these names (in that priority): `.postcssrc` (JSON), `.postcssrc.json`, `.postcssrc.js`, or `postcss.config.js`.\n\n\u003e If you use PostCSS config then you need added `cssnano` plugin to minify production build.\n\n**.postcssrc**\n\n```js\n{\n  \"plugins\": {\n    \"postcss-import\": {},\n    \"autoprefixer\": {},\n    \"cssnano\": {}\n  }\n}\n```\n\n## Alternative\n\nYou can use official build-in named pipelines `bundle-text:`. In this case Parcel create a JavaScript module.\n\n**style.css**\n\n```css\n.text {\n  color: #000000;\n}\n```\n\n**index.js**\n\n```js\nimport styles from 'bundle-text:./styles.css';\n\ndocument.body.insertAdjacentHTML('beforeend', `\u003cstyle\u003e${styles}\u003c/style\u003e`);\n```\n\n**Reslut:**\n\n```js\nfunction e(e){return e\u0026\u0026e.__esModule?e.default:e}document.body.insertAdjacentHTML(\"beforeend\",`\u003cstyle\u003e${e(\".text{color:#000}\")}\u003c/style\u003e`);\n//# sourceMappingURL=index.js.map\n```\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshoonia%2Fparcel-transformer-css-to-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshoonia%2Fparcel-transformer-css-to-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshoonia%2Fparcel-transformer-css-to-string/lists"}