{"name":"stylus-loader","version":"8.1.3","keywords":["webpack","loader","stylus"],"author":{"url":"http://dontkry.com","name":"Kyle Robinson Young","email":"kyle@dontkry.com"},"license":"MIT","_id":"stylus-loader@8.1.3","maintainers":[{"name":"evilebottnawi","email":"sheo13666q@gmail.com"},{"name":"sokra","email":"tobias.koppers@googlemail.com"},{"name":"jhnns","email":"mail@johannesewald.de"},{"name":"15000621931","email":"784487301@qq.com"},{"name":"ev1stensberg","email":"evenstensberg@gmail.com"},{"name":"__hai","email":"haijie0619@gmail.com"}],"homepage":"https://github.com/webpack/stylus-loader","bugs":{"url":"https://github.com/webpack/stylus-loader/issues"},"dist":{"shasum":"3aac853aa842b984bb72881066731aab69169faf","tarball":"http://registry-npm.ywwl.com/stylus-loader/download/stylus-loader-8.1.3.tgz","fileCount":7,"integrity":"sha512-Rxf+ybxW+wH9/fY2Qlaae/u/PrAck3I3LKXXZQq5XaxVGp1nNm/Z76vHSdhjXltyLETs+42lpQcA4SBY2DWswg==","signatures":[{"sig":"MEUCIBOeySvmiI5tYP1lpZNr6XmQ5i9KxdM9dJs918UrsLAyAiEA/hMY34F+6D7MKgeobfrbBywOWwCTRbpYdRVbZq40bX4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":46515,"size":12079,"noattachment":false,"key":"/stylus-loader/-/stylus-loader-8.1.3.tgz"},"main":"dist/cjs.js","engines":{"node":">= 18.12.0"},"funding":{"url":"https://opencollective.com/webpack","type":"opencollective"},"gitHead":"2997f6a3b808d3f169819f089cf4fdf2508e66c8","scripts":{"fix":"npm-run-all -l fix:code fix:prettier","lint":"npm-run-all -l -p \"lint:**\"","test":"npm run test:coverage","build":"cross-env NODE_ENV=production babel src -d dist --copy-files","clean":"del-cli dist","start":"npm run build -- -w","prepare":"husky && npm run build","pretest":"npm run lint","release":"standard-version","fix:code":"npm run lint:code -- --fix","prebuild":"npm run clean","security":"npm audit --production","lint:code":"eslint --cache .","test:only":"cross-env NODE_ENV=test jest","commitlint":"commitlint --from=main","test:watch":"npm run test:only -- --watch","fix:prettier":"npm run lint:prettier -- --write","lint:prettier":"prettier --cache --list-different .","lint:spelling":"cspell --cache --no-must-find-files --quiet \"**/*.*\"","test:coverage":"npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage"},"_npmUser":{"name":"evilebottnawi","email":"sheo13666q@gmail.com"},"repository":{"url":"git+https://github.com/webpack/stylus-loader.git","type":"git"},"_npmVersion":"11.6.2","description":"Stylus loader for webpack","directories":{},"_nodeVersion":"24.11.1","dependencies":{"fast-glob":"^3.3.2","normalize-path":"^3.0.0"},"_hasShrinkwrap":false,"devDependencies":{"del":"^7.1.0","nib":"^1.1.2","jest":"^30.0.0","husky":"^9.1.3","memfs":"^4.9.3","cspell":"^8.10.0","eslint":"^9.32.0","stylus":"^0.64.0","del-cli":"^5.1.0","globals":"^16.3.0","webpack":"^5.101.0","prettier":"^3.3.2","benchmark":"^2.1.4","cross-env":"^7.0.3","@babel/cli":"^7.24.7","@eslint/js":"^9.32.0","css-loader":"^7.1.2","raw-loader":"^4.0.2","@babel/core":"^7.24.7","lint-staged":"^15.2.7","npm-run-all":"^4.1.5","style-loader":"^4.0.0","bootstrap-styl":"^5.0.9","@commitlint/cli":"^19.8.1","eslint-plugin-n":"^17.21.0","@eslint/markdown":"^7.0.0","standard-version":"^9.3.2","@babel/preset-env":"^7.24.7","typescript-eslint":"^8.38.0","eslint-plugin-jest":"^29.0.1","eslint-plugin-jsdoc":"^51.4.1","eslint-plugin-import":"^2.32.0","eslint-config-webpack":"^4.4.2","eslint-plugin-unicorn":"^60.0.0","eslint-config-prettier":"^10.1.8","eslint-plugin-prettier":"^5.5.3","@stylistic/eslint-plugin":"^5.2.2","@commitlint/config-conventional":"^19.8.1"},"peerDependencies":{"stylus":">=0.52.4","webpack":"^5.0.0","@rspack/core":"0.x || ^1.0.0 || ^2.0.0-0"},"peerDependenciesMeta":{"webpack":{"optional":true},"@rspack/core":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/stylus-loader_8.1.3_1770329352285_0.6570691081658997","host":"s3://npm-registry-packages-npm-production"},"readme":"<div align=\"center\">\n  <a href=\"https://github.com/webpack/webpack\">\n    <img width=\"200\" height=\"200\" src=\"https://webpack.js.org/assets/icon-square-big.svg\">\n  </a>\n</div>\n\n[![npm][npm]][npm-url]\n[![node][node]][node-url]\n[![tests][tests]][tests-url]\n[![cover][cover]][cover-url]\n[![discussion][discussion]][discussion-url]\n[![size][size]][size-url]\n\n# stylus-loader\n\nA Stylus loader for webpack. Compiles Stylus files into CSS.\n\n## Getting Started\n\nTo begin, you'll need to install `stylus` and `stylus-loader`:\n\n```console\nnpm install stylus stylus-loader --save-dev\n```\n\nor\n\n```console\nyarn add -D stylus stylus-loader\n```\n\nor\n\n```console\npnpm add -D stylus stylus-loader\n```\n\nThen add the loader to your `webpack` configuration. For example:\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl$/,\n        loader: \"stylus-loader\", // compiles Styl to CSS\n      },\n    ],\n  },\n};\n```\n\nFinally, run `webpack` using the method you normally use (e.g., via CLI or an npm script).\n\n## Options\n\n- **[`stylusOptions`](#stylusOptions)**\n- **[`sourceMap`](#sourcemap)**\n- **[`webpackImporter`](#webpackimporter)**\n- **[`additionalData`](#additionalData)**\n- **[`implementation`](#implementation)**\n\n### `stylusOptions`\n\nType:\n\n```ts\ntype stylusOptions =\n  | {\n      use: (string | ((stylusOptions: StylusOptions) => void))[];\n      include: string[];\n      import: string[];\n      define: any[];\n      includeCSS: false;\n      resolveURL: boolean | object;\n      lineNumbers: boolean;\n      hoistAtrules: boolean;\n      compress: boolean;\n    }\n  | ((loaderContext: LoaderContext) => string[]);\n```\n\nDefault: `{}`\n\nYou can pass any Stylus specific options to the `stylus-loader` through the `stylusOptions` property in the [loader options](https://webpack.js.org/configuration/module/#ruleoptions--rulequery).\n\nSee the [Stylus documentation](https://stylus-lang.com/docs/js.html).\n\nOptions in dash-case should be written in camelCase.\n\n#### `object`\n\nUse an object to pass options through to Stylus.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl$/,\n        use: [\n          {\n            loader: \"style-loader\",\n          },\n          {\n            loader: \"css-loader\",\n          },\n          {\n            loader: \"stylus-loader\",\n            options: {\n              stylusOptions: {\n                // eslint-disable-next-line jsdoc/no-restricted-syntax\n                /**\n                 * Specify Stylus plugins to use. Plugins may be passed as\n                 * strings instead of importing them in your Webpack config.\n                 * @type {(string | (renderer: object) => void)[]}\n                 * @default []\n                 */\n                use: [\"nib\"],\n\n                /**\n                 * Add path(s) to the import lookup paths.\n                 * @type {string[]}\n                 * @default []\n                 */\n                include: [path.join(__dirname, \"src/styl/config\")],\n\n                /**\n                 * Import the specified Stylus files/paths.\n                 * @type {string[]}\n                 * @default []\n                 */\n                import: [\"nib\", path.join(__dirname, \"src/styl/mixins\")],\n\n                /**\n                 * Define Stylus variables or functions.\n                 * @type {[string, string | number | boolean, boolean?] | Record<string, string | number | boolean>}\n                 * @default {}\n                 */\n                // Array is the recommended syntax: [key, value, raw]\n                define: [\n                  [\"$development\", process.env.NODE_ENV === \"development\"],\n                  [\"rawVar\", 42, true],\n                ],\n                // Object is deprecated syntax (there is no possibility to specify \"raw')\n                // define: {\n                //   $development: process.env.NODE_ENV === 'development',\n                //   rawVar: 42,\n                // },\n\n                /**\n                 * Include regular CSS on \\@import.\n                 * @type {boolean}\n                 * @default false\n                 */\n                includeCSS: false,\n\n                /**\n                 * Resolve relative url()'s inside imported files.\n                 * @see https://stylus-lang.com/docs/js.html#stylusresolveroptions\n                 * @type {boolean | { nocheck?: boolean, paths?: string[] }}\n                 * @default { nocheck: true }\n                 */\n                resolveURL: true,\n                // resolveURL: { nocheck: true },\n\n                /**\n                 * Emits comments in the generated CSS indicating the corresponding Stylus line.\n                 * @see https://stylus-lang.com/docs/executable.html\n                 * @type {boolean}\n                 * @default false\n                 */\n                lineNumbers: true,\n\n                /**\n                 * Move \\@import and \\@charset to the top.\n                 * @see https://stylus-lang.com/docs/executable.html\n                 * @type {boolean}\n                 * @default false\n                 */\n                hoistAtrules: true,\n\n                /**\n                 * Compress CSS output.\n                 * In the \"production\" mode is `true` by default\n                 * @see https://stylus-lang.com/docs/executable.html\n                 * @type {boolean}\n                 * @default false\n                 */\n                compress: true,\n              },\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n#### `function`\n\nAllows setting the options passed through to Stylus based off of the loader context.\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl/,\n        use: [\n          \"style-loader\",\n          \"css-loader\",\n          {\n            loader: \"stylus-loader\",\n            options: {\n              stylusOptions: (loaderContext) => {\n                // More information about available properties https://webpack.js.org/api/loaders/\n                const { resourcePath, rootContext } = loaderContext;\n                const relativePath = path.relative(rootContext, resourcePath);\n\n                if (relativePath === \"styles/foo.styl\") {\n                  return {\n                    paths: [\"absolute/path/c\", \"absolute/path/d\"],\n                  };\n                }\n\n                return {\n                  paths: [\"absolute/path/a\", \"absolute/path/b\"],\n                };\n              },\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n### `sourceMap`\n\nType:\n\n```ts\ntype sourceMap = boolean;\n```\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl$/i,\n        use: [\n          \"style-loader\",\n          {\n            loader: \"css-loader\",\n            options: {\n              sourceMap: true,\n            },\n          },\n          {\n            loader: \"stylus-loader\",\n            options: {\n              sourceMap: true,\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n### `webpackImporter`\n\nType:\n\n```ts\ntype webpackImporter = boolean;\n```\n\nDefault: `true`\n\nEnables/disables the default Webpack importer.\n\nThis can improve performance in some cases.\nUse it with caution because aliases and `@import` at-rules starting with `~` will not work.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl/i,\n        use: [\n          \"style-loader\",\n          \"css-loader\",\n          {\n            loader: \"stylus-loader\",\n            options: {\n              webpackImporter: false,\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n### `additionalData`\n\nType:\n\n```ts\ntype additionalData =\n  | string\n  | ((\n      content: string | Buffer,\n      loaderContext: LoaderContext,\n      meta: any,\n    ) => string);\n```\n\nDefault: `undefined`\n\nPrepends `Stylus` code before the actual entry file.\nIn this case, the `stylus-loader` will not override the source but will simply **prepend** the entry's content.\n\nThis is especially useful when some of your Stylus variables depend on the environment.\n\n> [!NOTE]\n>\n> Since you're injecting code, this will break the source mappings in your entry file.\n> Often there's a simpler solution than this, such as using multiple Stylus entry files.\n\n#### `string`\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl/,\n        use: [\n          \"style-loader\",\n          \"css-loader\",\n          {\n            loader: \"stylus-loader\",\n            options: {\n              additionalData: `@env: ${process.env.NODE_ENV};`,\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n#### `function`\n\n##### Sync\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl/,\n        use: [\n          \"style-loader\",\n          \"css-loader\",\n          {\n            loader: \"stylus-loader\",\n            options: {\n              additionalData: (content, loaderContext) => {\n                // More information about available properties https://webpack.js.org/api/loaders/\n                const { resourcePath, rootContext } = loaderContext;\n                const relativePath = path.relative(rootContext, resourcePath);\n\n                if (relativePath === \"styles/foo.styl\") {\n                  return `value = 100px${content}`;\n                }\n\n                return `value = 200px${content}`;\n              },\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n##### Async\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl/,\n        use: [\n          \"style-loader\",\n          \"css-loader\",\n          {\n            loader: \"stylus-loader\",\n            options: {\n              additionalData: async (content, loaderContext) => {\n                // More information about available properties https://webpack.js.org/api/loaders/\n                const { resourcePath, rootContext } = loaderContext;\n                const relativePath = path.relative(rootContext, resourcePath);\n\n                if (relativePath === \"styles/foo.styl\") {\n                  return `value = 100px${content}`;\n                }\n\n                return `value = 200px${content}`;\n              },\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n### `implementation`\n\nType:\n\n```ts\ntype implementation = (() => typeof import(\"stylus\")) | string;\n```\n\nThe `implementation` option allows you to specify which `Stylus implementation` to use.\nIt overrides the locally installed `peerDependency` version of `stylus`.\n\n#### `function`\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl/i,\n        use: [\n          \"style-loader\",\n          \"css-loader\",\n          {\n            loader: \"stylus-loader\",\n            options: {\n              implementation: require(\"stylus\"),\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n#### `string`\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl/i,\n        use: [\n          \"style-loader\",\n          \"css-loader\",\n          {\n            loader: \"stylus-loader\",\n            options: {\n              implementation: require.resolve(\"stylus\"),\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n## Examples\n\n### Normal Usage\n\nChain `stylus-loader` with the [`css-loader`](https://github.com/webpack/css-loader) and [`style-loader`](https://github.com/webpack/style-loader) to immediately apply all styles to the DOM.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl$/,\n        use: [\n          {\n            loader: \"style-loader\", // creates style nodes from JS strings\n          },\n          {\n            loader: \"css-loader\", // translates CSS into CommonJS\n          },\n          {\n            loader: \"stylus-loader\", // compiles Stylus to CSS\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n### Source maps\n\nTo enable sourcemaps for CSS, you'll need to pass the `sourceMap` property in the loader's options.\nIf this is not passed, the loader will respect the setting for webpack source maps, set in `devtool`.\n\n**webpack.config.js**\n\n```javascript\nmodule.exports = {\n  devtool: \"source-map\", // any \"source-map\"-like devtool is possible\n  module: {\n    rules: [\n      {\n        test: /\\.styl$/,\n        use: [\n          \"style-loader\",\n          {\n            loader: \"css-loader\",\n            options: {\n              sourceMap: true,\n            },\n          },\n          {\n            loader: \"stylus-loader\",\n            options: {\n              sourceMap: true,\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n### Using nib with stylus\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl$/,\n        use: [\n          {\n            loader: \"style-loader\", // creates style nodes from JS strings\n          },\n          {\n            loader: \"css-loader\", // translates CSS into CommonJS\n          },\n          {\n            loader: \"stylus-loader\", // compiles Stylus to CSS\n            options: {\n              stylusOptions: {\n                use: [require(\"nib\")()],\n                import: [\"nib\"],\n              },\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n### Import JSON files\n\nStylus does not provide resolving capabilities in the `json()` function.\nTherefore webpack resolver does not work for `.json` files.\nTo handle this, use a [`stylus resolver`](#stylus-resolver).\n\n**index.styl**\n\n```styl\n// Suppose the file is located here `node_modules/vars/vars.json`\njson('vars.json')\n\n@media queries-small\n  body\n    display nope\n\n```\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl$/,\n        use: [\n          \"style-loader\",\n          \"css-loader\",\n          {\n            loader: \"stylus-loader\",\n            options: {\n              stylusOptions: {\n                // Specify the path. where to find files\n                paths: [\"node_modules/vars\"],\n              },\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n### In production\n\nUsually, it's recommended to extract the style sheets into a dedicated CSS file in production using the [MiniCssExtractPlugin](https://github.com/webpack/mini-css-extract-plugin). This way your styles are not dependent on JavaScript.\n\n### webpack resolver\n\nWebpack provides an [advanced mechanism to resolve files](https://webpack.js.org/configuration/resolve/).\nThe `stylus-loader` applies the webpack resolver when processing queries.\nThus you can import your Stylus modules directly from `node_modules`.\n\n```styl\n@import 'bootstrap-styl/bootstrap/index.styl';\n```\n\nUsing `~` prefix is deprecated and can be removed from your code (**we recommended**), but we still support it for historical reasons.\n\nWhy you can removed it? The loader will first try to resolve `@import`/`@require` as relative, if it cannot be resolved, the loader will try to resolve `@import`/`@require` inside [`node_modules`](https://webpack.js.org/configuration/resolve/#resolvemodules).\n\nJust prepend them with a `~` which tells webpack to look up the [`modules`](https://webpack.js.org/configuration/resolve/#resolvemodules).\n\n```styl\n@import \"~bootstrap-styl/bootstrap/index.styl\";\n```\n\nIt's important to only prepend it with `~`, because `~/` resolves to the home-directory, which is different.\n\nWebpack needs to distinguish between `bootstrap` and `~bootstrap`, because CSS and Stylus files have no special syntax for importing relative files.\n\nWriting `@import \"file\"` is the same as `@import \"./file\";`\n\n### Stylus resolver\n\nIf you specify the `paths` option, modules will be searched in the given `paths`.\nThis is the default Stylus behavior.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.styl/,\n        use: [\n          {\n            loader: \"style-loader\",\n          },\n          {\n            loader: \"css-loader\",\n          },\n          {\n            loader: \"stylus-loader\",\n            options: {\n              stylusOptions: {\n                paths: [path.resolve(__dirname, \"node_modules\")],\n              },\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n### Extracting style sheets\n\nBundling CSS with webpack has some nice advantages like referencing images and fonts with hashed URLs or [hot module replacement](https://webpack.js.org/concepts/hot-module-replacement/) in development.\nIn production, on the other hand, it's not a good idea to apply your style sheets depending on JS execution.\nRendering may be delayed or even a [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) might be visible. Thus it's often still better to have them as separate files in your final production build.\n\nThere are two possibilities to extract a style sheet from the bundle:\n\n- [`extract-loader`](https://github.com/peerigon/extract-loader) (simpler, but specialized on the css-loader's output)\n- [MiniCssExtractPlugin](https://github.com/webpack/mini-css-extract-plugin) (more complex, but works in all use-cases)\n\n## Contributing\n\nWe welcome all contributions!\nIf you're new here, please take a moment to review our contributing guidelines before submitting issues or pull requests.\n\n[CONTRIBUTING](https://github.com/webpack/stylus-loader?tab=contributing-ov-file#contributing)\n\n## License\n\n[MIT](./LICENSE)\n\n[npm]: https://img.shields.io/npm/v/stylus-loader.svg\n[npm-url]: https://npmjs.com/package/stylus-loader\n[node]: https://img.shields.io/node/v/stylus-loader.svg\n[node-url]: https://nodejs.org\n[tests]: https://github.com/webpack/stylus-loader/workflows/stylus-loader/badge.svg\n[tests-url]: https://github.com/webpack/stylus-loader/actions\n[cover]: https://codecov.io/gh/webpack/stylus-loader/branch/main/graph/badge.svg\n[cover-url]: https://codecov.io/gh/webpack/stylus-loader\n[discussion]: https://img.shields.io/github/discussions/webpack/webpack\n[discussion-url]: https://github.com/webpack/webpack/discussions\n[size]: https://packagephobia.now.sh/badge?p=stylus-loader\n[size-url]: https://packagephobia.now.sh/result?p=stylus-loader\n","publish_time":1770329352449,"_cnpm_publish_time":1770329352449,"dist-tags":{"latest":"9.1.0","webpack1":"2.5.1"}}