{"id":28220976,"url":"https://github.com/morulus/postcss-import-sub","last_synced_at":"2026-05-16T17:07:34.731Z","repository":{"id":57328134,"uuid":"77338951","full_name":"morulus/postcss-import-sub","owner":"morulus","description":"Postcss import substitution","archived":false,"fork":false,"pushed_at":"2017-11-29T16:16:55.000Z","size":223,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-21T04:29:09.730Z","etag":null,"topics":["import","postcss","resolving","substitution"],"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/morulus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-25T19:01:21.000Z","updated_at":"2024-02-01T12:55:19.000Z","dependencies_parsed_at":"2022-08-23T14:40:58.637Z","dependency_job_id":null,"html_url":"https://github.com/morulus/postcss-import-sub","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/morulus/postcss-import-sub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morulus%2Fpostcss-import-sub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morulus%2Fpostcss-import-sub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morulus%2Fpostcss-import-sub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morulus%2Fpostcss-import-sub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/morulus","download_url":"https://codeload.github.com/morulus/postcss-import-sub/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morulus%2Fpostcss-import-sub/sbom","scorecard":{"id":660651,"data":{"date":"2025-08-11","repo":{"name":"github.com/morulus/postcss-import-sub","commit":"60b4a39b615883bb37b3147c7c2d4502eb7fd09a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/14 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: license.md:0","Info: FSF or OSI recognized license: MIT License: license.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 19 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-21T16:06:21.595Z","repository_id":57328134,"created_at":"2025-08-21T16:06:21.595Z","updated_at":"2025-08-21T16:06:21.595Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33111500,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["import","postcss","resolving","substitution"],"created_at":"2025-05-18T04:16:35.117Z","updated_at":"2026-05-16T17:07:34.714Z","avatar_url":"https://github.com/morulus.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"postcss-import-sub\n--\n\nIt is decoration for plugin [postcss-import](https://github.com/postcss/postcss-import), which helps to create resolve rules.\n\n## Installation\n\n```shell\n$ npm install postcss-import-sub\n```\n\n## Usage\n\nFirst, you should learn how to use [post-import](https://github.com/postcss/postcss-import), because the plugin uses its functionality and acts in the same way, with one exception: in the options you can specify the instructions for the path substitution.\n```js\n// dependencies\nvar fs = require(\"fs\")\nvar postcss = require(\"postcss\")\nvar subImport = require(\"postcss-import-sub\")\n\n// css to be processed\nvar css = fs.readFileSync(\"css/input.css\", \"utf8\")\n\n// process css\npostcss()\n  .use(subImport([\n    {\n      match: {\n        base: /components/\n      },\n      use: {\n        base: '\u003croot\u003e/custom/\u003cfolder\u003e'\n      }\n    }\n  ]))\n  .process(css, {\n    // `from` option is required so relative import can work from input dirname\n    from: \"css/input.css\"\n  })\n  .then(function (result) {\n    var output = result.css\n\n    console.log(output)\n  })\n```\n\n## How it works\n\nThe rule consists of two parts:\n\n1. Conditions in which cases a rule should work. To do this, you specify a regular expression for _request_ (query string) and/or _base_ (path to module which requires resource).\n\nFor example, you have `style.css` inside directory `app/components/Button`, which imports `colors.css`.\n\n```css\n@import \"colors.css\";\n\nButton {\n  background-color: $bgColor;\n}\n```\n\nHere:\n- `colors.css` is __request__;\n- `./app/components/Button` is __base__;\n\nUse regular expressions to create the condition, based on these values:\n\n```js\nsubImport([{\n  match: {\n    request: /colors\\.css/,\n    base: /components\\/Button/,\n  },\n  use: {\n    ...\n  }\n}]);\n```\n\nNext property specify a new values of _request_ and/or _base_.\n\nUse a property `to` when you want to specify a particular file.\n```js\nsubImport([{\n  match: {\n    request: /colors\\.css/,\n    base: /components\\/Button/,\n  },\n  use: {\n    request: \"./customized/components/Button/colors.css\",\n    base: \"\u003croot\u003e\"\n  }\n}]);\n```\n\nThis way will give you:\n```css\n/* content of ./customized/components/colors.css\ninstead of ./app/components/Button/colors.css */\n\nButton {\n  background-color: $bgColor;\n}\n```\n\n## Using substrings\n\nYou can use the substrings retrieved from `request` or `base` by the regular expression to form the path. To insert a substring of a concrete source there are special aliases, that are created based on the pattern `\u003c{source}:{index}\u003e`.\n\n```js\nsubImport([\n  {\n    match: {\n      request: /([a-z0-9\\.\\-]*\\.css)$/i,\n      base: /components/([a-z0-9]*)\\/assets\\/([a-z0-9]*)$/i,\n    },\n    use: {\n      request: '~/theme/components/\u003cbase:1\u003e/assets/\u003cbase:2\u003e/\u003crequest:1\u003e'\n    }\n  }\n]);\n```\n\nIn this case, we get the three aliases:\n- `([a-z0-9\\.\\-]*\\.css)` will become `\u003crequest:1\u003e` and will contain required filename;\n- First `([a-z0-9]*)` will become `\u003cbase:1\u003e` and will contain component name;\n- Second `([a-z0-9]*)` will become `\u003cbase:2\u003e` and will contain some directory inside assets.\n\nUsage of approach of the regular expression is limited only by your imagination.\n\nIn addition, you can use predefined placeholders, such as `\u003croot\u003e`, `\u003cid\u003e`, `\u003cbasename\u003e` (read [Predefined placeholders](#Predefined-Placeholders)).\n\n\n## Not strict substitution\n\nA nice feature of the plugin is the fact that if the overridden path does not exists, it will use the standard method of file resolving. It allows you to create an environment in which any style can work fine without substitution (for example, in the case of using the classic postcss-import plugin). When you replace postcss-import to postcss-import-sub, you have the opportunity to customize the styles without spoiling the original sources.\n\n## Appending\n\nIn some cases, it is important not to replace imported resource, and to add to the default. For these cases, there is an option `append`.\n\n```js\nsubImport([\n    {\n      match: {\n        request: /variables\\.css/,\n      },\n      use: {\n        request: \"\u003croot\u003e/global/style.css\",\n      },\n      append: true\n    }\n])\n```\n\nThe added resource will work exactly the same as if you add it as a second import.\n\n```css\n@import \"variables.css\";\n@import \"style.css\"; /* Appended style */\n```\n\n## Properties of rules\n\n- __match__ {object} The values for matching:\n  - __request__ {RegExp} Regular expression to match and test `request`;\n  - __base__ {RegExp} Regular expression to match and test `base`.\n- __use__ {object} The substituted values:\n  - __request__ {string} Path to target file;\n  - __base__ {string} Path of directory to resolve with.\n- __append__ {bool} Enable append mode.\n\n## Designation\n\n- __request__ The string passed to import; `@import \"it_is_id\";`\n- __base__ The absolute path to the directory, relative to which the file will be resolved.\n\n## Predefined placeholders\n\n\"~\": root,\n    \"\u003crequest\u003e\": request,\n    \"\u003croot\u003e\": root,\n    \"\u003cbase\u003e\": base,\n    \"\u003cid\u003e\": path.parse(request).base,\n    \"\u003cbasename\u003e\": basename,\n\n\n- `\u003croot\u003e`, `~` Root directory of the project (process.cwd() by default);\n- `\u003crequest\u003e` The string passed to import;\n- `\u003cid\u003e` The name of requested file;\n- `\u003cbase\u003e` The path to the folder where an import was performed from;\n- `\u003cbasename\u003e` The name of the folder where an import was performed from.\n\n## Using original postcss-import options\n\nYou can define original postcss-import options as well as the usual. But in this case, the rules for a postcss-import-sub is specified in the property `sub`.\n\n```js\nsubImport({\n    root: path.join(process.cwd(), 'app'),\n    sub: {\n      match: {...},\n      use: {...}\n    }\n});\n```\n\nIf you wanna to specify your own `resolve` function, keep in mind that your function will be called only in case of failure of sub.\n\n# Examples\n\n__Common theme__\n\nAppend to all `theme.css` common theme.\n\n```shell\ngit clone https://github.com/morulus/postcss-import-sub.git\ncd postcss-import-sub/examples/common-theme\nnpm install\nnpm start\n```\n\n# License\n\nUnder MIT license, 2016-2017, Vladimir Kalmykov \u003cvladimirmorulus@gmail.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorulus%2Fpostcss-import-sub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorulus%2Fpostcss-import-sub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorulus%2Fpostcss-import-sub/lists"}