@pwrs/lit-css 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lit-css.cjs +87194 -7
- package/lit-css.d.ts +8 -1
- package/lit-css.js +13 -2
- package/package.json +2 -1
package/lit-css.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UglifyCSSOptions } from 'uglifycss';
|
|
2
|
+
import { Options as CssnanoOptions } from 'cssnano';
|
|
2
3
|
export interface Meta {
|
|
3
4
|
/**
|
|
4
5
|
* Path to the source file being transformed
|
|
@@ -29,8 +30,14 @@ export interface Options {
|
|
|
29
30
|
/**
|
|
30
31
|
* Whether to uglify the CSS. Can also be an object of uglifycss options
|
|
31
32
|
* @default false
|
|
33
|
+
* @deprecated: use `minify`
|
|
32
34
|
*/
|
|
33
35
|
uglify?: boolean | UglifyCSSOptions;
|
|
36
|
+
/**
|
|
37
|
+
* Whether to minify the CSS using cssnano. can also be an object of css nano options.
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
cssnano?: boolean | CssnanoOptions;
|
|
34
41
|
/**
|
|
35
42
|
* Transform sources using tools like sass or postcss
|
|
36
43
|
* @param source Source file contents e.g. scss or postcss sources
|
|
@@ -39,4 +46,4 @@ export interface Options {
|
|
|
39
46
|
*/
|
|
40
47
|
transform?(source: string, meta: Meta): string | Promise<string>;
|
|
41
48
|
}
|
|
42
|
-
export declare function transform({ css: source, filePath, specifier, tag, uglify, transform, }: Options): Promise<string>;
|
|
49
|
+
export declare function transform({ css: source, filePath, specifier, tag, uglify, cssnano, transform, }: Options): Promise<string>;
|
package/lit-css.js
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import stringToTemplateLiteral from "string-to-template-literal";
|
|
2
2
|
import { processString } from "uglifycss";
|
|
3
|
+
import cssnano from "cssnano";
|
|
4
|
+
async function cssnanoify(css, options) {
|
|
5
|
+
const cssnanoOptions = typeof options === "object" ? options : void 0;
|
|
6
|
+
const result = await cssnano(cssnanoOptions).process(css);
|
|
7
|
+
return result.css;
|
|
8
|
+
}
|
|
9
|
+
async function uglifycssify(css, options) {
|
|
10
|
+
const uglifyOptions = typeof options === "object" ? options : void 0;
|
|
11
|
+
const result = processString(css, uglifyOptions);
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
3
14
|
async function transform({
|
|
4
15
|
css: source,
|
|
5
16
|
filePath,
|
|
6
17
|
specifier = "lit",
|
|
7
18
|
tag = "css",
|
|
8
19
|
uglify = false,
|
|
20
|
+
cssnano: cssnano2 = false,
|
|
9
21
|
transform: transform2 = (x) => x
|
|
10
22
|
}) {
|
|
11
23
|
const css = await transform2(source, { filePath });
|
|
12
|
-
const
|
|
13
|
-
const cssContent = !uglify ? css : processString(css, uglifyOptions);
|
|
24
|
+
const cssContent = cssnano2 ? await cssnanoify(css, cssnano2) : uglify ? await uglifycssify(css, uglify) : css;
|
|
14
25
|
return `import {${tag}} from '${specifier}';
|
|
15
26
|
export const styles = ${tag}${stringToTemplateLiteral(cssContent)};
|
|
16
27
|
export default styles;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pwrs/lit-css",
|
|
3
3
|
"description": "Import CSS files as css tagged-template literals",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lit-css.js",
|
|
7
7
|
"types": "lit-css.d.ts",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"lit-css.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
+
"cssnano": "^6.0.1",
|
|
33
34
|
"string-to-template-literal": "^2.0.0",
|
|
34
35
|
"uglifycss": "^0.0.29"
|
|
35
36
|
}
|