{"name":"val-loader","version":"3.0.0","description":"val loader module for webpack","license":"MIT","repository":{"type":"git","url":"git+https://github.com/webpack-contrib/val-loader.git"},"author":{"name":"Tobias Koppers @sokra"},"homepage":"https://github.com/webpack-contrib/val-loader","bugs":{"url":"https://github.com/webpack-contrib/val-loader/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/webpack"},"main":"dist/cjs.js","engines":{"node":">= 10.13.0"},"scripts":{"start":"npm run build -- -w","clean":"del-cli dist","prebuild":"npm run clean","build":"cross-env NODE_ENV=production babel src -d dist --copy-files","commitlint":"commitlint --from=master","security":"npm audit","lint:prettier":"prettier --list-different .","lint:js":"eslint --cache .","lint":"npm-run-all -l -p \"lint:**\"","test:only":"cross-env NODE_ENV=test jest","test:watch":"npm run test:only -- --watch","test:coverage":"npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage","pretest":"npm run lint","test":"npm run test:coverage","prepare":"npm run build","release":"standard-version","defaults":"webpack-defaults"},"peerDependencies":{"webpack":"^5.0.0"},"devDependencies":{"@babel/cli":"^7.12.10","@babel/core":"^7.12.10","@babel/preset-env":"^7.12.11","@commitlint/cli":"^11.0.0","@commitlint/config-conventional":"^11.0.0","@webpack-contrib/defaults":"^6.3.0","@webpack-contrib/eslint-config-webpack":"^3.0.0","babel-jest":"^26.6.3","cross-env":"^7.0.3","del":"^6.0.0","del-cli":"^3.0.1","eslint":"^7.16.0","eslint-config-prettier":"^7.1.0","eslint-plugin-import":"^2.22.1","figlet":"^1.5.0","husky":"^4.3.6","jest":"^26.6.3","lint-staged":"^10.5.3","memfs":"^3.2.0","modernizr":"^3.11.4","npm-run-all":"^4.1.5","prettier":"^2.2.1","standard-version":"^9.0.0","webpack":"^5.11.0"},"keywords":["webpack","loader","execute","val"],"gitHead":"10807dbe6f0edbc9f7208a4e5c7bc5f0e790f441","_id":"val-loader@3.0.0","_nodeVersion":"12.20.0","_npmVersion":"6.14.10","dist":{"integrity":"sha512-bzoJAdCCjrh3nK61djE9/d717oCDyxKaHQhKpW8muop64MvKk0TLYOGgn1ZdNduYdplNtInynZ0cdzDifpLzZw==","shasum":"fd4683a748257b65b15d0cc7b9deda8e0d2fb133","tarball":"http://registry-npm.ywwl.com/val-loader/download/val-loader-3.0.0.tgz","fileCount":7,"unpackedSize":18836,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf4f2uCRA9TVsSAnZWagAAbe8P+wbcv6QneZqNyvieatzJ\n1qxdb973MNrc1ySkTnKAW8OQjTki8d26z6AsDq0qu0/E4xY5FW2tcjsehqlQ\n8Cg8kvVtymRmvzTwy7JMbJn1lekcQ8s5sNUsC9FwmRe1yqH8obl+uk0BHrSU\n0vAjvdnpUb8FTvaWI0dIaLiZtzINuLD85DOQuuXuHBecE8dlLMhQm7PuSt91\nuF4Gt6ldBIHlpZ7g/ppsejRrjDE0GFqdxPtR71/byxO+thL0wXPSv3puBPDG\ndSO/PllxLj6ndT2q9ZuL0OrTTHHF3Lfn1BWGFOZxNUSWBZOYX8gRRqWnATJL\njMA3A4IkeaIX/Mk8p2KFkLFVq1412QHCLceldeTZ4GwMN84Cm4DgMoG/uRU2\nVVcmJ/wqD1kYdLXRtVGaqtg4XDl/mvJqny0+RemxK3W57Y8nbj2xraxgEMbG\nIg0mPFHnZFaOLeYp74NBwa9Dl/gf8X6a+Lwx5Nkysj1y3sLcMxD+pcQU+YlA\nkEsDkoBxu8785sj7FIJSJpF1FeaAHPd9xPqqi+/cbVGWls61iIyHLubNLVOF\nl/dH4PqgT4YkRbPw1EDqSSGsQ2WUx6cSaTpowt10r9DWNTJ8wPnlMVrntgrZ\nM7/2numnFn0Hd2jxkLBPoEth/hfitKBVYJpzTw3iQKwjSry3OzrC+mFEFyVP\nCyla\r\n=zgPp\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCsVwRkBwB6m0IKofBg8+7WeUecZn4+qKvbsoiUCf8KagIhAPke4Bmxuv5nf7eRnly4aNFDoDHnrJk/bZOeKJ0Aac6T"}],"size":6619,"noattachment":false,"key":"/val-loader/-/val-loader-3.0.0.tgz"},"_npmUser":{"name":"evilebottnawi","email":"sheo13666q@gmail.com"},"directories":{},"maintainers":[{"name":"evilebottnawi","email":"sheo13666q@gmail.com"},{"name":"sokra","email":"tobias.koppers@googlemail.com"},{"name":"jhnns","email":"mail@johannesewald.de"},{"name":"michael-ciniawsky","email":"michael.ciniawsky@gmail.com"},{"name":"d3viant0ne","email":"wiens.joshua@gmail.com"},{"name":"bebraw","email":"bebraw@gmail.com"},{"name":"ericclemmons","email":"eric@smarterspam.com"},{"name":"thelarkinn","email":"sean.larkin@cuw.edu"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/val-loader_3.0.0_1608646061599_0.8505895314958396"},"_hasShrinkwrap":false,"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[![coverage][cover]][cover-url]\n[![discussion][discussion]][discussion-url]\n[![size][size]][size-url]\n\n# val-loader\n\nA webpack loader which executes a given module, and returns the result of the\nexecution at build-time, when the module is required in the bundle. In this way,\nthe loader changes a module from code to a result.\n\nAnother way to view `val-loader`, is that it allows a user a way to make their\nown custom loader logic, without having to write a custom loader.\n\nThe target module is called with two arguments: `(options, loaderContext)`\n\n- `options`: The loader options (for instance provided in the webpack config. See the [example](#examples) below).\n- `loaderContext`: [The loader context](https://webpack.js.org/api/loaders/#the-loader-context).\n\n## Getting Started\n\nTo begin, you'll need to install `val-loader`:\n\n```console\nnpm install val-loader --save-dev\n```\n\n```console\nyarn add -D val-loader\n```\n\n```console\npnpm add -D val-loader\n```\n\nThen add the loader to your `webpack` config. For example:\n\n**target-file.js**\n\n```js\nmodule.exports = (options, loaderContext) => {\n  return { code: \"module.exports = 42;\" };\n};\n```\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /target-file.js$/,\n        use: [\n          {\n            loader: `val-loader`,\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n**src/entry.js**\n\n```js\nconst answer = require(\"target-file\");\n```\n\nAnd run `webpack` via your preferred method.\n\n## Options\n\n- **[`executableFile`](#executableFile)**\n\n### `executableFile`\n\nType:\n\n```ts\ntype executableFile = string;\n```\n\nDefault: `undefined`\n\nAllows to specify path to the executable file\n\n**data.json**\n\n```json\n{\n  \"years\": \"10\"\n}\n```\n\n**executable-file.js**\n\n```js\nmodule.exports = function yearsInMs(options, loaderContext, content) {\n  const { years } = JSON.parse(content);\n  const value = years * 365 * 24 * 60 * 60 * 1000;\n\n  return {\n    cacheable: true,\n    code: \"module.exports = \" + value,\n  };\n};\n```\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.(json)$/i,\n        rules: [\n          {\n            loader: \"val-loader\",\n            options: {\n              executableFile: path.resolve(\n                __dirname,\n                \"fixtures\",\n                \"executableFile.js\",\n              ),\n            },\n          },\n        ],\n      },\n      {\n        test: /\\.json$/i,\n        type: \"asset/resource\",\n      },\n    ],\n  },\n};\n```\n\n## Return Object Properties\n\nTargeted modules of this loader must export a `Function` that returns an object,\nor a `Promise` resolving an object (e.g. async function), containing a `code` property at a minimum, but can\ncontain any number of additional properties.\n\n### `code`\n\nType:\n\n```ts\ntype code = string | Buffer;\n```\n\nDefault: `undefined`\n_Required_\n\nCode passed along to webpack or the next loader that will replace the module.\n\n### `sourceMap`\n\nType:\n\n```ts\ntype sourceMap = object;\n```\n\nDefault: `undefined`\n\nA source map passed along to webpack or the next loader.\n\n### `ast`\n\nType:\n\n```ts\ntype ast = Array<object>;\n```\n\nDefault: `undefined`\n\nAn [Abstract Syntax Tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree)\nthat will be passed to the next loader. Useful to speed up the build time if the\nnext loader uses the same AST.\n\n### `dependencies`\n\nType:\n\n```ts\ntype dependencies = Array<string>;\n```\n\nDefault: `[]`\n\nAn array of absolute, native paths to file dependencies that should be watched by webpack for changes.\n\nDependencies can also be added using [`loaderContext.addDependency(file: string)`](https://webpack.js.org/api/loaders/#thisadddependency).\n\n### `contextDependencies`\n\nType:\n\n```ts\ntype contextDependencies = Array<string>;\n```\n\nDefault: `[]`\n\nAn array of absolute, native paths to directory dependencies that should be watched by webpack for changes.\n\nContext dependencies can also be added using [`loaderContext.addContextDependency(directory: string)`](https://webpack.js.org/api/loaders/#thisaddcontextdependency).\n\n### `buildDependencies`\n\nType:\n\n```ts\ntype buildDependencies = Array<string>;\n```\n\nDefault: `[]`\n\nAn array of absolute, native paths to directory dependencies that should be watched by webpack for changes.\n\nBuild dependencies can also be added using `loaderContext.addBuildDependency(file: string)`.\n\n### `cacheable`\n\nType:\n\n```ts\ntype cacheable = boolean;\n```\n\nDefault: `false`\n\nIf `true`, specifies that the code can be re-used in watch mode if none of the\n`dependencies` have changed.\n\n## Examples\n\n### Simple\n\nIn this example the loader is configured to operator on a file name of\n`years-in-ms.js`, execute the code, and store the result in the bundle as the\nresult of the execution. This example passes `years` as an `option`, which\ncorresponds to the `years` parameter in the target module exported function:\n\n**years-in-ms.js**\n\n```js\nmodule.exports = function yearsInMs({ years }) {\n  const value = years * 365 * 24 * 60 * 60 * 1000;\n\n  // NOTE: this return value will replace the module in the bundle\n  return {\n    cacheable: true,\n    code: \"module.exports = \" + value,\n  };\n};\n```\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: require.resolve(\"src/years-in-ms.js\"),\n        use: [\n          {\n            loader: \"val-loader\",\n            options: {\n              years: 10,\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\nIn the bundle, requiring the module then returns:\n\n```js\nimport tenYearsMs from \"years-in-ms\";\n\nconsole.log(tenYearsMs); // 315360000000\n```\n\n### Modernizr\n\nExample shows how to build [`modernizr`](https://www.npmjs.com/package/modernizr).\n\n**entry.js**\n\n```js\nimport modenizr from \"./modernizr.js\";\n```\n\n**modernizr.js**\n\n```js\nconst modernizr = require(\"modernizr\");\n\nmodule.exports = function (options) {\n  return new Promise(function (resolve) {\n    // It is impossible to throw an error because modernizr causes the process.exit(1)\n    modernizr.build(options, function (output) {\n      resolve({\n        cacheable: true,\n        code: `var modernizr; var hadGlobal = 'Modernizr' in window; var oldGlobal = window.Modernizr; ${output} modernizr = window.Modernizr; if (hadGlobal) { window.Modernizr = oldGlobal; } else { delete window.Modernizr; } export default modernizr;`,\n      });\n    });\n  });\n};\n```\n\n**webpack.config.js**\n\n```js\nconst path = require(\"path\");\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: path.resolve(__dirname, \"src\", \"modernizr.js\"),\n        use: [\n          {\n            loader: \"val-loader\",\n            options: {\n              minify: false,\n              options: [\"setClasses\"],\n              \"feature-detects\": [\n                \"test/css/flexbox\",\n                \"test/es6/promises\",\n                \"test/serviceworker\",\n              ],\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n### Figlet\n\nExample shows how to build [`figlet`](https://www.npmjs.com/package/figlet).\n\n**entry.js**\n\n```js\nimport { default as figlet } from \"./figlet.js\";\n\nconsole.log(figlet);\n```\n\n**figlet.js**\n\n```js\nconst figlet = require(\"figlet\");\n\nfunction wrapOutput(output, config) {\n  let figletOutput = \"\";\n\n  if (config.textBefore) {\n    figletOutput += encodeURI(`${config.textBefore}\\n`);\n  }\n\n  output.split(\"\\n\").forEach((line) => {\n    figletOutput += encodeURI(`${line}\\n`);\n  });\n\n  if (config.textAfter) {\n    figletOutput += encodeURI(`${config.textAfter}\\n`);\n  }\n\n  return `module.exports = decodeURI(\"${figletOutput}\");`;\n}\n\nmodule.exports = function (options) {\n  const defaultConfig = {\n    fontOptions: {\n      font: \"ANSI Shadow\",\n      horizontalLayout: \"default\",\n      kerning: \"default\",\n      verticalLayout: \"default\",\n    },\n    text: \"FIGLET-LOADER\",\n    textAfter: null,\n    textBefore: null,\n  };\n\n  const config = Object.assign({}, defaultConfig, options);\n\n  return new Promise(function (resolve, reject) {\n    figlet.text(config.text, config.fontOptions, (error, output) => {\n      if (error) {\n        return reject(error);\n      }\n\n      resolve({\n        cacheable: true,\n        code: \"module.exports = \" + wrapOutput(output, config),\n      });\n    });\n  });\n};\n```\n\n**webpack.config.js**\n\n```js\nconst path = require(\"path\");\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: path.resolve(__dirname, \"src\", \"figlet.js\"),\n        use: [\n          {\n            loader: \"val-loader\",\n            options: {\n              text: \"FIGLET\",\n            },\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n## Contributing\n\nPlease take a moment to read our contributing guidelines if you haven't yet done so.\n\n[CONTRIBUTING](./.github/CONTRIBUTING.md)\n\n## License\n\n[MIT](./LICENSE)\n\n[npm]: https://img.shields.io/npm/v/val-loader.svg\n[npm-url]: https://npmjs.com/package/val-loader\n[node]: https://img.shields.io/node/v/val-loader.svg\n[node-url]: https://nodejs.org\n[tests]: https://github.com/webpack-contrib/val-loader/workflows/val-loader/badge.svg\n[tests-url]: https://github.com/webpack-contrib/val-loader/actions\n[cover]: https://codecov.io/gh/webpack-contrib/val-loader/branch/master/graph/badge.svg\n[cover-url]: https://codecov.io/gh/webpack-contrib/val-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=val-loader\n[size-url]: https://packagephobia.now.sh/result?p=val-loader\n","publish_time":1608646061712,"_cnpm_publish_time":1608646061712,"dist-tags":{"latest":"6.0.0"}}