postcss-loader
Advanced tools
Comparing version 6.0.0 to 6.1.0
@@ -10,4 +10,2 @@ "use strict"; | ||
var _postcss = _interopRequireDefault(require("postcss")); | ||
var _semver = require("semver"); | ||
@@ -46,3 +44,9 @@ | ||
const configOption = typeof options.postcssOptions === "undefined" || typeof options.postcssOptions.config === "undefined" ? true : options.postcssOptions.config; | ||
const postcssFactory = options.implementation || _postcss.default; | ||
const postcssFactory = (0, _utils.getPostcssImplementation)(this, options.implementation); | ||
if (!postcssFactory) { | ||
callback(new Error(`The Postcss implementation "${options.implementation}" not found`)); | ||
return; | ||
} | ||
let loadedConfig; | ||
@@ -49,0 +53,0 @@ |
@@ -42,3 +42,10 @@ { | ||
"description": "The implementation of postcss to use, instead of the locally installed version (https://github.com/postcss/postcss-loader#implementation)", | ||
"instanceof": "Function" | ||
"anyOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"instanceof": "Function" | ||
} | ||
] | ||
} | ||
@@ -45,0 +52,0 @@ }, |
@@ -12,2 +12,3 @@ "use strict"; | ||
exports.findPackageJSONDir = findPackageJSONDir; | ||
exports.getPostcssImplementation = getPostcssImplementation; | ||
@@ -393,2 +394,22 @@ var _path = _interopRequireDefault(require("path")); | ||
return dir; | ||
} | ||
function getPostcssImplementation(loaderContext, implementation) { | ||
let resolvedImplementation = implementation; | ||
if (!implementation || typeof implementation === "string") { | ||
const postcssImplPkg = implementation || "postcss"; | ||
try { | ||
// eslint-disable-next-line import/no-dynamic-require, global-require | ||
resolvedImplementation = require(postcssImplPkg); | ||
} catch (error) { | ||
loaderContext.emitError(error); // eslint-disable-next-line consistent-return | ||
return; | ||
} | ||
} // eslint-disable-next-line consistent-return | ||
return resolvedImplementation; | ||
} |
{ | ||
"name": "postcss-loader", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "PostCSS loader for webpack", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -600,3 +600,3 @@ <div align="center"> | ||
Type: `Function` | ||
Type: `Function | String` | ||
@@ -607,2 +607,4 @@ The special `implementation` option determines which implementation of PostCSS to use. Overrides the locally installed `peerDependency` version of `postcss`. | ||
#### Function | ||
**webpack.config.js** | ||
@@ -631,2 +633,27 @@ | ||
#### String | ||
**webpack.config.js** | ||
```js | ||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/i, | ||
use: [ | ||
{ loader: "style-loader" }, | ||
{ loader: "css-loader" }, | ||
{ | ||
loader: "postcss-loader", | ||
options: { implementation: require.resolve("postcss") }, | ||
}, | ||
{ loader: "sass-loader" }, | ||
], | ||
}, | ||
], | ||
}, | ||
}; | ||
``` | ||
## Examples | ||
@@ -633,0 +660,0 @@ |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
47612
595
1098
6