@rspack/plugin-postcss
Advanced tools
Comparing version 0.0.0-20220909061012 to 0.0.0-20221025154751
# 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) { |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
5201
4
147
2
+ Added@rspack/binding@0.0.0-20221025154751(transitive)
- Removed@rspack/binding@0.0.0-20220909061012(transitive)