@pwrs/lit-css 2.0.0 → 3.0.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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UglifyCSSOptions } from 'uglifycss';
1
+ import { Options as CssnanoOptions } from 'cssnano';
2
2
  export interface Meta {
3
3
  /**
4
4
  * Path to the source file being transformed
@@ -27,10 +27,10 @@ export interface Options {
27
27
  */
28
28
  tag?: string;
29
29
  /**
30
- * Whether to uglify the CSS. Can also be an object of uglifycss options
30
+ * Whether to minify the CSS using cssnano. can also be an object of css nano options.
31
31
  * @default false
32
32
  */
33
- uglify?: boolean | UglifyCSSOptions;
33
+ cssnano?: boolean | CssnanoOptions;
34
34
  /**
35
35
  * Transform sources using tools like sass or postcss
36
36
  * @param source Source file contents e.g. scss or postcss sources
@@ -39,4 +39,4 @@ export interface Options {
39
39
  */
40
40
  transform?(source: string, meta: Meta): string | Promise<string>;
41
41
  }
42
- export declare function transform({ css: source, filePath, specifier, tag, uglify, transform, }: Options): Promise<string>;
42
+ export declare function transform({ css: source, filePath, specifier, tag, cssnano, transform, }: Options): Promise<string>;
package/lit-css.js CHANGED
@@ -1,22 +1,21 @@
1
- import stringToTemplateLiteral from "string-to-template-literal";
2
- import { processString } from "uglifycss";
3
- async function transform({
4
- css: source,
5
- filePath,
6
- specifier = "lit",
7
- tag = "css",
8
- uglify = false,
9
- transform: transform2 = (x) => x
10
- }) {
11
- const css = await transform2(source, { filePath });
12
- const uglifyOptions = typeof uglify === "object" ? uglify : void 0;
13
- const cssContent = !uglify ? css : processString(css, uglifyOptions);
14
- return `import {${tag}} from '${specifier}';
1
+ import cssnano from 'cssnano';
2
+ function stringToTemplateLiteral(x = '') {
3
+ x = `${x}`;
4
+ const escaped = x.replace(/\\|`|\$(?={)|(?<=<)\//g, y => `\\${y}`);
5
+ return `\`${escaped}\``;
6
+ }
7
+ async function cssnanoify(css, options) {
8
+ const cssnanoOptions = typeof options === 'object' ? options : undefined;
9
+ const result = await cssnano(cssnanoOptions).process(css);
10
+ return result.css;
11
+ }
12
+ export async function transform({ css: source, filePath, specifier = 'lit', tag = 'css', cssnano = false, transform = x => x, }) {
13
+ const css = await transform(source, { filePath });
14
+ const cssContent = cssnano ? await cssnanoify(css, cssnano)
15
+ : css;
16
+ return `import {${tag}} from '${specifier}';
15
17
  export const styles = ${tag}${stringToTemplateLiteral(cssContent)};
16
18
  export default styles;
17
19
  `;
18
20
  }
19
- export {
20
- transform
21
- };
22
- //# sourceMappingURL=lit-css.js.map
21
+ //# sourceMappingURL=lit-css.js.map
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.0.0",
4
+ "version": "3.0.0",
5
5
  "type": "module",
6
6
  "main": "lit-css.js",
7
7
  "types": "lit-css.d.ts",
@@ -30,7 +30,6 @@
30
30
  "lit-css.d.ts"
31
31
  ],
32
32
  "dependencies": {
33
- "string-to-template-literal": "^2.0.0",
34
- "uglifycss": "^0.0.29"
33
+ "cssnano": "^6.1.2"
35
34
  }
36
35
  }