{"id":15048782,"url":"https://github.com/privatenumber/md-vue-loader","last_synced_at":"2025-04-10T01:33:58.230Z","repository":{"id":53127104,"uuid":"135802374","full_name":"privatenumber/md-vue-loader","owner":"privatenumber","description":"Webpack loader for compiling Markdown to Vue","archived":false,"fork":false,"pushed_at":"2024-01-09T10:04:28.000Z","size":506,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-03-24T03:11:54.298Z","etag":null,"topics":["inline-demos","loader","markdown","markdown-vue-loader","markdownit","md-vue-loader","vue","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/privatenumber.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":"2018-06-02T08:52:38.000Z","updated_at":"2024-01-09T09:21:34.000Z","dependencies_parsed_at":"2022-09-03T23:20:43.310Z","dependency_job_id":null,"html_url":"https://github.com/privatenumber/md-vue-loader","commit_stats":null,"previous_names":["hirokiosame/mdvue-loader"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fmd-vue-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fmd-vue-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fmd-vue-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fmd-vue-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/privatenumber","download_url":"https://codeload.github.com/privatenumber/md-vue-loader/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248140884,"owners_count":21054366,"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":["inline-demos","loader","markdown","markdown-vue-loader","markdownit","md-vue-loader","vue","webpack","webpack-loader"],"created_at":"2024-09-24T21:16:11.054Z","updated_at":"2025-04-10T01:33:58.203Z","avatar_url":"https://github.com/privatenumber.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# md-vue-loader \u003ca href=\"https://npm.im/md-vue-loader\"\u003e\u003cimg src=\"https://badgen.net/npm/v/md-vue-loader\"\u003e\u003c/a\u003e \u003ca href=\"https://npm.im/md-vue-loader\"\u003e\u003cimg src=\"https://badgen.net/npm/dm/md-vue-loader\"\u003e\u003c/a\u003e \u003ca href=\"https://packagephobia.now.sh/result?p=md-vue-loader\"\u003e\u003cimg src=\"https://packagephobia.now.sh/badge?p=md-vue-loader\"\u003e\u003c/a\u003e\n\n`md-vue-loader` is a Webpack loader to import Markdown files as Vue components.\n\n## :raising_hand: Why?\n- **🙌  Decoupled from Vue** Compatible with any version of [Vue](https://github.com/vuejs/vue) ([`vue-loader`](https://vue-loader.vuejs.org)/`vue-template-compiler`)!\n- **👩‍🎨  Vue code rendering** Render Vue code-blocks to inline demos!\n- **⚙️  Customizable** Configure your demo to be syntax-highlighted, or wrapped in any component!\n\n## :rocket: Install\n```bash\nnpm i -D md-vue-loader\n```\n\n## 🚦 Quick Setup\nAdd to your Webpack config:\n\n```diff\nmodule.exports = {\n    module: {\n        rules: [\n+            {\n+                test: /\\.md.vue$/,\n+                use: [\n+                    'vue-loader',\n+                    'md-vue-loader'\n+                ]\n+            }\n        ]\n    },\n\n    /// ...\n}\n```\n\n## 👨🏻‍🏫 Examples\n\n### Inlining Vue demos\nYou can inline `vue` codeblocks like the following as inline-demos by enabling the `buildDemos` option.\n\n````\n```vue\n\u003ctemplate\u003e\n    \u003cdiv\u003eHello world!\u003c/div\u003e\n\u003c/template\u003e\n```\n````\n\nTo enable `buildDemos`, pass in options in your Webpack config:\n\n```diff\nmodule.exports = {\n    module: {\n        rules: [\n            {\n                test: /\\.md$/,\n                use: [\n                    'vue-loader',\n+                    {\n+                        loader: 'md-vue-loader',\n+                        options: {\n+                            buildDemos: true\n+                        }\n+                    }\n                ]\n            }\n        ]\n    },\n\n    /// ...\n}\n```\n\n### Multi-file demos\nDemos can be multi-file by naming code-blocks by prepending it with the filename in wrapped in underscores. You can import these code-blocks within the `doc` alias.\n\nName a code-block:\n````\n_HelloWorld.vue_\n```vue\n\u003ctemplate\u003e\n    \u003cdiv\u003e\n        Hello World\n    \u003c/div\u003e\n\u003c/template\u003e\n```\n````\n\nImport the code-block from `doc/HelloWorld.vue`:\n````\n```vue\n\u003ctemplate\u003e\n    \u003chello-world /\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\nimport HelloWorld from 'doc/HelloWorld.vue';\n\nexport default {\n    components: {\n        HelloWorld\n    }\n}\n\u003c/script\u003e\n```\n````\n\n### Wrapping demos in custom markup\nYou might want more control over how your demo is inlined to have it wrapped for styling, or to have the source-code next to it.\n\nTo configure the demo markup, you can pass in a function to control how the component is inlined: `function (demoTag, files)`. In the function context, you have access to `this.addComponent([...named imports], 'module-name')` to register external components.\n\nIn this example, I use [`vue-demo-collapse`](https://www.npmjs.com/package/vue-demo-collapse) to wrap my demo with an expandable container to show the demo source-code:\n\n```diff\nmodule.exports = {\n    module: {\n        rules: [\n            {\n                test: /\\.md$/,\n                use: [\n                    'vue-loader',\n                    {\n                        loader: 'md-vue-loader',\n                        options: {\n+                            buildDemos(Tag, demoFiles) {\n+                                this.addComponent(['DemoCollapse', 'SrcFile'], 'vue-demo-collapse');\n+\n+                                const listFiles = demoFiles\n+                                    .map((file) =\u003e `\u003csrc-file name=\"${file.name || ''}\" language=\"html\"\u003e\u003ctemplate v-pre\u003e${ent.encode(file.content)}\u003c/template\u003e\u003c/src-file\u003e`)\n+                                    .join('');\n+\n+                                return `\n+                                \u003cdemo-collapse\u003e\n+                                    ${Tag}\n+                                    ${listFiles}\n+                                \u003c/demo-collapse\u003e\n+                                `;\n+                            }\n                        }\n                    }\n                ]\n            }\n        ]\n    },\n\n    /// ...\n}\n```\n\n## ⚙️ Options\n\n- `buildDemos` (`Boolean`|`Function`)\n\t- `Boolean` Renders Vue code-blocks as inline demos\n\t- `Function(Tag, demoFiles)` Enable inline Vue demos and customize how they're inlined. Outputs the new template.\n\t\t- `Tag` is the tag-name of the demo component. Make sure to use it in your output to output the demo.\n\t\t- `demoFiles` (`Array`) contains all the source code releavnt to the demo\n\n- `markdownItOpts` (Object): An object to configure [MarkdownIt](https://www.npmjs.com/package/markdown-it) — the Markdown compiler.\n\n\t_Example:_\n\t```js\n\t({\n\t    // ...,\n\t    options: {\n\t        markdownItOpts: {\n\t            html: true,\n\t            linkify: true,\n\t            typographer: true\n\t        }\n\t    }\n\t})\n\t```\n\n- `markdownItPlugins` (`Array`): An array of [MarkdownIt Plugins](https://www.npmjs.com/search?q=keywords:markdown-it-plugin).\n\n\t_Example:_\n\t```js\n\tconst markdownItAnchor = require('markdown-it-anchor')\n\t\n\t// ...\n\t\n\tmodule.exports = {\n\t    module: {\n\t        rules: [\n\t            {\n\t                // ...\n\t                options: {\n\t                    markdownItPlugins: [\n\t                        [markdownItAnchor, {\n\t                            permalink: true,\n\t                            permalinkBefore: true,\n\t                            permalinkSymbol: '\u003cimg class=\"icon anchor-link\" aria-hidden=\"true\" src=\"../../assets/md-anchor-link.svg\"\u003e'\n\t                        }]\n\t                    ]\n\t                }\n\t            }\n\t        ]\n\t    }\n\t}\n\t```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprivatenumber%2Fmd-vue-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprivatenumber%2Fmd-vue-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprivatenumber%2Fmd-vue-loader/lists"}