clean-css-loader
Advanced tools
Comparing version
/// <reference types="node" /> | ||
import CleanCSS from "clean-css"; | ||
import type { LoaderContext } from "webpack"; | ||
declare type CleanCSSOptions = Omit< | ||
Exclude<ConstructorParameters<typeof CleanCSS>[0], undefined>, | ||
"returnPromise" | ||
>; | ||
type CleanCSSOptions = Omit<Exclude<ConstructorParameters<typeof CleanCSS>[0], undefined>, "returnPromise">; | ||
interface LoaderOptions extends CleanCSSOptions { | ||
skipWarn?: boolean; | ||
disable?: boolean; | ||
sourceMap?: boolean; | ||
} | ||
@@ -25,8 +23,3 @@ interface SourceMap { | ||
} | ||
declare function cleanCssLoader( | ||
this: LoaderContext<LoaderOptions>, | ||
content: string | Buffer, | ||
prevSourceMap?: string | SourceMap, | ||
additionalData?: AdditionalData | ||
): void; | ||
declare function cleanCssLoader(this: LoaderContext<LoaderOptions>, content: string | Buffer, prevSourceMap?: string | SourceMap, additionalData?: AdditionalData): void; | ||
export = cleanCssLoader; |
@@ -11,9 +11,17 @@ "use strict"; | ||
const schema_json_1 = __importDefault(require("./schema.json")); | ||
function parsePrevSourceMap(prevSourceMap) { | ||
if (prevSourceMap != null && typeof prevSourceMap === "object") { | ||
return JSON.stringify(prevSourceMap); | ||
} | ||
return undefined; | ||
} | ||
function cleanCssLoader(content, prevSourceMap, additionalData) { | ||
const callback = this.async(); | ||
const loaderOptions = (0, loader_utils_1.getOptions)(this) || {}; | ||
const loaderOptions = | ||
(typeof this.getOptions === "function" ? this.getOptions(schema_json_1.default) : loader_utils_1.getOptions === null || loader_utils_1.getOptions === void 0 ? void 0 : (0, loader_utils_1.getOptions)(this)) || {}; | ||
(0, schema_utils_1.validate)(schema_json_1.default, loaderOptions, { | ||
name: "group-css-media-queries-loader", | ||
name: "clean-css-loader", | ||
}); | ||
const { disable, skipWarn, ...options } = loaderOptions; | ||
const { sourceMap, disable, skipWarn, ...options } = loaderOptions; | ||
const useSourceMap = Boolean(sourceMap !== null && sourceMap !== void 0 ? sourceMap : this.sourceMap); | ||
if (disable) { | ||
@@ -23,6 +31,7 @@ return callback(null, content, prevSourceMap, additionalData); | ||
new clean_css_1.default({ | ||
...options, | ||
returnPromise: true, | ||
...options, | ||
sourceMap: useSourceMap, | ||
}) | ||
.minify(content, prevSourceMap) | ||
.minify(content, parsePrevSourceMap(prevSourceMap)) | ||
.then((output) => { | ||
@@ -34,3 +43,11 @@ if (!skipWarn && Array.isArray(output.warnings)) { | ||
} | ||
return callback(null, output.styles, output.sourceMap, additionalData); | ||
let resultSourceMap; | ||
if (useSourceMap && output.sourceMap) { | ||
resultSourceMap = { | ||
...JSON.parse(output.sourceMap.toString()), | ||
sources: (prevSourceMap === null || prevSourceMap === void 0 ? void 0 : prevSourceMap.sources) || [this.resourcePath], | ||
sourcesContent: (prevSourceMap === null || prevSourceMap === void 0 ? void 0 : prevSourceMap.sourcesContent) || [content.toString()], | ||
}; | ||
} | ||
return callback(null, output.styles, resultSourceMap, additionalData); | ||
}) | ||
@@ -37,0 +54,0 @@ .catch(callback); |
@@ -183,7 +183,3 @@ { | ||
"link": "https://github.com/clean-css/clean-css#formatting-options", | ||
"anyOf": [ | ||
{ "type": "string" }, | ||
{ "type": "boolean" }, | ||
{ "type": "object", "additionalProperties": true } | ||
] | ||
"anyOf": [{ "type": "string" }, { "type": "boolean" }, { "type": "object", "additionalProperties": true }] | ||
}, | ||
@@ -206,6 +202,3 @@ "inline": { | ||
"link": "https://github.com/clean-css/clean-css#optimization-levels", | ||
"anyOf": [ | ||
{ "type": "number" }, | ||
{ "type": "object", "additionalProperties": true } | ||
] | ||
"anyOf": [{ "type": "number" }, { "type": "object", "additionalProperties": true }] | ||
}, | ||
@@ -212,0 +205,0 @@ "rebase": { |
{ | ||
"name": "clean-css-loader", | ||
"version": "4.0.0", | ||
"version": "4.1.0-alpha.0", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"dependencies": { | ||
"types": "lib/index.d.ts", | ||
"dependencies": { | ||
"clean-css": "^5.0.0" | ||
}, | ||
"peerDependencies": { | ||
"loader-utils": "^1.0.0 || ^2.0.0", | ||
"loader-utils": "^1.0.0 || ^2.0.0 || ^3.0.0", | ||
"webpack": ">=2.0.0" | ||
@@ -22,3 +22,3 @@ }, | ||
"scripts": { | ||
"pree2e": "yarn build", | ||
"pree2e": "yarn build", | ||
"e2e": "yarn update-e2e && yarn test", | ||
@@ -40,5 +40,7 @@ "force-clean": "rimraf ./test/e2e/webpack*/node_modules/ ./test/e2e/webpack*/tests/**/*.test.js", | ||
"repository": "https://github.com/retyui/clean-css-loader", | ||
"author": "David <4661784+retyui@users.noreply.github.com>", | ||
"author": "David <4661784+retyui@users.noreply.github.com>", | ||
"license": "MIT", | ||
"files": ["lib"], | ||
"files": [ | ||
"lib" | ||
], | ||
"engines": { | ||
@@ -48,15 +50,16 @@ "node": ">= 10.0.0" | ||
"devDependencies": { | ||
"@tsconfig/node10": "^1.0.8", | ||
"@types/clean-css": "^4.2.5", | ||
"@tsconfig/node10": "^1.0.9", | ||
"@types/clean-css": "^4.2.6", | ||
"@types/loader-utils": "^2.0.3", | ||
"@types/node": "^16.9.6", | ||
"@types/node": "^16.18.11", | ||
"@types/schema-utils": "^2.4.0", | ||
"jest": "^27.1.0", | ||
"loader-utils": "^2.0.0", | ||
"prettier": "^2.4.1", | ||
"jest": "^29.3.1", | ||
"loader-utils": "^3.2.1", | ||
"prettier": "^2.8.2", | ||
"rimraf": "^3.0.2", | ||
"schema-utils": "^3.1.1", | ||
"typescript": "^4.4.3", | ||
"webpack": "^5.53.0" | ||
"schema-utils": "^4.0.0", | ||
"source-maps": "^1.0.12", | ||
"typescript": "^4.9.4", | ||
"webpack": "^5.75.0" | ||
} | ||
} |
@@ -15,2 +15,3 @@ <div align="center"> | ||
[](https://github.com/retyui/clean-css-loader/actions/workflows/nodejs.yml) | ||
[](https://packagephobia.com/result?p=clean-css-loader) | ||
[](https://www.npmjs.com/package/clean-css-loader) | ||
@@ -33,3 +34,2 @@ | ||
module.exports = { | ||
mode: isProduction ? "production" : "development", | ||
module: { | ||
@@ -82,4 +82,8 @@ rules: [ | ||
#### `sourceMap: boolean` | ||
Enables/Disables generation of source maps. (default: `compiler.devtool`) | ||
## `CleanCSS` module options | ||
- [clean-css/clean-css#constructor-options](https://github.com/jakubpawlowicz/clean-css#constructor-options) |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
16982
2.37%302
1%87
4.82%0
-100%13
8.33%6
-14.29%2
100%