{"name":"style-resources-loader","version":"1.3.2","description":"CSS processor resources loader for webpack","author":{"name":"Shi Yan","email":"yenshih95@gmail.com","url":"https://github.com/yenshih"},"license":"MIT","engines":{"node":">=7.6"},"main":"lib/index.js","scripts":{"clean":"rimraf lib coverage test/**/outputs","lint":"eslint . --ext .js,.jsx,.ts,.tsx","prettier":"prettier {src,test}/**/*.{js,jsx,ts,tsx} --write","test":"jest --detectOpenHandles","coverage":"npm test -- --coverage","posttest":"rimraf test/**/outputs","start":"tsc -w","build":"tsc -d","prepare":"npm run clean && npm run lint && npm run build && npm run coverage"},"keywords":["webpack","loader","style","css","sass","scss","less","stylus","inject","resource","variable","mixin"],"repository":{"type":"git","url":"git+https://github.com/yenshih/style-resources-loader.git"},"homepage":"https://github.com/yenshih/style-resources-loader","bugs":{"url":"https://github.com/yenshih/style-resources-loader/issues"},"dependencies":{"glob":"^7.1.6","is-promise":"^2.1.0","loader-utils":"^1.2.3","schema-utils":"^2.5.0"},"devDependencies":{"@commitlint/cli":"^8.2.0","@commitlint/config-conventional":"^8.2.0","@types/glob":"^7.1.1","@types/is-promise":"^2.1.0","@types/jest":"^24.0.22","@types/loader-utils":"^1.1.3","@types/node":"^12.12.7","@types/webpack":"^4.39.8","@types/webpack-merge":"^4.1.5","@typescript-eslint/eslint-plugin":"^2.6.1","@typescript-eslint/parser":"^2.6.1","coveralls":"^3.0.7","cross-env":"^6.0.3","eslint":"^6.6.0","eslint-config-prettier":"^6.5.0","eslint-plugin-import":"^2.18.2","eslint-plugin-prettier":"^3.1.1","husky":"^3.0.9","jest":"^24.9.0","lint-staged":"^9.4.2","prettier":"^1.19.1","raw-loader":"^3.1.0","ts-jest":"^24.1.0","typescript":"^3.7.2","webpack":"^4.41.2","webpack-merge":"^4.2.2"},"peerDependencies":{"webpack":"^3.0.0 || ^4.0.0"},"sideEffects":false,"gitHead":"d27041b8f3681a0c7f3c833e8988744ac7c7d5ec","_id":"style-resources-loader@1.3.2","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","dist":{"integrity":"sha512-UIwyrl/OZGO+ptyeNyeDnNE+2RqD0AKqjAuxBxhce0YlHMx2DbZ48g0Mx9buKuiNSgBUXYQtbwilKcYeJlVsog==","shasum":"dee034e33e84060ded0b1980f866453e98589873","tarball":"http://registry-npm.ywwl.com/style-resources-loader/download/style-resources-loader-1.3.2.tgz","fileCount":65,"unpackedSize":44952,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdyPr5CRA9TVsSAnZWagAAwA0QAKOezdQYsaKk37CUAGAz\nUwbuKKxgzWnGeqxTzKvwAJ4WVg5XsYNB9wNcn45gE8GuR8DeyR2AijIwIjn+\nIcTF4wvlgkCNAP0VSLQPqzedY8plJU5fVPIkAr0Dc2uxG5dA3w2I2eWDWBAD\n6fx3PmFQflSfZCt0z0d0mpGwOYDARyMuu02rM4QP2c14ORYdb9zRkA0SLG1Y\nwPm/BIVk/Q8naHkK0uYfrwqoqB/jOCg8VB7TJLP1hasA4VmwzZe91uk3qxXA\n69dEUJkOCt1zTBJF2lQdhR9Q+zCayLy2K5bLDc8n9joAgYM3lbPx5JlkRx5v\n7VmzsiCKiSvnIIC5VQLAh/uRxRBbcgwtiJbNGvH4eFhNFvPZnEMEtka7Rvoq\nPadB3Pg3LKmkrztb1R2V+LBg5617QJRow66n0XetqamLyaZperO0jd+iLZJU\nyzZVonJvXTQFylbQzb8wJ1u4IIOBzUH7GsX+yAAePaV6+IG4f94UNaWRmoAh\nP0gkFPoQmfADzzLbvEvEsrFvgnPbFH74bYHYjuf9QTRl3+Cbow+4YoVew2Qg\n8dyrgpIqZf5jdLRuy3dAHm8yGsZcD6x0Rp4xxuk41gZWOw41F6didKHZ6G5n\ng07IXFBSI6Fu9oiPaA75nBtOVMUzAbFQ9kYeEAxjaxOc0LkC/Qiw3ao+V4Ke\ny21u\r\n=aLK+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDVyGjmukK4EbBYk1Eg8TubarzgR2KGhpH4bfInNZdcwAiEAzMxX6Nq8gs7P1pCw8ziM5nzRFjQAZ6pcDaaJuil1gZA="}],"size":13874,"noattachment":false,"key":"/style-resources-loader/-/style-resources-loader-1.3.2.tgz"},"maintainers":[{"name":"yenshih","email":"yenshih95@gmail.com"}],"_npmUser":{"name":"yenshih","email":"yenshih95@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/style-resources-loader_1.3.2_1573452536646_0.47006550485430343"},"_hasShrinkwrap":false,"readme":"[![npm][npm]][npm-url]\n[![node][node]][node-url]\n[![downloads][downloads]][downloads-url]\n[![build][build]][build-url]\n[![coverage][coverage]][coverage-url]\n[![996.icu][996.icu]][996.icu-url]\n\n<div align=\"center\">\n  <a href=\"https://github.com/webpack/webpack\">\n    <img\n        width=\"200\"\n        height=\"200\"\n        src=\"https://webpack.js.org/assets/icon-square-big.svg\"\n    >\n  </a>\n  <h1>Style Resources Loader</h1>\n  <p>CSS processor resources loader for webpack.</p>\n</div>\n\n\n<h2 align=\"center\">Install</h2>\n\n```bash\nnpm i style-resources-loader -D\n```\n\n<h2 align=\"center\">Usage</h2>\n\nThis loader is a CSS processor resources loader for webpack, which injects your style resources (e.g. `variables, mixins`) into multiple imported `css, sass, scss, less, stylus` modules.\n\nIt's mainly used to\n - share your `variables, mixins, functions` across all style files, so you don't need to `@import` them manually.\n - override `variables` in style files provided by other libraries (e.g. [ant-design](https://github.com/ant-design/ant-design)) and customize your own theme.\n\n### Usage with Vue CLI\n\nSee [automatic imports](https://cli.vuejs.org/guide/css.html#automatic-imports) for more details.\n\n<h2 align=\"center\">Examples</h2>\n\nPrepends `variables` and `mixins` to all `scss` files with default resources injector.\n\n**webpack.config.js**\n``` js\nmodule.exports = {\n    // ...\n    module: {\n        rules: [{\n            test: /\\.scss$/,\n            use: ['style-loader', 'css-loader', 'sass-loader', {\n                loader: 'style-resources-loader',\n                options: {\n                    patterns: [\n                        './path/from/context/to/scss/variables/*.scss',\n                        './path/from/context/to/scss/mixins/*.scss',\n                    ]\n                }\n            }]\n        }]\n    },\n    // ...\n}\n```\n\nAppends `variables` to all `less` files and overrides original `less variables`.\n\n**webpack.config.js**\n```js\nmodule.exports = {\n    // ...\n    module: {\n        rules: [{\n            test: /\\.less$/,\n            use: ['style-loader', 'css-loader', 'less-loader', {\n                loader: 'style-resources-loader',\n                options: {\n                    patterns: path.resolve(__dirname, 'path/to/less/variables/*.less'),\n                    injector: 'append'\n                }\n            }]\n        }]\n    },\n    // ...\n}\n```\n\nPrepends `variables` and `mixins` to all `stylus` files with customized resources injector.\n\n**webpack.config.js**\n``` js\nmodule.exports = {\n    // ...\n    module: {\n        rules: [{\n            test: /\\.styl$/,\n            use: ['style-loader', 'css-loader', 'stylus-loader', {\n                loader: 'style-resources-loader',\n                options: {\n                    patterns: [\n                        path.resolve(__dirname, 'path/to/stylus/variables/*.styl'),\n                        path.resolve(__dirname, 'path/to/stylus/mixins/*.styl')\n                    ],\n                    injector: (source, resources) => {\n                        const combineAll = type => resources\n                            .filter(({ file }) => file.includes(type))\n                            .map(({ content }) => content)\n                            .join('');\n\n                        return combineAll('variables') + combineAll('mixins') + source;\n                    }\n                }\n            }]\n        }]\n    },\n    // ...\n}\n```\n\n<h2 align=\"center\">Options</h2>\n\n|Name|Type|Default|Description|\n|:--:|:--:|:-----:|:----------|\n|**[`patterns`](#patterns)**|`string \\| string[]`|`/`|Path to the resources you would like to inject|\n|**[`injector`](#injector)**|`Injector \\| 'prepend' \\| 'append'`|`'prepend'`|Controls the resources injection precisely|\n|**[`globOptions`](#globoptions)**|`GlobOptions`|`{}`|An options that can be passed to `glob(...)`|\n|**[`resolveUrl`](#resolveurl)**|`boolean`|`true`|Enable/Disable `@import` url to be resolved|\n\nSee [the type definition file](https://github.com/yenshih/style-resources-loader/blob/master/src/types.ts) for more details.\n\n### `patterns`\n\nA string or an array of string, which represents the path to the resources you would like to inject. If the path is relative, it would relative to [webpack context](https://webpack.js.org/configuration/entry-context/).\n\nIt supports [globbing](https://github.com/isaacs/node-glob). You could include many files using a file mask.\n\nFor example, `'./styles/*/*.less'` would include all `less` files from `variables` and `mixins` directories and ignore `reset.less` in such following structure.\n\n```\n./src  <-- webpack context\n  /styles\n    /variables\n      |-- fonts.less\n      |-- colors.less\n    /mixins\n      |-- size.less\n    |-- reset.less\n```\n\nOnly supports `.css` `.sass` `.scss` `.less` `.styl` as resources file extensions.\n\n### `injector`\n\nAn optional function which controls the resources injection precisely. It also supports `'prepend'` and `'append'` for convenience, which means the loader will prepend or append all resources to source files, respectively.\n\nIt defaults to `'prepend'`, which implements as an injector function internally.\n\nFurthermore, an injector function should match the following type signature:\n\n```ts\ntype Injector = (\n    this: LoaderContext,\n    source: string,\n    resources: StyleResource[],\n) => string | Promise<string>\n```\n\nIt receives two parameters:\n\n|Name|Type|Description|\n|:--:|:--:|:----------|\n|**`source`**|`string`|Content of the source file|\n|**[`resources`](#resources)**|`StyleResource[]`|Resource descriptors|\n\nIt is called with `this` context pointing to the loader context.\n\n#### `resources`\n\nAn array of resource descriptor, each contains `file` and `content` properties:\n\n|Name|Type|Description|\n|:--:|:--:|:----------|\n|**`file`**|`string`|Absolute path to the resource|\n|**`content`**|`string`|Content of the resource file|\n\nIt can be asynchronous. You could use `async / await` syntax in your own injector function or just return a promise.\n\n### `globOptions`\n\nOptions that can be passed to `glob(...)`. See [node-glob options](https://github.com/isaacs/node-glob#options) for more details.\n\n### `resolveUrl`\n\nA boolean which defaults to `true`. It represents whether the relative path in `@import` or `@require` statements should be resolved.\n\nIf you were to use `@import` or `@require` statements in style resource files, you should make sure that the URL is relative to that resource file, rather than the source file.\n\nYou could disable this feature by setting `resolveUrl` to `false`.\n\n<h2 align=\"center\">License</h2>\n\n[MIT](http://www.opensource.org/licenses/mit-license.php)\n\n[npm]: https://img.shields.io/npm/v/style-resources-loader.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/style-resources-loader\n[node]: https://img.shields.io/node/v/style-resources-loader.svg\n[node-url]: https://nodejs.org\n[downloads]: https://img.shields.io/npm/dm/style-resources-loader.svg?style=flat-square\n[downloads-url]: https://www.npmjs.com/package/style-resources-loader\n[build]: https://img.shields.io/travis/yenshih/style-resources-loader/master.svg?style=flat-square\n[build-url]: https://travis-ci.org/yenshih/style-resources-loader\n[coverage]: https://img.shields.io/coveralls/yenshih/style-resources-loader/master.svg?style=flat\n[coverage-url]: https://coveralls.io/github/yenshih/style-resources-loader?branch=master\n[996.icu]: https://img.shields.io/badge/link-996.icu-%23FF4D5B.svg?style=flat-square\n[996.icu-url]: https://996.icu/#/en_US\n","publish_time":1573452536790,"_cnpm_publish_time":1573452536790,"dist-tags":{"latest":"1.5.0"}}