@webpack-blocks/postcss
Advanced tools
Comparing version 0.4.3 to 1.0.0-alpha
# @webpack-blocks/postcss - Changelog | ||
## 1.0 | ||
- Updated for new core API ([#125](https://github.com/andywer/webpack-blocks/issues/125)) | ||
- Requires node 6+ | ||
## 0.4.3 | ||
@@ -4,0 +9,0 @@ |
71
index.js
@@ -18,6 +18,3 @@ /** | ||
*/ | ||
function postcss (plugins, options) { | ||
plugins = plugins || [] | ||
options = options || {} | ||
function postcss (plugins = [], options = {}) { | ||
// https://github.com/postcss/postcss-loader#options | ||
@@ -31,42 +28,34 @@ const postcssOptions = Object.assign( | ||
return (context) => Object.assign( | ||
{ | ||
module: { | ||
loaders: [ | ||
Object.assign({ | ||
test: context.fileType('text/css'), | ||
loaders: [ 'style-loader', 'css-loader', 'postcss-loader?' + JSON.stringify(postcssOptions) ] | ||
}, options.exclude ? { | ||
exclude: Array.isArray(options.exclude) ? options.exclude : [ options.exclude ] | ||
} : {}) | ||
] | ||
} | ||
}, | ||
plugins.length > 0 ? createPostcssPluginsConfig(context.webpack, plugins) : {} | ||
) | ||
} | ||
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 ] | ||
} : {} | ||
) | ||
function createPostcssPluginsConfig (webpack, plugins) { | ||
const isWebpack2 = typeof webpack.validateSchema !== 'undefined' | ||
const _addLoader = util.addLoader(ruleDef) | ||
const _addPlugin = plugins.length > 0 | ||
? addLoaderOptionsPlugin(context, util, plugins) | ||
: config => config | ||
if (isWebpack2) { | ||
return { | ||
plugins: [ | ||
new webpack.LoaderOptionsPlugin({ | ||
options: { | ||
postcss: plugins, | ||
// 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: '/' | ||
} | ||
}) | ||
] | ||
} | ||
} else { | ||
return { | ||
postcss: plugins | ||
} | ||
return _addPlugin(_addLoader(prevConfig)) | ||
} | ||
} | ||
function addLoaderOptionsPlugin ({ webpack }, util, postcssPlugins) { | ||
return util.addPlugin( | ||
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: '/' | ||
} | ||
}) | ||
) | ||
} |
{ | ||
"name": "@webpack-blocks/postcss", | ||
"version": "0.4.3", | ||
"version": "1.0.0-alpha", | ||
"description": "Webpack block for PostCSS.", | ||
@@ -13,3 +13,3 @@ "main": "lib/index", | ||
"engines": { | ||
"node": ">= 4.0" | ||
"node": ">= 6.0" | ||
}, | ||
@@ -16,0 +16,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5289
52
1