{"id":14967545,"url":"https://github.com/bluewings/pug-as-jsx-loader","last_synced_at":"2025-04-07T09:22:28.581Z","repository":{"id":15155795,"uuid":"77661138","full_name":"bluewings/pug-as-jsx-loader","owner":"bluewings","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-06T01:52:24.000Z","size":20369,"stargazers_count":188,"open_issues_count":35,"forks_count":15,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-30T02:28:21.426Z","etag":null,"topics":["jade","jsx","loader","pug","react","webpack","webpack-loader"],"latest_commit_sha":null,"homepage":null,"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/bluewings.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":"2016-12-30T04:49:11.000Z","updated_at":"2024-07-12T19:31:18.000Z","dependencies_parsed_at":"2023-01-11T20:22:57.081Z","dependency_job_id":null,"html_url":"https://github.com/bluewings/pug-as-jsx-loader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluewings%2Fpug-as-jsx-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluewings%2Fpug-as-jsx-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluewings%2Fpug-as-jsx-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluewings%2Fpug-as-jsx-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bluewings","download_url":"https://codeload.github.com/bluewings/pug-as-jsx-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247623001,"owners_count":20968579,"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":["jade","jsx","loader","pug","react","webpack","webpack-loader"],"created_at":"2024-09-24T13:38:14.403Z","updated_at":"2025-04-07T09:22:28.530Z","avatar_url":"https://github.com/bluewings.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pug-as-jsx loader for webpack\r\n\r\n[![npm version](https://badge.fury.io/js/pug-as-jsx-loader.svg)](https://badge.fury.io/js/pug-as-jsx-loader)\r\n\r\n[![npm badge][npm-badge-png]][package-url]\r\n\r\n## [Try it out here...](https://bluewings.github.io/pug-as-jsx-loader/)\r\n\r\n\u003ca href=\"https://bluewings.github.io/pug-as-jsx-loader/\"\u003e\u003cimg src='https://bluewings.github.io/pug-as-jsx-loader/static/img/pug-as-jsx-loader.anim.gif'\u003e\u003c/a\u003e\r\n\r\n## Installation\r\n\r\n```\r\nnpm install pug-as-jsx-loader --save-dev\r\n```\r\n\r\n## Usage\r\n\r\n### webpack.config.js\r\n```js\r\nmodule.exports = {\r\n  module: {\r\n    rules: [\r\n      {\r\n        test: /\\.pug$/,\r\n        use: [ 'babel-loader', 'pug-as-jsx-loader' ]\r\n      }\r\n    ]\r\n  }\r\n}\r\n```\r\n\r\n\r\n\r\n### [pug | jade](https://pugjs.org) template (./file.pug)\r\n```pug\r\ndiv\r\n  h1 {period.start} ~ {period.end}\r\n  ul\r\n    li(@repeat='items as item')\r\n      i.ico(@if='item.icon', className='{\"ico-\" + item.icon}')\r\n      ItemDetail(item='{item}')\r\n```\r\n\r\n### → transpiled function\r\n```jsx\r\nimport React from 'react';\r\n\r\nexport default function (params = {}) {\r\n  const { items, period, ItemDetail } = params;\r\n  return (\r\n    \u003cdiv\u003e\r\n      \u003ch1\u003e\r\n        {period.start} ~ {period.end}\r\n      \u003c/h1\u003e\r\n      \u003cul\u003e\r\n        {items.map((item, i) =\u003e\r\n          \u003cli key={i}\u003e\r\n            {(item.icon) \u0026\u0026 (\r\n            \u003ci className={`ico ico-${item.icon}`} /\u003e\r\n            )}\r\n            \u003cItemDetail item={item} /\u003e\r\n          \u003c/li\u003e\r\n        )}\r\n      \u003c/ul\u003e\r\n    \u003c/div\u003e\r\n  );\r\n};\r\n```\r\n\r\n### import pug template\r\n```jsx\r\nimport React from 'react';\r\n\r\nimport template from './file.pug';      // ← import pug template\r\nimport ItemDetail from './ItemDetail';\r\n\r\nclass Report extends React.Component {\r\n  render() {\r\n    const {\r\n      items,\r\n      period,\r\n    } = this.props;\r\n\r\n    return template.call(this, {        // ← use transpiled function\r\n      // variables\r\n      items,\r\n      period,\r\n      // components\r\n      ItemDetail,\r\n    });\r\n  }\r\n};\r\n```\r\n\r\n### integration with Typescript\r\n```tsx\r\n// react-app-env.d.ts\r\nconst React = require('react');\r\n\r\ndeclare module '*.pug' {\r\n  const template: (params?: { [key: string]: any }) =\u003e React.ReactElement;\r\n  export = template;\r\n}\r\n```\r\n\r\n## License\r\n\r\nMIT (http://www.opensource.org/licenses/mit-license.php)\r\n\r\n[npm-badge-png]: https://nodei.co/npm/pug-as-jsx-loader.png\r\n[package-url]: https://www.npmjs.com/package/pug-as-jsx-loader\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluewings%2Fpug-as-jsx-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbluewings%2Fpug-as-jsx-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluewings%2Fpug-as-jsx-loader/lists"}