Socket
Socket
Sign inDemoInstall

@webpack-blocks/postcss

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webpack-blocks/postcss - npm Package Compare versions

Comparing version 1.0.0-beta to 1.0.0-rc

74

__tests__/integration.test.js

@@ -6,6 +6,2 @@ import test from 'ava'

function LoaderOptionsPlugin (loaderOptions) {
this.loaderOptions = loaderOptions
}
test('Postcss works with defaults, without match()', t => {

@@ -16,3 +12,2 @@ const config = createConfig({}, [

t.deepEqual(config.plugins, [])
t.deepEqual(config.module.rules, [

@@ -23,4 +18,9 @@ {

'style-loader',
'css-loader',
{
loader: 'css-loader',
options: {
minimize: undefined
}
},
{
loader: 'postcss-loader',

@@ -42,3 +42,2 @@ options: {}

t.deepEqual(config.plugins, [])
t.deepEqual(config.module.rules, [

@@ -49,6 +48,36 @@ {

use: [
{
loader: 'style-loader',
options: {}
},
{
loader: 'css-loader',
options: {
minimize: undefined
}
},
{
loader: 'postcss-loader',
options: {}
}
]
}
])
})
test('Postcss should pass minimize option to css-loader', t => {
const config = createConfig({}, [
postcss({ minimize: true })
])
t.deepEqual(config.module.rules, [
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {}
options: {
minimize: true
}
},

@@ -67,27 +96,24 @@ {

const config = createConfig({ webpack: { LoaderOptionsPlugin } }, [
match('*.css', [
postcss([
fakePostcssPlugin
], { parser: 'sugarss' })
])
const config = createConfig({}, [
postcss({
plugins: [ fakePostcssPlugin ],
parser: 'sugarss'
})
])
t.deepEqual(config.plugins, [
new LoaderOptionsPlugin({
options: {
postcss: [ fakePostcssPlugin ],
context: '/'
}
})
])
t.deepEqual(config.module.rules, [
{
test: /^.*\.css$/,
test: /\.css$/,
use: [
'style-loader',
'css-loader',
{
loader: 'css-loader',
options: {
minimize: undefined
}
},
{
loader: 'postcss-loader',
options: {
plugins: [ fakePostcssPlugin ],
parser: 'sugarss'

@@ -94,0 +120,0 @@ }

# @webpack-blocks/postcss - Changelog
## 1.0.0-rc
- Breaking change: Remove `plugins` argument
- Add `minimize` option
## 1.0.0-beta

@@ -4,0 +9,0 @@

@@ -7,13 +7,21 @@ /**

const _ = require('lodash')
module.exports = postcss
/**
* @param {PostCSSPlugin[]} [plugins] Will read `postcss.config.js` file if not supplied.
* @param {object} [options] https://github.com/postcss/postcss-loader#options
* @param {bool} [options.minimize] Enable minification.
* @param {string} [options.parser] Package name of custom PostCSS parser to use.
* @param {string} [options.stringifier] Package name of custom PostCSS stringifier to use.
* @param {string} [options.syntax] Package name of custom PostCSS parser/stringifier to use.
* @param {PostCSSPlugin[]} [options.plugins] PostCSS plugins, will read `postcss.config.js` file if not supplied.
* @return {Function}
*/
function postcss (plugins = [], options = {}) {
function postcss (options = {}) {
if (Array.isArray(options)) {
throw Error('Passing PostCSS plugins as a first argument is not supported anymore, use options.plugins instead')
}
const postcssOptions = _.omit(options, 'minimize')
return (context, util) => prevConfig => {

@@ -24,4 +32,10 @@ const ruleDef = Object.assign({

'style-loader',
'css-loader',
{ loader: 'postcss-loader', options }
{
loader: 'css-loader',
options: { minimize: options.minimize }
},
{
loader: 'postcss-loader',
options: postcssOptions
}
]

@@ -32,21 +46,4 @@ }, context.match)

if (plugins.length > 0) {
nextConfig = util.addPlugin(createLoaderOptionsPlugin(context, plugins))(nextConfig)
}
return nextConfig
}
}
function createLoaderOptionsPlugin ({ webpack }, postcssPlugins) {
return new webpack.LoaderOptionsPlugin({
options: {
postcss: postcssPlugins,
// Hacky fix for a strange issue involving the postcss-loader, sass-loader and webpack@2
// (see https://github.com/andywer/webpack-blocks/issues/116)
// TODO: Might be removed again once the `sass` block uses a newer `sass-loader`
context: '/'
}
})
}
{
"name": "@webpack-blocks/postcss",
"version": "1.0.0-beta",
"version": "1.0.0-rc",
"description": "Webpack block for PostCSS.",

@@ -22,7 +22,8 @@ "main": "lib/index",

"dependencies": {
"lodash": "^4.17.4",
"postcss-loader": "^1.3.3"
},
"devDependencies": {
"@webpack-blocks/assets": "^1.0.0-beta",
"@webpack-blocks/core": "^1.0.0-beta",
"@webpack-blocks/assets": "^1.0.0-rc",
"@webpack-blocks/core": "^1.0.0-rc",
"ava": "^0.19.1",

@@ -29,0 +30,0 @@ "standard": "^8.6.0"

@@ -1,7 +0,8 @@

# Webpack blocks - PostCSS
# webpack-blocks - PostCSS
[![Gitter chat](https://badges.gitter.im/webpack-blocks.svg)](https://gitter.im/webpack-blocks)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![NPM Version](https://img.shields.io/npm/v/@webpack-blocks/postcss.svg)](https://www.npmjs.com/package/@webpack-blocks/postcss)
This is the `postcss` block providing PostCSS configuration.
This is the `postcss` block providing [PostCSS](http://postcss.org/) configuration.

@@ -15,3 +16,2 @@

const postcss = require('@webpack-blocks/postcss')
const autoprefixer = require('autoprefixer')

@@ -21,5 +21,3 @@ module.exports = createConfig([

css(),
postcss([
autoprefixer({ browsers: ['last 2 versions'] })
], { /* custom PostCSS options */ })
postcss()
])

@@ -29,3 +27,3 @@ ])

Instead of passing the PostCSS plugins as an array you can also create a `postcss.config.js` file containing the plugin configuration (see [PostCSS loader usage](https://github.com/postcss/postcss-loader#usage)):
We recommend you to configure PostCSS using the `postcss.config.js` file (see [PostCSS loader usage](https://github.com/postcss/postcss-loader#usage)):

@@ -43,5 +41,26 @@ ```js

But you can pass configuration directly to the `postcss` block:
```js
const { createConfig, match } = require('@webpack-blocks/webpack')
const { css } = require('@webpack-blocks/assets')
const postcss = require('@webpack-blocks/postcss')
const autoprefixer = require('autoprefixer')
module.exports = createConfig([
postcss({
plugins: [
autoprefixer({ browsers: ['last 2 versions'] })
]
/* Other PostCSS options */
})
])
```
## Options
#### minimize *(optional)*
Enable CSS minification (by passing this option to `css-loader`).
### PostCSS options

@@ -58,9 +77,12 @@

#### plugins *(optional)*
Array of PostCSS plugins.
## Webpack blocks
## webpack-blocks
Check out the
👉 [Main Documentation](https://github.com/andywer/webpack-blocks)
👉 [Main documentation](https://github.com/andywer/webpack-blocks)
Released under the terms of the MIT license.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc