Skip to content

Commit 3e0e90f

Browse files
author
mcha
committed
feat: use default tailwind separator ":"
1 parent 42b3ae2 commit 3e0e90f

5 files changed

Lines changed: 38 additions & 25 deletions

File tree

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
node-version: ${{ matrix.node-version }}
3030
- run: npm ci
3131
- run: npm run build --if-present
32-
# - run: npm test
32+
- run: npm test
3333

3434
publish:
3535
if: ${{ github.ref == 'refs/heads/main' }}

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
# rollup-plugin-lit-tailwindcss
22

33
```js
4-
import litTw from 'rollup-plugin-lit-tailwindcss';
4+
import litTailwind from 'rollup-plugin-lit-tailwindcss';
55

66
export default {
77
input: 'src/index.ts',
88
output: {
99
dir: 'dist',
1010
},
1111
plugins: [
12-
litTw({
12+
litTailwind({
1313
include: 'src/components/**/*.ts',
1414
placeholder: 'tw_placeholder',
15+
placeholder: undefined,
1516
}),
1617
],
1718
};
1819
```
1920

20-
lit component
21+
Then in `lit` component file:
2122

2223
```ts
2324
import { html, css, LitElement } from 'lit';
2425
import { customElement } from 'lit/decorators.js';
2526

26-
@customElement('simple-component')
27+
@customElement('simple-footer')
2728
export class SimpleComponent extends LitElement {
28-
static styles = css`tw_placeholder`;
29+
static styles = css`tw_placeholder`; // 👈 classes will be injected here
2930

3031
render() {
31-
return html`<h1 class="text-purple-400 hover_text-green-500">Hello, world!</h1>`;
32+
return html`<h1
33+
class="text-purple-400 md:text-red-400 md:hover:text-green-500"
34+
>
35+
Hello, world!
36+
</h1>`;
3237
}
3338
}
3439
```
3540

36-
## Todos
37-
41+
## Todo
3842
- is this performant???
39-
- tailwind separator (`_` to default one `:`)
4043
- read tailwind config, styles.css?
4144
- ...

src/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import tailwindcss from 'tailwindcss';
44
import autoprefixer from 'autoprefixer';
55

66
function postcssTw(purgeFile) {
7-
const processors = [
7+
const plugins = [
88
tailwindcss({
99
config: { mode: 'jit', purge: [purgeFile], separator: ':' },
1010
}),
1111
autoprefixer,
1212
];
13-
return postcss(processors).process('@tailwind utilities;', {
13+
return postcss(plugins).process('@tailwind utilities;', {
1414
from: undefined,
1515
to: undefined,
1616
});
@@ -33,16 +33,16 @@ export default function litTailwindcss(options = defaultOptions) {
3333

3434
transform(code, id) {
3535
if (!filter(id)) return;
36-
3736
if (code.includes(options.placeholder)) {
38-
return postcssTw(id).then((result) =>
39-
result.css
40-
? code.replace(
41-
options.placeholder,
42-
result.css.replaceAll(':', '\\:'),
43-
)
44-
: null,
45-
);
37+
return postcssTw(id).then((result) => {
38+
if (result.css) {
39+
return code.replace(
40+
options.placeholder,
41+
result.css.replaceAll(':', '\\:'),
42+
);
43+
}
44+
return null;
45+
});
4646
}
4747
return null;
4848
},

tailwind.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// dev only
2+
module.exports = {
3+
purge: [],
4+
darkMode: false, // or 'media' or 'class'
5+
theme: {
6+
extend: {},
7+
},
8+
variants: {
9+
extend: {},
10+
},
11+
plugins: [],
12+
}

test/test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const test = require('ava');
22
const rollup = require('rollup');
33
const { getCode } = require('../helpers');
4-
const litTw = require('..');
4+
const litTailwindcss = require('..');
55

66
process.chdir(__dirname);
77

88
test('processes lit component', async (t) => {
99
const bundle = await rollup.rollup({
1010
input: 'fixtures/component.js',
1111
plugins: [
12-
litTw({
12+
litTailwindcss({
1313
include: 'fixtures/component.js',
1414
placeholder: 'tw_placeholder',
1515
}),
@@ -18,5 +18,3 @@ test('processes lit component', async (t) => {
1818

1919
t.snapshot(await getCode(bundle));
2020
});
21-
22-

0 commit comments

Comments
 (0)