{"id":20810898,"url":"https://github.com/exposedcat/rollup-plugin-string-import","last_synced_at":"2025-08-11T06:42:27.137Z","repository":{"id":252843497,"uuid":"841620592","full_name":"ExposedCat/rollup-plugin-string-import","owner":"ExposedCat","description":"Import any files as strings","archived":false,"fork":false,"pushed_at":"2024-10-27T11:19:06.000Z","size":65,"stargazers_count":4,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T08:21:14.970Z","etag":null,"topics":["import","library","plugin","rollup","rollup-plugin","string","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/rollup-plugin-string-import","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ExposedCat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-08-12T19:19:27.000Z","updated_at":"2025-01-24T21:05:52.000Z","dependencies_parsed_at":"2024-10-27T12:28:49.725Z","dependency_job_id":"d154bb46-5929-4802-a832-2f7336a85bc4","html_url":"https://github.com/ExposedCat/rollup-plugin-string-import","commit_stats":null,"previous_names":["exposedcat/rollup-plugin-string-import"],"tags_count":0,"template":false,"template_full_name":"ExposedCat/barebone-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExposedCat%2Frollup-plugin-string-import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExposedCat%2Frollup-plugin-string-import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExposedCat%2Frollup-plugin-string-import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExposedCat%2Frollup-plugin-string-import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ExposedCat","download_url":"https://codeload.github.com/ExposedCat/rollup-plugin-string-import/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252846105,"owners_count":21813378,"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":["import","library","plugin","rollup","rollup-plugin","string","typescript"],"created_at":"2024-11-17T20:28:40.671Z","updated_at":"2025-05-07T08:43:57.719Z","avatar_url":"https://github.com/ExposedCat.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[npm]: https://img.shields.io/npm/v/rollup-plugin-string-import\n[npm-url]: https://www.npmjs.com/package/rollup-plugin-string-import\n[size]: https://packagephobia.now.sh/badge?p=rollup-plugin-string-import\n[size-url]: https://packagephobia.now.sh/result?p=rollup-plugin-string-import\n\n[![npm][npm]][npm-url]\n[![size][size]][size-url]\n[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)\n\n# rollup-plugin-string-import\n\n🍣 A Rollup plugin to import any file as a string with proper TypeScript support\n\n## Requirements\n\nThis plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+.\n\n## Install\n\nUsing `npm`:\n\n```bash\nnpm install -D rollup-plugin-string-import\n```\n\nor `yarn`\n\n```bash\nyarn add -D rollup-plugin-string-import\n```\n\n## Usage\n\nCreate a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:\n\n```js\nimport { importAsString } from 'rollup-plugin-string-import';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    dir: 'output',\n    format: 'cjs',\n  },\n  plugins: [\n    importAsString({\n      include: ['**/*.txt', '**/*.frag', '**/*.vert'],\n      exclude: ['**/*.test.*'],\n    }),\n  ],\n};\n```\n\nThen call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).  \nIn runtime, all matching files will be imported as strings, same as if they were defined in TypeScript files like this:\n\n```typescript\nexport default `This is a\ntext file\ncontent!`;\n```\n\nOptionally, you can create a `.d.ts` file to let TypeScript know that such imports should be treated as strings:\n\n```typescript\n// string-import.d.ts\n\ndeclare module '*.txt' {\n  const file: string;\n  export default file;\n}\n\ndeclare module '*.vert' {\n  const file: string;\n  export default file;\n}\n\ndeclare module '*.frag' {\n  const file: string;\n  export default file;\n}\n```\n\n## Options\n\n### `include`\n\nType: `String` | `Array[...String]`\u003cbr\u003e\n\nA [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should operate on.\n\n### `exclude`\n\nType: `String` | `Array[...String]`\u003cbr\u003e\nDefault: `undefined`\n\nA [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored.\n\n### `transform`\n\nType: `(content: String, file: String) =\u003e String`\u003cbr\u003e\nDefault: `content =\u003e content`\n\nA transformer function that will be applied to each matched file. In this example, we append \"Hello World\" to each `.txt` file:\n\n```typescript\n...\n    importAsString({\n      include: ['**/*.txt', '**/*.frag', '**/*.vert'],\n      exclude: ['**/*.test.*'],\n      transform:\n        (content, file) =\u003e file.endsWith('.txt') ? `${content}\\nHello World` : content,\n    }),\n...\n```\n\n## Meta\n\nLicensed under the GPL version 3.0 or higher\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexposedcat%2Frollup-plugin-string-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexposedcat%2Frollup-plugin-string-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexposedcat%2Frollup-plugin-string-import/lists"}