{"id":14976555,"url":"https://github.com/react-doc/directory-trees-webpack-plugin","last_synced_at":"2026-01-31T00:40:18.059Z","repository":{"id":57212315,"uuid":"114747393","full_name":"react-doc/directory-trees-webpack-plugin","owner":"react-doc","description":"Store a JSON mapping of a directory.","archived":false,"fork":false,"pushed_at":"2018-01-05T08:35:28.000Z","size":25,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-02T22:54:51.730Z","etag":null,"topics":["directory","directory-tree","webpack-plugin","webpack3"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/react-doc.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}},"created_at":"2017-12-19T09:45:42.000Z","updated_at":"2017-12-25T05:02:00.000Z","dependencies_parsed_at":"2022-09-03T10:30:20.459Z","dependency_job_id":null,"html_url":"https://github.com/react-doc/directory-trees-webpack-plugin","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-doc%2Fdirectory-trees-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-doc%2Fdirectory-trees-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-doc%2Fdirectory-trees-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-doc%2Fdirectory-trees-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/react-doc","download_url":"https://codeload.github.com/react-doc/directory-trees-webpack-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-doc%2Fdirectory-trees-webpack-plugin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259271879,"owners_count":22832100,"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":["directory","directory-tree","webpack-plugin","webpack3"],"created_at":"2024-09-24T13:54:03.854Z","updated_at":"2026-01-31T00:40:18.016Z","avatar_url":"https://github.com/react-doc.png","language":"JavaScript","readme":"# Directory Tree Plugin\n\n\u003e A variation of [directory-tree-webpack-plugin](https://github.com/skipjack/directory-tree-webpack-plugin)\n\nThis plugin allows you to generate a JSON representation of a directory and all\nits child nodes (files and folders). It uses the fantastic [directory-tree-md][1]\npackage, which does the majority of the work.\n\nInstall the plugin via NPM:\n\n``` bash\nnpm i directory-trees-webpack-plugin --save\n```\n\n## Usage\n\nThis plugin is particularly useful when using [dynamic `import()`][2] statements\nas you can get a mapping of all the items in the `import(...)` location. For example,\nlet's say we wanted to dynamically `import()` all `*.md` pages within a content \ndirectory:\n\n__project__\n\n``` diff\ndemo\n|- package.json\n|- webpack.config.js\n|- /src\n  |- index.js\n  |- /content\n    |- index.md\n    |- about.md\n    |- contact.md\n```\n\n__webpack.config.js__\n\n``` js\nconst PATH = require('path')\nconst DirectoryTreePlugin = require('directory-trees-webpack-plugin')\n\nmodule.exports = {\n  entry: './src/index.js',\n  plugins: [\n    new DirectoryTreePlugin({\n      dir: './src/content',\n      // dir: ['./src/content','./src/content2'],\n      path: './src/_content.json',\n      // watch: true,\n      watch: {\n        dir: PATH.join('./src/.catch', './md'), // Save to the specified directory\n        filename: 'underline', // \"underline | dir\"\n        sep: '___', // Named directory path, using ___ interval\n      },\n      mdconf: true, // Whether to return Markdown configuration.\n      extensions: /\\.md/\n    })\n  ],\n  module: {\n    rules: [\n      {\n        test: /\\.md/,\n        use: [\n          'html-loader',\n          'markdown-loader'\n        ]\n      }\n    ]\n  },\n  output: {\n    path: PATH.resolve(__dirname, 'dist'),\n    filename: 'bundle.js'\n  }\n}\n```\n\n__src/index.js__\n\n``` js\nimport ContentTree from './_content.json'\n\nContentTree.children.forEach(page =\u003e {\n  import(`./content/${item.path}.md`)\n    .then(body =\u003e {\n      console.log('The page object can be used to generate routes, build navigations, and more...')\n      console.log(page)\n      console.log('The body string can be rendered when needed...')\n      console.log(body)\n    })\n    .catch(error =\u003e console.error('Failed to load page!'))\n})\n```\n\n\u003e Note that the example above uses promises and arrow functions. In a real app, you\n\u003e would likely polyfill these ES6+ features to ensure they work on older browsers.\n\n\n## Options\n\nThe following options can be passed to the plugin:\n\n- `dir` (string/string[]): A path to the directory that should be mapped.\n- `path` (string): The path to and filename of the JSON file to create.\n- `watch` (boolean/object): The path to and filename of the js file to create, Used for webpack monitoring file changes.\n  - `dir` Copy to the '/path/md' directory.\n  - `filename` \"underline | dir\"\n  - `sep` filename=\"underline\", File name to the directory, using '___' interval, default value '__'.\n- `mdconf` (string): Whether to return Markdown configuration..\n- `enhance` (func): A function to execute on every item in the tree (see below).\n\nAll the remaining options are passed to the `directory-tree` package. See that\npackage's [documentation][1] for a listing of all available options.\n\n\n## Enhancing the Output\n\nTo customize each item in the tree, simply pass an `enhance` method. When this\noption is passed, the plugin will recurse through the tree calling it on every\nitem. Here's a small example of how it can be used to change each item's `path`:\n\n``` js\nnew DirectoryTreePlugin({\n  dir: './src/content',\n  path: './src/_content.json',\n  extensions: /\\.md/,\n  enhance: (item, options) =\u003e {\n    item.path = item.path.replace(options.dir, '')\n    return item\n  }\n})\n```\n\nThe first parameter given to the method is the `item` and the second, `options`,\ncontains the same options object passed to the plugin. Note that this function\n__MUST__ be deterministic, if it isn't an infinite loop of tree generation will\noccur.\n\n\n[1]: https://github.com/uiw-react/node-directory-tree-md\n[2]: https://webpack.js.org/api/module-methods/#import-\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freact-doc%2Fdirectory-trees-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freact-doc%2Fdirectory-trees-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freact-doc%2Fdirectory-trees-webpack-plugin/lists"}