npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prettier-webpack-plugin

v1.2.0

Published

Automatically process your source files with Prettier when bundling via Webpack

Downloads

17,653

Readme

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💻 📖 🤔 ⚠️ | | :---: | :---: | :---: | :---: | :---: | :---: |

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