{"id":24983673,"url":"https://github.com/posthtml/posthtml-load-config","last_synced_at":"2025-04-11T20:51:35.321Z","repository":{"id":57339002,"uuid":"60193067","full_name":"posthtml/posthtml-load-config","owner":"posthtml","description":"Autoload Config for PostHTML","archived":false,"fork":false,"pushed_at":"2020-08-28T09:24:04.000Z","size":29,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-29T21:06:06.537Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/posthtml.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-01T16:23:38.000Z","updated_at":"2020-08-28T09:24:04.000Z","dependencies_parsed_at":"2022-09-01T20:12:24.347Z","dependency_job_id":null,"html_url":"https://github.com/posthtml/posthtml-load-config","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-load-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-load-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-load-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-load-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posthtml","download_url":"https://codeload.github.com/posthtml/posthtml-load-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480512,"owners_count":21110936,"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":[],"created_at":"2025-02-04T09:20:16.374Z","updated_at":"2025-04-11T20:51:35.286Z","avatar_url":"https://github.com/posthtml.png","language":"JavaScript","readme":"[![npm][npm]][npm-url]\n[![node][node]][node-url]\n[![deps][deps]][deps-url]\n[![tests][tests]][tests-url]\n[![coverage][cover]][cover-url]\n[![code style][style]][style-url]\n[![chat][chat]][chat-url]\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"140\" height=\"120\" title=\"Load Options\" src=\"http://posthtml.github.io/posthtml-load-options/logo.svg\"\u003e\n  \u003ca href=\"https://github.com/posthtml/posthtml\"\u003e\n    \u003cimg width=\"220\" height=\"200\" title=\"PosHTML\"           src=\"http://posthtml.github.io/posthtml/logo.svg\" hspace=\"20\"\u003e\n  \u003c/a\u003e\n  \u003cimg width=\"140\" height=\"120\" title=\"Load Plugins\" src=\"http://michael-ciniawsky.github.io/postcss-load-plugins/logo.svg\"\u003e\n  \u003ch1\u003eLoad Config\u003c/h1\u003e\n  \u003cp\u003eAutoload Config for PostHTML\u003cp\u003e\n\u003c/div\u003e\n\n\u003ch2 align=\"center\"\u003eInstall\u003c/h2\u003e\n\n```bash\nnpm i -D posthtml-load-config\n```\n\n\u003ch2 align=\"center\"\u003eUsage\u003c/h2\u003e\n\n```\nnpm i -S|-D posthtml-plugin posthtml-plugin ...\n```\n\nInstall plugins and save them to your ***package.json***\n\n### `package.json`\n\nCreate a **`posthtml`** section in **`package.json`**.\n\n```\nRoot\n  |– client\n  |– public\n  |\n  |- package.json\n```\n\n```json\n{\n  \"posthtml\": {\n    \"parser\": \"posthtml-sugarml\",\n    \"from\": \"/path/to/src/file.sml\",\n    \"to\": \"/path/to/dest/file.html\",\n    \"plugins\": {\n      \"posthtml-plugin\": {}\n    }\n  }\n}\n```\n\n### `.posthtmlrc`\n\nCreate a **`.posthtmlrc`** file.\n\n```\nRoot\n  |– client\n  |– public\n  |\n  |-.posthtmlrc\n  |- package.json\n```\n\n```json\n{\n  \"parser\": \"posthtml-sugarml\",\n  \"from\": \"/path/to/src/file.sml\",\n  \"to\": \"/path/to/dest/file.html\",\n  \"plugins\": {\n    \"posthtml-plugin\": {}\n  }\n}\n```\n\n### `posthtml.config.js`\n\nCreate a **`posthtml.config.js`** file.\n\n```\nRoot\n  |– client\n  |– public\n  |\n  |- posthtml.config.js\n  |- package.json\n```\n\n```js\nmodule.exports = (ctx) =\u003e {\n  return {\n    parser: ctx.ext === '.sml' ? 'posthtml-sugarml' : false,\n    from: ctx.from,\n    to: ctx.to,\n    plugins: {\n      'posthtml-plugin': ctx.plugin\n    }\n  }\n}\n```\n\nPlugins can be loaded either using an `{Object}` or an `{Array}` in `config.plugins`.\n\n##### `{Object}`\n\n```js\nmodule.exports = (ctx) =\u003e {\n  return {\n    ...options,\n    plugins: {\n      'posthtml-plugin': ctx.plugin\n    }\n  }\n}\n```\n\n##### `{Array}`\n\n```js\nmodule.exports = (ctx) =\u003e {\n  return {\n    ...options,\n    plugins: [\n      require('posthtml-plugin')(ctx.plugin)\n    ]\n  }\n}\n```\n\n\u003e :warning: When using an Array, make sure to `require()` them.\n\n\u003ch2 align=\"center\"\u003eOptions\u003c/h2\u003e\n\n**`parser`**:\n\n```js\nparser: 'posthtml-sugarml'\n```\n\n**`from`**:\n\n```js\nfrom: 'path/to/src/file.sml'\n```\n\n**`to`**:\n\n```js\nto: 'path/to/dest/file.html'\n```\n\n**`render`**:\n\n```js\nrender: 'posthtml-jsx'\n```\n\n\u003ch2 align=\"center\"\u003ePlugins\u003c/h2\u003e\n\n### Options\n\n**`{} || null`**: Plugin loads with defaults.\n\n```js\n'posthtml-plugin': {} || null\n```\n\u003e :warning: `{}` must be an **empty** object\n\n**`[Object]`**: Plugin loads with given options.\n\n```js\n'posthtml-plugin': { option: '', option: '' }\n```\n\n**`false`**: Plugin will not be loaded.\n\n```js\n'posthtml-plugin': false\n```\n\n### Order\n\nPlugin **order** is determined by declaration in the plugins section.\n\n```js\n{\n  plugins: {\n    'posthtml-plugin': {}, // plugins[0]\n    'posthtml-plugin': {}, // plugins[1]\n    'posthtml-plugin': {}  // plugins[2]\n  }\n}\n```\n\n\u003ch2 align=\"center\"\u003eContext\u003c/h2\u003e\n\nWhen using a function `(posthtml.config.js)`, it is possible to pass context to `posthtml-load-config`, which will be evaluated while loading your config. By default `ctx.env (process.env.NODE_ENV)` and `ctx.cwd (process.cwd())` are available.\n\n\u003ch2 align=\"center\"\u003eExamples\u003c/h2\u003e\n\n**posthtml.config.js**\n\n```js\nmodule.exports = (ctx) =\u003e ({\n  parser: ctx.ext === '.sml' ? 'posthtml-sugarml' : false,\n  from: ctx.from,\n  to: ctx.to,\n  plugins: {\n    posthtml-include: {},\n    posthtml-expressions: { locals: ctx.locals },\n    htmlnano: ctx.env === 'production' ? {} : false\n  }\n})\n```\n\n### \u003cimg width=\"80\" height=\"80\" src=\"https://worldvectorlogo.com/logos/nodejs-icon.svg\"\u003e\n\n```json\n\"scripts\": {\n  \"build\": \"NODE_ENV=production node posthtml\",\n  \"start\": \"NODE_ENV=development node posthtml\"\n}\n```\n\n```js\nimport { readFileSync } = require('fs')\n\nconst posthtml = require('posthtml')\nconst posthtmlrc = require('posthtml-load-config')\n\nconst sml = readFileSync('index.sml', 'utf8')\n\nconst ctx = { ext: '.sml' }\n\nposthtmlrc(ctx).then(({ plugins, options }) =\u003e {\n  posthtml(plugins)\n    .process(sml, options)\n    .then((result) =\u003e console.log(result.html))\n})\n```\n\n### \u003cimg width=\"80\" height=\"80\" src=\"https://worldvectorlogo.com/logos/gulp.svg\"\u003e\n\n```bash\nnpm i -D gulp-posthtml\n```\n\n**package.json**\n```json\n\"scripts\": {\n  \"build\": \"NODE_ENV=production gulp\",\n  \"start\": \"NODE_ENV=development gulp\"\n}\n```\n\n**gulpfile.js**\n```js\nimport { task, src, dest } from 'gulp'\nimport plugins from 'gulp-load-plugins'\n\ntask('pug', () =\u003e {\n  const ctx = { locals: {} }\n\n  return src('src/*.pug')\n    .pipe(posthtml(ctx))\n    .pipe(rename({ ext: '.html' }))\n    .pipe(dest('dest'))\n})\n\ntask('sml', () =\u003e {\n  return src('src/*.sml')\n    .pipe(posthtml())\n    .pipe(rename({ ext: '.html' }))\n    .pipe(dest('dest'))\n})\n\ntask('html', () =\u003e {\n  return src('src/*.html')\n    .pipe(posthtml())\n    .pipe(dest('dest'))\n})\n```\n\n### \u003cimg width=\"80\" height=\"80\" src=\"https://worldvectorlogo.com/logos/webpack.svg\"\u003e\n\n```bash\nnpm i -D html-loader posthtml-loader\n```\n\n**package.json**\n```json\n\"scripts\": {\n  \"build\": \"NODE_ENV=production webpack\",\n  \"start\": \"NODE_ENV=development webpack-dev-server\"\n}\n```\n\n**webpack.config.js**\n```js\nmodule.exports = (env) =\u003e {\n  module: {\n    rules: [\n      {\n        test: /\\.html$/\n        use: [\n          'html-loader',\n          'posthtml-loader'\n        ]\n      }\n    ]\n  }\n}\n```\n\n\u003ch2 align=\"center\"\u003eMaintainer\u003c/h2\u003e\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n   \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\n      \u003cimg width=\"150 height=\"150\"  src=\"https://avatars.githubusercontent.com/u/5419992?v=3\u0026s=150\"\u003e\n      \u003cbr\u003e\n      \u003ca href=\"https://github.com/michael-ciniawsky\"\u003eMichael Ciniawsky\u003c/a\u003e\n    \u003c/td\u003e\n   \u003c/tr\u003e\n  \u003ctbody\u003e\n\u003c/table\u003e\n\n\u003ch2 align=\"center\"\u003eContributors\u003c/h2\u003e\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n   \u003ctr\u003e\u003c/tr\u003e\n  \u003ctbody\u003e\n\u003c/table\u003e\n\n[npm]: https://img.shields.io/npm/v/posthtml-load-config.svg\n[npm-url]: https://npmjs.com/package/posthtml-load-config\n\n[node]: https://img.shields.io/node/v/posthtml-load-plugins.svg\n[node-url]: https://nodejs.org/\n\n[deps]: https://david-dm.org/posthtml/posthtml-load-config.svg\n[deps-url]: https://david-dm.org/posthtml/posthtml-load-config\n\n[style]: https://img.shields.io/badge/code%20style-standard-yellow.svg\n[style-url]: http://standardjs.com/\n\n[tests]: http://img.shields.io/travis/posthtml/posthtml-load-config.svg?branch=master\n[tests-url]: https://travis-ci.org/posthtml/posthtml-load-config?branch=master\n\n[cover]: https://coveralls.io/repos/github/posthtml/posthtml-load-config/badge.svg?branch=master\n[cover-url]: https://coveralls.io/github/posthtml/posthtml-load-config?branch=master\n\n[chat]: https://badges.gitter.im/posthtml/posthtml.svg\n[chat-url]: https://gitter.im/posthtml/posthtml?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge\"\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-load-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthtml%2Fposthtml-load-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-load-config/lists"}