An open API service indexing awesome lists of open source software.

https://github.com/scriptex/postcss-watch-folder

PostCSS plugin to watch folder for changes
https://github.com/scriptex/postcss-watch-folder

postcss-plugin watch-files watch-folder

Last synced: 7 months ago
JSON representation

PostCSS plugin to watch folder for changes

Awesome Lists containing this project

README

          

[![Codacy Badge](https://app.codacy.com/project/badge/Grade/34d3d75710534dc6a38c3584a1dcd068)](https://www.codacy.com/gh/scriptex/postcss-watch-folder/dashboard?utm_source=github.com&utm_medium=referral&utm_content=scriptex/postcss-watch-folder&utm_campaign=Badge_Grade)
[![Codebeat Badge](https://codebeat.co/badges/d765a4c8-2c0e-44f2-89c3-fa364fdc14e6)](https://codebeat.co/projects/github-com-scriptex-postcss-watch-folder-master)
[![CodeFactor Badge](https://www.codefactor.io/repository/github/scriptex/postcss-watch-folder/badge)](https://www.codefactor.io/repository/github/scriptex/postcss-watch-folder)
[![DeepScan grade](https://deepscan.io/api/teams/3574/projects/5257/branches/40799/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=3574&pid=5257&bid=40799)
[![Analytics](https://ga-beacon-361907.ew.r.appspot.com/UA-83446952-1/github.com/scriptex/postcss-watch-folder/README.md?pixel)](https://github.com/scriptex/postcss-watch-folder/)

# postcss-watch-folder

> A [PostCSS](https://github.com/postcss/postcss) plugin to watch a folder for new files.

## Visitor stats

![GitHub stars](https://img.shields.io/github/stars/scriptex/postcss-watch-folder?style=social)
![GitHub forks](https://img.shields.io/github/forks/scriptex/postcss-watch-folder?style=social)
![GitHub watchers](https://img.shields.io/github/watchers/scriptex/postcss-watch-folder?style=social)
![GitHub followers](https://img.shields.io/github/followers/scriptex?style=social)

## Code stats

![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/scriptex/postcss-watch-folder)
![GitHub repo size](https://img.shields.io/github/repo-size/scriptex/postcss-watch-folder?style=plastic)
![GitHub language count](https://img.shields.io/github/languages/count/scriptex/postcss-watch-folder?style=plastic)
![GitHub top language](https://img.shields.io/github/languages/top/scriptex/postcss-watch-folder?style=plastic)
![GitHub last commit](https://img.shields.io/github/last-commit/scriptex/postcss-watch-folder?style=plastic)

## Why?

I've had issues when using globs to import stylesheets: `@import 'settings/**/*.scss';`.

The issues appear when using sass-loader and/or postcss-loader in webpack.

Basically, both SASS and PostCSS do not handle the event of adding files to a watched folder.

This simple plugin solves this issue by watching for `add` event and updating the main entrypoint.

## Dependencies

1. NodeJS
2. NPM or Yarn
3. PostCSS
4. Bash Terminal (Default on OSX/Linux, GitBash on Windows)

## Install

```sh
npm i postcss postcss-watch-folder --save-dev
```

or

```sh
yarn add postcss postcss-watch-folder --dev
```

## Usage

Webpack:

```javascript
module.exports = {
...
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: 'postcss-loader',
options: {
plugins: [
require('postcss-watch-folder')({
folder: './your/stylesheets/folder',
main: './your/stylesheets/folder/main.css'
}),
...other postcss plugins
],
}
}
]
}
]
}
}
```

The location of this plugin does not matter. It can be placed as first or last in the `plugins` array.

## Options

There are two configuration options. They are both required and the plugin will not work if they are not provided:

```javascript
folder: './assets/styles/', // The folder to watch
main : './assets/styles/main.css' // The main styles entrypoint
```

Default options are:

```javascript
folder: '.', // Current working directory
main : './style.css' // style.css located in CWD
```

## Demo

You can see a demo of the usage in [my webpack boilerplate](https://github.com/scriptex/webpack-mpa/blob/master/webpack.config.js#L147)

## License

MIT

---


Connect with me:






 



 



 



 



 



 



 



 



 



 



 



---


Support and sponsor my work: