Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
prettier-webpack-plugin
Advanced tools
Automatically process your source files with Prettier when bundling via Webpack
Automatically process your source files with Prettier when bundling via Webpack.
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.
It's in its early stages, but you can find a loader version of this plugin here: prettier-webpack-loader
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()
],
};
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!
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
)
utf-8
extensions
(type: [String]
)
[ ".css", ".graphql", ".js", ".json", ".jsx", ".less", ".sass", ".scss", ".ts", ".tsx", ".vue", ".yaml" ]
configFile
(type: String
)
.prettierrc
(from your current project directory)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.
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!
FAQs
Automatically process your source files with Prettier when bundling via Webpack
The npm package prettier-webpack-plugin receives a total of 2,543 weekly downloads. As such, prettier-webpack-plugin popularity was classified as popular.
We found that prettier-webpack-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.