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-alpha to 1.0.0-beta

__tests__/integration.test.js

6

CHANGELOG.md
# @webpack-blocks/postcss - Changelog
## 1.0
## 1.0.0-beta
- Use `match()` instead of `exclude`/`include` option
## 1.0.0-alpha
- Updated for new core API ([#125](https://github.com/andywer/webpack-blocks/issues/125))

@@ -6,0 +10,0 @@ - Requires node 6+

68

index.js

@@ -10,51 +10,41 @@ /**

/**
* @param {PostCSSPlugin[]} [plugins] Will read `postcss.config.js` file if not supplied.
* @param {object} [options]
* @param {RegExp|Function|string} [options.exclude] Directories to exclude.
* @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[]} [plugins] Will read `postcss.config.js` file if not supplied.
* @param {object} [options] https://github.com/postcss/postcss-loader#options
* @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.
* @return {Function}
*/
function postcss (plugins = [], options = {}) {
// https://github.com/postcss/postcss-loader#options
const postcssOptions = Object.assign(
{},
options.parser && { parser: options.parser },
options.stringifier && { stringifier: options.stringifier },
options.syntax && { syntax: options.syntax }
)
return (context, util) => prevConfig => {
const ruleDef = Object.assign(
{
test: context.fileType('text/css'),
use: [ 'style-loader', 'css-loader', 'postcss-loader?' + JSON.stringify(postcssOptions) ]
}, options.exclude ? {
exclude: Array.isArray(options.exclude) ? options.exclude : [ options.exclude ]
} : {}
)
const ruleDef = Object.assign({
test: /\.css$/,
use: [
'style-loader',
'css-loader',
{ loader: 'postcss-loader', options }
]
}, context.match)
const _addLoader = util.addLoader(ruleDef)
const _addPlugin = plugins.length > 0
? addLoaderOptionsPlugin(context, util, plugins)
: config => config
let nextConfig = util.addLoader(ruleDef)(prevConfig)
return _addPlugin(_addLoader(prevConfig))
if (plugins.length > 0) {
nextConfig = util.addPlugin(createLoaderOptionsPlugin(context, plugins))(nextConfig)
}
return nextConfig
}
}
function addLoaderOptionsPlugin ({ webpack }, util, postcssPlugins) {
return util.addPlugin(
new webpack.LoaderOptionsPlugin({
options: {
postcss: postcssPlugins,
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)
// Might be removed again once the `sass` block uses a newer `sass-loader`
context: '/'
}
})
)
// 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-alpha",
"version": "1.0.0-beta",
"description": "Webpack block for PostCSS.",

@@ -9,3 +9,3 @@ "main": "lib/index",

"scripts": {
"test": "standard",
"test": "ava && standard",
"prepublish": "npm test"

@@ -23,7 +23,10 @@ },

"dependencies": {
"postcss-loader": "^1.2.0"
"postcss-loader": "^1.3.3"
},
"devDependencies": {
"standard": "^8.1.0"
"@webpack-blocks/assets": "^1.0.0-beta",
"@webpack-blocks/core": "^1.0.0-beta",
"ava": "^0.19.1",
"standard": "^8.6.0"
}
}

@@ -12,3 +12,4 @@ # Webpack blocks - PostCSS

```js
const { createConfig } = require('@webpack-blocks/webpack')
const { createConfig, match } = require('@webpack-blocks/webpack')
const { css } = require('@webpack-blocks/assets')
const postcss = require('@webpack-blocks/postcss')

@@ -18,5 +19,8 @@ const autoprefixer = require('autoprefixer')

module.exports = createConfig([
postcss([
autoprefixer({ browsers: ['last 2 versions'] })
], { /* custom PostCSS options */ })
match('*.css', { exclude: path.resolve('node_modules') }, [
css(),
postcss([
autoprefixer({ browsers: ['last 2 versions'] })
], { /* custom PostCSS options */ })
])
])

@@ -29,5 +33,7 @@ ```

// postcss.config.js
const autoprefixer = require('autoprefixer')
module.exports = {
plugins: [
require('precss')
autoprefixer({ browsers: ['last 2 versions'] })
]

@@ -40,2 +46,4 @@ }

### PostCSS options
#### parser *(optional)*

@@ -42,0 +50,0 @@ Package name of a custom PostCSS parser to use. Pass for instance `'sugarss'` to be able to write indent-based CSS.

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