Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hawkins/prettier-webpack-plugin
Process your Webpack dependencies with Prettier
https://github.com/hawkins/prettier-webpack-plugin
hacktoberfest2018 javascript prettier webpack webpack-plugin
Last synced: 18 days ago
JSON representation
Process your Webpack dependencies with Prettier
- Host: GitHub
- URL: https://github.com/hawkins/prettier-webpack-plugin
- Owner: hawkins
- Created: 2017-01-24T15:26:29.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-05T08:36:26.000Z (almost 2 years ago)
- Last Synced: 2024-12-09T18:24:36.701Z (27 days ago)
- Topics: hacktoberfest2018, javascript, prettier, webpack, webpack-plugin
- Language: JavaScript
- Homepage: https://travis-ci.org/hawkins/prettier-webpack-plugin
- Size: 198 KB
- Stars: 50
- Watchers: 2
- Forks: 14
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Prettier Webpack Plugin
[![Greenkeeper badge](https://badges.greenkeeper.io/hawkins/prettier-webpack-plugin.svg)](https://greenkeeper.io/)
[![All Contributors](https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square)](#contributors)Automatically process your source files with [Prettier](https://github.com/jlongster/prettier) when bundling via Webpack.
## How it works
This plugin reads all file dependencies in your dependency graph.
If a file is found with a matching extension, the file is processed by Prettier and overwritten.You can provide options Prettier by specifying them when creating the plugin.
## Looking for a loader?
It's in its early stages, but you can find a loader version of this plugin here: [prettier-webpack-loader](https://github.com/hawkins/prettier-webpack-loader)
## Installation
> Note, for Webpack 4 support, install prettier-webpack-plugin@1. For Webpack < 4, install prettier-webpack-plugin@0
Simply run `npm install --save-dev prettier prettier-webpack-plugin` or `yarn add --dev prettier prettier-webpack-plugin` to install.
Then, in your Webpack config files, add the lines:
```JavaScript
var PrettierPlugin = require("prettier-webpack-plugin");module.exports = {
// ... config settings here ...
plugins: [
new PrettierPlugin()
],
};```
### Why?
Keeping style consistent between programmers new to collaboration can be tricky.
Prettier tackles this problem by formatting your code to fit its preferred style, which is admittedly very pretty.
Now, your code is automatically formatted when you bundle with Webpack.Perfect for group projects bundling code on save!
### Usage
The API is very simple.
The constructor accepts one argument, `options`, a JavaScript object which you can leverage to override any default behaviors.
You can specify any of [Prettier's options](https://github.com/jlongster/prettier#api) to override any of the defaults.For the most basic example, simple add this in your `webpack.config.js`:
```JavaScript
plugins: [
new PrettierPlugin()
],
```Or, you could add options to the plugin in the form of an `Object`:
```JavaScript
plugins: [
new PrettierPlugin({
printWidth: 80, // Specify the length of line that the printer will wrap on.
tabWidth: 2, // Specify the number of spaces per indentation-level.
useTabs: false, // Indent lines with tabs instead of spaces.
semi: true, // Print semicolons at the ends of statements.
encoding: 'utf-8', // Which encoding scheme to use on files
extensions: [ ".js", ".ts" ] // Which file extensions to process
})
],
```> Again, see [Prettier's options](https://github.com/jlongster/prettier#api) for a complete list of options to specify for Prettier.
Note that you can specify any option for Prettier to use in this object. So, all options are assumed to be for Prettier, and will thus be passed to prettier, with the exception of three for this plugin:
- `encoding` (type: `String`)
- The encoding scheme to use for the file.
- **Default**: `utf-8`
- `extensions` (type: `[String]`)
- Which file extensions to pass.
- **Default**: Either what your version of Prettier supports, or `[ ".css", ".graphql", ".js", ".json", ".jsx", ".less", ".sass", ".scss", ".ts", ".tsx", ".vue", ".yaml" ]`
- `configFile` (type: `String`)
- Optional value to supply global config file from your project in order to avoid hardcoding values in multiple places
- **Default**: `.prettierrc` (from your current project directory)### Testing
`npm run test` or `yarn run test` will show you how tests are going currently.
These tests can also serve as primitive examples for configuring Prettier Webpack Plugin.
## Contributors
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
| [
Josh Hawkins](https://hawkins.is/)
[💻](https://github.com/hawkins/prettier-webpack-plugin/commits?author=hawkins "Code") [📖](https://github.com/hawkins/prettier-webpack-plugin/commits?author=hawkins "Documentation") [💡](#example-hawkins "Examples") [⚠️](https://github.com/hawkins/prettier-webpack-plugin/commits?author=hawkins "Tests") | [
Erwann Mest](http://kud.io)
[📖](https://github.com/hawkins/prettier-webpack-plugin/commits?author=kud "Documentation") | [
Eduardo Sganzerla](http://esganzerla.com.br)
[💻](https://github.com/hawkins/prettier-webpack-plugin/commits?author=esganzerla "Code") [📖](https://github.com/hawkins/prettier-webpack-plugin/commits?author=esganzerla "Documentation") [⚠️](https://github.com/hawkins/prettier-webpack-plugin/commits?author=esganzerla "Tests") | [
rkilgore-meta](https://github.com/rkilgore-meta)
[💻](https://github.com/hawkins/prettier-webpack-plugin/commits?author=rkilgore-meta "Code") [🤔](#ideas-rkilgore-meta "Ideas, Planning, & Feedback") [⚠️](https://github.com/hawkins/prettier-webpack-plugin/commits?author=rkilgore-meta "Tests") | [
Jacob](http://jacob.wtf)
[🤔](#ideas-jacobbuck "Ideas, Planning, & Feedback") | [
Jason Salzman](https://github.com/jasonsalzman)
[💻](https://github.com/hawkins/prettier-webpack-plugin/commits?author=jasonsalzman "Code") [📖](https://github.com/hawkins/prettier-webpack-plugin/commits?author=jasonsalzman "Documentation") [🤔](#ideas-jasonsalzman "Ideas, Planning, & Feedback") [⚠️](https://github.com/hawkins/prettier-webpack-plugin/commits?author=jasonsalzman "Tests") | [
pastelInc](https://github.com/pastelInc)
[💻](https://github.com/hawkins/prettier-webpack-plugin/commits?author=pastelInc "Code") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [
Nicolas Beauvais](http://nicolas-beauvais.com)
[💻](https://github.com/hawkins/prettier-webpack-plugin/commits?author=nicolasbeauvais "Code") | [
Alejandro Sanchez](https://alesanchezr.com)
[🐛](https://github.com/hawkins/prettier-webpack-plugin/issues?q=author%3Aalesanchezr "Bug reports") [💻](https://github.com/hawkins/prettier-webpack-plugin/commits?author=alesanchezr "Code") |This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!