|
| 1 | +# [PEG.js](https://github.com/pegjs/pegjs) loader for [webpack](http://webpack.github.io/) |
| 2 | + |
| 3 | +[](https://travis-ci.org/eploko/pegjs-loader) |
| 4 | +[](https://www.npmjs.com/package/pegjs-loader) |
| 5 | +[](https://www.npmjs.com/package/pegjs-loader) |
| 6 | + |
| 7 | +## Install |
| 8 | + |
| 9 | +`npm install --save-dev pegjs-loader pegjs webpack` |
| 10 | + |
| 11 | +The pegjs-loader requires [PEG.js](https://github.com/pegjs/pegjs) and [webpack](https://github.com/webpack/webpack) |
| 12 | +as [`peerDependency`](https://docs.npmjs.com/files/package.json#peerdependencies). Thus you are able to specify the required versions accurately. |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html) |
| 17 | + |
| 18 | +``` js |
| 19 | +var parser = require("!pegjs!./parser.pegjs"); |
| 20 | +// => returns compiled PEG.js parser |
| 21 | +``` |
| 22 | + |
| 23 | +### Apply via webpack config |
| 24 | + |
| 25 | +It's recommended to adjust your `webpack.config` so `pegjs!` is applied automatically on all files ending with `.pegjs`: |
| 26 | + |
| 27 | +``` js |
| 28 | +module.exports = { |
| 29 | + ... |
| 30 | + module: { |
| 31 | + loaders: [ |
| 32 | + { |
| 33 | + test: /\.pegjs$/, |
| 34 | + loader: 'pegjs-loader' |
| 35 | + } |
| 36 | + ] |
| 37 | + } |
| 38 | +}; |
| 39 | +``` |
| 40 | + |
| 41 | +Then you only need to write: `require("./parser.pegjs")`. |
| 42 | + |
| 43 | +### PEG.js options |
| 44 | + |
| 45 | +You can pass options to PEG.js as [query parameters](http://webpack.github.io/docs/using-loaders.html#query-parameters). The following options are supported: |
| 46 | + |
| 47 | + * `cache` — if `true`, makes the parser cache results, avoiding exponential |
| 48 | + parsing time in pathological cases but making the parser slower (default: |
| 49 | + `false`) |
| 50 | + |
| 51 | + * `optimize` - whether to optimize the built parser either for `speed` or |
| 52 | + `size` (default: `speed`) |
| 53 | + |
| 54 | +``` js |
| 55 | +module.exports = { |
| 56 | + ... |
| 57 | + module: { |
| 58 | + loaders: [ |
| 59 | + { |
| 60 | + test: /\.pegjs$/, |
| 61 | + loader: 'pegjs-loader?cache=true&optimize=size' |
| 62 | + } |
| 63 | + ] |
| 64 | + } |
| 65 | +}; |
| 66 | +``` |
| 67 | + |
| 68 | +## Change Log |
| 69 | + |
| 70 | +This project adheres to [Semantic Versioning](http://semver.org/). |
| 71 | +Every release, along with the migration instructions, if any, is documented on the Github [Releases](https://github.com/eploko/pegjs-loader/releases) page. |
| 72 | + |
| 73 | +## Thanks |
| 74 | + |
| 75 | +* [Victor Homyakov](https://github.com/victor-homyakov) for the propagation of the `cache` option. |
| 76 | +* [VladimirTechMan](https://github.com/VladimirTechMan) for the propagation of the `optimize` option. |
| 77 | + |
| 78 | +## License |
| 79 | + |
| 80 | +MIT (http://www.opensource.org/licenses/mit-license.php) |
0 commit comments