All Projects → hawkins → prettier-webpack-plugin

hawkins / prettier-webpack-plugin

Licence: other
Process your Webpack dependencies with Prettier

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to prettier-webpack-plugin

prettier-eslint-webpack-plugin
Webpack plugin for prettier-eslint which ESLint's settings is set to JavaScript Standard Style
Stars: ✭ 24 (-48.94%)
Mutual labels:  webpack-plugin, prettier
dva-typescript-antd-starter-kit
A admin dashboard application demo based on antd by typescript and dva
Stars: ✭ 61 (+29.79%)
Mutual labels:  webpack-plugin, prettier
prettier-check
Check that all files match prettier code style.
Stars: ✭ 54 (+14.89%)
Mutual labels:  prettier
prettier-eslint-atom
DEPRECATED IN FAVOR OF prettier-atom + ESLint integration
Stars: ✭ 64 (+36.17%)
Mutual labels:  prettier
asset-graph-webpack-plugin
Webpack plugin to easily get assets dependency graph based on entry point
Stars: ✭ 13 (-72.34%)
Mutual labels:  webpack-plugin
webpack-typescript-react
Webpack 5 boilerplate with support of most common loaders and modules (see tags and description)
Stars: ✭ 185 (+293.62%)
Mutual labels:  prettier
ying-template
这是一个基于 `webpack@^5.27.2` + `typescript@^4.2.3` + `@babel/core@^7.2.2` + `jest@^26.6.3` + `eslint@^7.22.0` 的多页面脚手架。
Stars: ✭ 125 (+165.96%)
Mutual labels:  prettier
template-react-ts
A React template with typescript, styled-components, prettier, eslint, axios and react-router-dom
Stars: ✭ 29 (-38.3%)
Mutual labels:  prettier
tinyimg-webpack-plugin
A webpack plugin for compressing image
Stars: ✭ 61 (+29.79%)
Mutual labels:  webpack-plugin
expo-multi-screen-starter
react native / expo / react navigation v6
Stars: ✭ 74 (+57.45%)
Mutual labels:  prettier
React-Native-Web-TypeScript-Prettier-Boilerplate
A starterkit to work with nextjs, react-native, storybook… all with prettified typescript and in a monorepo
Stars: ✭ 16 (-65.96%)
Mutual labels:  prettier
luozhu
Luozhu's practice in Front End Engineering and Components Development.
Stars: ✭ 28 (-40.43%)
Mutual labels:  prettier
vscode-react-javascript-snippets
Extension for React/Javascript snippets with search supporting ES7+ and babel features
Stars: ✭ 782 (+1563.83%)
Mutual labels:  prettier
next.js-tailwindcss-template
Opinionated Next.js and TailwindCSS template.
Stars: ✭ 15 (-68.09%)
Mutual labels:  prettier
eslint-config-hardcore
The most strict (yet practical) ESLint config. 34 plugins. 1047 rules.
Stars: ✭ 168 (+257.45%)
Mutual labels:  prettier
OSAPI
👋 OSAPI 是依靠通用性后台管理平台搭建的API管理平台,基于 vue3、Nestjs 技术栈实现,包含 RBAC 角色权限模块、数据展示、编辑等模块。
Stars: ✭ 32 (-31.91%)
Mutual labels:  prettier
eslint-config
My shared ESLint & Prettier configuration for projects
Stars: ✭ 12 (-74.47%)
Mutual labels:  prettier
operationcode-pybot
Operation Code's Official Slackbot
Stars: ✭ 29 (-38.3%)
Mutual labels:  hacktoberfest2018
eslint-config-adjunct
A reasonable collection of plugins to use alongside your main esLint configuration
Stars: ✭ 39 (-17.02%)
Mutual labels:  prettier
react-component-library-lerna
Build your own React component library managed with lerna, presented with storybook and published in private npm registry.
Stars: ✭ 55 (+17.02%)
Mutual labels:  prettier

Prettier Webpack Plugin

Greenkeeper badge All Contributors

Automatically process your source files with 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

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:

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 to override any of the defaults.

For the most basic example, simple add this in your webpack.config.js:

plugins: [
  new PrettierPlugin()
],

Or, you could add options to the plugin in the form of an Object:

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 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):


Josh Hawkins

💻 📖 💡 ⚠️

Erwann Mest

📖

Eduardo Sganzerla

💻 📖 ⚠️

rkilgore-meta

💻 🤔 ⚠️

Jacob

🤔

Jason Salzman

💻 📖 🤔 ⚠️

pastelInc

💻

Nicolas Beauvais

💻

Alejandro Sanchez

🐛 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].