{"id":17375827,"url":"https://github.com/notlmn/rollup-plugin-transform-tagged-template","last_synced_at":"2025-04-15T07:20:52.689Z","repository":{"id":65412146,"uuid":"274336403","full_name":"notlmn/rollup-plugin-transform-tagged-template","owner":"notlmn","description":"Apply transformations on static contents of tagged template string literals","archived":false,"fork":false,"pushed_at":"2023-12-31T13:00:30.000Z","size":11,"stargazers_count":5,"open_issues_count":3,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T21:53:23.592Z","etag":null,"topics":["rollup","rollup-plugin","tagged-template-string-literals","template-literals","template-strings"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/rollup-plugin-transform-tagged-template","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/notlmn.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":"https://paypal.me/bytemode"}},"created_at":"2020-06-23T07:18:00.000Z","updated_at":"2023-12-29T23:24:51.000Z","dependencies_parsed_at":"2023-01-22T07:35:15.293Z","dependency_job_id":null,"html_url":"https://github.com/notlmn/rollup-plugin-transform-tagged-template","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notlmn%2Frollup-plugin-transform-tagged-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notlmn%2Frollup-plugin-transform-tagged-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notlmn%2Frollup-plugin-transform-tagged-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notlmn%2Frollup-plugin-transform-tagged-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/notlmn","download_url":"https://codeload.github.com/notlmn/rollup-plugin-transform-tagged-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249023981,"owners_count":21200003,"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":["rollup","rollup-plugin","tagged-template-string-literals","template-literals","template-strings"],"created_at":"2024-10-16T04:03:52.392Z","updated_at":"2025-04-15T07:20:52.673Z","avatar_url":"https://github.com/notlmn.png","language":"JavaScript","funding_links":["https://paypal.me/bytemode"],"categories":[],"sub_categories":[],"readme":"# rollup-plugin-transform-tagged-template\n\n\u003e Apply transformations on contents of [tagged template string literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals), aka. template strings aka. template literals.\n\n[![npm](https://img.shields.io/npm/v/rollup-plugin-transform-tagged-template)](https://www.npmjs.com/package/rollup-plugin-transform-tagged-template)\n\n## Usage\n\n``` js\n// rollup.config.js\nimport transformTaggedTemplate from 'rollup-plugin-transform-tagged-template';\n\nexport default {\n\tinput: 'test.js',\n\tplugins: [\n\t\ttransformTaggedTemplate({\n\t\t\ttagsToProcess: ['css'],\n\t\t\ttransformer(data) {\n\t\t\t\t// Spaces before and after these characters\n\t\t\t\tdata = data.replace(/\\s*([{}()\u003e~+=^$:!;])\\s*/gm, '$1');\n\n\t\t\t\t// Spaces only after these characters\n\t\t\t\tdata = data.replace(/([\",\\[\\]])\\s+/gm, '$1');\n\n\t\t\t\t// You only need one space consequent in CSS\n\t\t\t\tdata = data.replace(/\\s{2,}/gm, ' ');\n\n\t\t\t\treturn data.trim();\n\t\t\t}\n\t\t})\n\t],\n\toutput: {\n\t\tfile: 'build.js'\n\t}\n};\n```\n\n## API\n\n### `tagsToProces: string[]`\n\nRefers to the tag names that are to be processed. In the example above, `css` is the tag that is processed.\n\nExample: `tagsToProcess: ['handleCSS']` would target the following template literal.\n\n``` js\nconst result = handleCSS`\n\t:host {\n\t\tdisplay: block;\n\t}\n`;\n```\n\n### `transformer: (string) =\u003e string`\n\nDoes what it says, one-to-one mapping of part of a template string.\n\n\u003e This could sometimes be only part of what you are expecting to get as argument. See example below.\n\nExample:\n\n``` js\n// code.js\nconst declaration = handleCSS`color: #212121;`;\nconst result = handleCSS`\n\t:host {\n\t\tdisplay: block;\n\t\t${declaration}\n\t}\n`;\n```\n\n``` js\n// rollup.js\n\t// ...\n\tplugins: [\n\t\ttransformTaggedTemplate({\n\t\t\ttagsToProcess: ['handleCSS'],\n\t\t\ttransformer(data) {\n                console.log(data);\n\t\t\t\treturn data;\n\t\t\t}\n\t\t})\n\t],\n\t// ...\n\n// Output\n[\n\t'color: #212121;',\n\t'\\n\\t:host {\\n\\t\\tdisplay: block;\\n\\t\\t',\n\t'\\n\\t\\t}\\n',\n]\n```\n\n### `parserOptions: object`\n\nConfig options to pass to the Babel parser.\n\n\u003e Babel Parser options may be needed depending on how your project is structured. See [Babel parser options](https://babeljs.io/docs/en/babel-parser#options) for all available options.\n\nExample:\n\n```js\n// rollup.js\n\t// ...\n\tplugins: [\n\t\ttransformTaggedTemplate({\n\t\t\tparserOptions: {\n\t\t\t\tsourceType: \"module\", // treat files as ES6 modules\n\t\t\t\tplugins: [\n\t\t\t\t\t\"typescript\", // parse the file as TypeScript\n\t\t\t\t\t[\n\t\t\t\t\t\t\"decorators\", // use decorators proposal plugin\n\t\t\t\t\t\t{ decoratorsBeforeExport: true }\n\t\t\t\t\t]\n\t\t\t\t]\n\t\t\t}\n\t\t})\n\t],\n\t// ...\n```\n\n## Related\n\n- [rollup-plugin-minify-tagged-css-template](https://github.com/notlmn/rollup-plugin-minify-tagged-css-template) - Rollup plugin to minify CSS content of tagged template string literals.\n\n## License\n\n[MIT](license) \u0026copy; Laxman Damera\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotlmn%2Frollup-plugin-transform-tagged-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotlmn%2Frollup-plugin-transform-tagged-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotlmn%2Frollup-plugin-transform-tagged-template/lists"}