{"name":"val-loader","version":"1.0.2","author":{"name":"Tobias Koppers @sokra"},"description":"val loader module for webpack","main":"dist/cjs.js","scripts":{"test":"jest","posttest":"npm run lint","lint":"eslint --cache src test","webpack-defaults":"webpack-defaults","start":"yarn run serve:dev src","build":"cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js'","clean:dist":"del-cli dist","lint-staged":"lint-staged","prebuild":"yarn run clean:dist","prepublish":"yarn run build","release":"yarn run standard-version","security":"nsp check","serve:dev":"nodemon $2 --exec babel-node","test:coverage":"jest --collectCoverageFrom='src/**/*.js' --coverage","travis:coverage":"yarn run test:coverage","travis:lint":"yarn run lint && yarn run security","travis:test":"yarn run test","test:watch":"jest --watch"},"dependencies":{"loader-utils":"^1.1.0"},"devDependencies":{"babel-cli":"^6.24.0","babel-jest":"^19.0.0","babel-plugin-transform-object-rest-spread":"^6.23.0","babel-polyfill":"^6.23.0","babel-preset-env":"^1.2.2","cross-env":"^3.2.3","del-cli":"^0.2.1","eslint":"^3.18.0","eslint-config-webpack":"^1.1.1","eslint-plugin-import":"^2.2.0","inspect-loader":"^1.0.0","jest":"^19.0.2","lint-staged":"^3.4.0","nodemon":"^1.11.0","nsp":"^2.6.3","pre-commit":"^1.2.2","standard-version":"^4.0.0","webpack":"^2.2.1","webpack-defaults":"^0.4.4"},"licenses":"MIT","files":["dist"],"engines":{"node":">= 4.3 < 5.0.0 || >= 5.10"},"pre-commit":"lint-staged","lint-staged":{"*.js":["eslint --fix","git add"]},"gitHead":"b0c6f352d18314ca0d0c8b39b15b205a161af173","_id":"val-loader@1.0.2","_shasum":"7909198093b37cba0a96bf4f6d29de970d099d3d","_from":".","_npmVersion":"4.1.2","_nodeVersion":"7.7.3","_npmUser":{"name":"jhnns","email":"mail@johannesewald.de"},"dist":{"shasum":"7909198093b37cba0a96bf4f6d29de970d099d3d","tarball":"http://registry-npm.ywwl.com/val-loader/download/val-loader-1.0.2.tgz","integrity":"sha512-Ci+3rh2j/b3JS/9lRoggQTVqHyhP0rlqZxNOTpCRtDeMm4Pjz54UA2Kq9ogp7C0gn4eJnQLqu/KmLFt+x03dzg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAXGXSCZHXk5H2Ez/JeD55NY/SqjXyVFNlUjNGyVsUqTAiArKsv5Tq7FsyEHFy3NkhZ2+l5GJjJkmAaJdGowmVfwMA=="}],"size":4899,"noattachment":false,"key":"/val-loader/-/val-loader-1.0.2.tgz"},"maintainers":[{"name":"bebraw","email":"bebraw@gmail.com"},{"name":"d3viant0ne","email":"wiens.joshua@gmail.com"},{"name":"ericclemmons","email":"eric@smarterspam.com"},{"name":"jhnns","email":"mail@johannesewald.de"},{"name":"sokra","email":"tobias.koppers@googlemail.com"},{"name":"thelarkinn","email":"sean.larkin@cuw.edu"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/val-loader-1.0.2.tgz_1490098144966_0.007208741037175059"},"directories":{},"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":1490098146831,"_cnpm_publish_time":1490098146831,"dist-tags":{"latest":"6.0.0"}}