New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@rspack/plugin-postcss

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rspack/plugin-postcss - npm Package Compare versions

Comparing version 0.0.0-20220909061012 to 0.0.0-20221025154751

src/utils.js

8

CHANGELOG.md
# rspack-plugin-postcss
## 0.0.0-20220909061012
## 0.0.0-20221025154751
### Patch Changes
- e6d0926: unify version
- Updated dependencies [e6d0926]
- @rspack/binding@0.0.0-20220909061012
- e6d0926a2: unify version
- Updated dependencies [e6d0926a2]
- @rspack/binding@0.0.0-20221025154751

@@ -11,0 +11,0 @@ ## 0.0.4

{
"name": "@rspack/plugin-postcss",
"version": "0.0.0-20220909061012",
"version": "0.0.0-20221025154751",
"description": "",

@@ -8,3 +8,3 @@ "main": "src/index.js",

"dependencies": {
"@rspack/binding": "0.0.0-20220909061012",
"@rspack/binding": "0.0.0-20221025154751",
"postcss-modules": "^5.0.0",

@@ -22,4 +22,4 @@ "postcss-pxtorem": "^6.0.0"

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo success"
}
}
const { Processor } = require("postcss");
const pxtorem = require("postcss-pxtorem");
const cssModules = require("postcss-modules");
const {
normalizeSourceMap,
normalizeSourceMapAfterPostcss
} = require("./utils");

@@ -10,14 +14,36 @@ module.exports = async function loader(loaderContext) {

let enableModules = options.modules;
let pxToRem = options.pxToRem;
let useSourceMap =
typeof options.sourceMap !== "undefined"
? options.sourceMap
: loaderContext.useSourceMap;
try {
let meta = "";
let plugins = [
pxtorem({
rootValue: 50,
propList: ["*"]
})
];
let plugins = [];
let enablePxToRem = false;
let pxToRemConfig = {
rootValue: 50,
propList: ["*"]
};
let processOptions = {
from: loaderContext.resourcePath,
to: loaderContext.resourcePath
};
if (pxToRem) {
enablePxToRem = true;
// Custom config
if (typeof pxToRem === "object") {
pxToRemConfig = pxToRem;
}
}
if (enablePxToRem) {
plugins.push(pxtorem(pxToRemConfig));
}
if (enableModules) {
plugins.push(
cssModules({
getJSON(name, json) {
getJSON(_, json) {
if (json) {

@@ -30,7 +56,31 @@ meta = json;

}
if (useSourceMap) {
processOptions.map = {
inline: false,
annotation: false
};
}
if (loaderContext.sourceMap && processOptions.map) {
processOptions.map.prev = normalizeSourceMap(
loaderContext.sourceMap,
loaderContext.context
);
}
let root = new Processor(plugins);
let res = await root.process(loaderContext.source.getCode());
let res = await root.process(
loaderContext.source.getCode(),
processOptions
);
let map = res.map ? res.map.toJSON() : undefined;
if (map && useSourceMap) {
map = normalizeSourceMapAfterPostcss(map, loaderContext.context);
}
return {
content: res.css,
meta: meta ? Buffer.from(JSON.stringify(meta)) : ""
meta: meta ? Buffer.from(JSON.stringify(meta)) : "",
sourceMap: map
};

@@ -37,0 +87,0 @@ } catch (err) {

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