@telegraph/postcss-config 0.0.28 → 0.0.30
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/CHANGELOG.md +14 -0
- package/README.md +289 -4
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @telegraph/postcss-config
|
|
2
2
|
|
|
3
|
+
## 0.0.30
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`0474256`](https://github.com/knocklabs/telegraph/commit/047425631c37101998e39896a34812da5bd4dcbb)]:
|
|
8
|
+
- @telegraph/tokens@0.1.2
|
|
9
|
+
|
|
10
|
+
## 0.0.29
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [[`fd14d50`](https://github.com/knocklabs/telegraph/commit/fd14d509c3f3f76eafc07d08c73e30db79255a2e)]:
|
|
15
|
+
- @telegraph/tokens@0.1.1
|
|
16
|
+
|
|
3
17
|
## 0.0.28
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,14 +1,299 @@
|
|
|
1
|
+
# ⚙️ PostCSS Config
|
|
2
|
+
|
|
3
|
+
> Shared PostCSS configuration for Telegraph projects with optimized plugins and design token integration.
|
|
4
|
+
|
|
1
5
|

|
|
2
6
|
|
|
3
7
|
[](https://www.npmjs.com/package/@telegraph/postcss-config)
|
|
8
|
+
[](https://bundlephobia.com/result?p=@telegraph/postcss-config)
|
|
9
|
+
[](https://github.com/knocklabs/telegraph/blob/main/LICENSE)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @telegraph/postcss-config
|
|
15
|
+
```
|
|
4
16
|
|
|
5
|
-
|
|
6
|
-
> Shared `PostCSS` config for internal use in the telegraph project.
|
|
17
|
+
> **Note**: This package has no stylesheets required.
|
|
7
18
|
|
|
19
|
+
## Quick Start
|
|
8
20
|
|
|
9
|
-
|
|
21
|
+
```js
|
|
22
|
+
// postcss.config.js
|
|
23
|
+
const { styleEnginePostCssConfig } = require("@telegraph/postcss-config");
|
|
10
24
|
|
|
25
|
+
module.exports = styleEnginePostCssConfig;
|
|
11
26
|
```
|
|
12
|
-
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
// Or with ES modules (postcss.config.mjs)
|
|
30
|
+
import { styleEnginePostCssConfig } from "@telegraph/postcss-config";
|
|
31
|
+
|
|
32
|
+
export default styleEnginePostCssConfig;
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## What's Included
|
|
36
|
+
|
|
37
|
+
This configuration includes optimized PostCSS plugins specifically chosen for Telegraph projects:
|
|
38
|
+
|
|
39
|
+
- **`postcss-discard-empty`** - Removes empty CSS rules for cleaner output
|
|
40
|
+
- **`autoprefixer`** - Automatically adds vendor prefixes for browser compatibility
|
|
41
|
+
- **`@csstools/postcss-global-data`** - Provides Telegraph design tokens (breakpoints)
|
|
42
|
+
- **`postcss-custom-media`** - Enables custom media queries using Telegraph breakpoints
|
|
43
|
+
|
|
44
|
+
## API Reference
|
|
45
|
+
|
|
46
|
+
### `styleEnginePostCssConfig`
|
|
47
|
+
|
|
48
|
+
The main PostCSS configuration object that includes all Telegraph-specific plugins and settings.
|
|
49
|
+
|
|
50
|
+
**Type**: `PostCSSConfig`
|
|
51
|
+
|
|
52
|
+
**Returns**: PostCSS configuration object with plugins array
|
|
53
|
+
|
|
54
|
+
## Usage Patterns
|
|
55
|
+
|
|
56
|
+
### Basic PostCSS Config
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
// postcss.config.js
|
|
60
|
+
const { styleEnginePostCssConfig } = require("@telegraph/postcss-config");
|
|
61
|
+
|
|
62
|
+
module.exports = styleEnginePostCssConfig;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### With Webpack
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
// webpack.config.js
|
|
69
|
+
const { styleEnginePostCssConfig } = require("@telegraph/postcss-config");
|
|
70
|
+
|
|
71
|
+
module.exports = {
|
|
72
|
+
module: {
|
|
73
|
+
rules: [
|
|
74
|
+
{
|
|
75
|
+
test: /\.css$/,
|
|
76
|
+
use: [
|
|
77
|
+
"style-loader",
|
|
78
|
+
"css-loader",
|
|
79
|
+
{
|
|
80
|
+
loader: "postcss-loader",
|
|
81
|
+
options: {
|
|
82
|
+
postcssOptions: styleEnginePostCssConfig,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### With Vite
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
// vite.config.js
|
|
96
|
+
import { styleEnginePostCssConfig } from "@telegraph/postcss-config";
|
|
97
|
+
import { defineConfig } from "vite";
|
|
98
|
+
|
|
99
|
+
export default defineConfig({
|
|
100
|
+
css: {
|
|
101
|
+
postcss: styleEnginePostCssConfig,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### With Next.js
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
// next.config.js
|
|
110
|
+
const { styleEnginePostCssConfig } = require("@telegraph/postcss-config");
|
|
111
|
+
|
|
112
|
+
module.exports = {
|
|
113
|
+
experimental: {
|
|
114
|
+
postcss: styleEnginePostCssConfig,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Advanced Usage
|
|
120
|
+
|
|
121
|
+
### Extending the Configuration
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
// postcss.config.js
|
|
125
|
+
const { styleEnginePostCssConfig } = require("@telegraph/postcss-config");
|
|
126
|
+
|
|
127
|
+
module.exports = {
|
|
128
|
+
...styleEnginePostCssConfig,
|
|
129
|
+
plugins: [
|
|
130
|
+
...styleEnginePostCssConfig.plugins,
|
|
131
|
+
// Add your custom plugins
|
|
132
|
+
require("postcss-nested"),
|
|
133
|
+
require("cssnano")({
|
|
134
|
+
preset: "default",
|
|
135
|
+
}),
|
|
136
|
+
],
|
|
137
|
+
};
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Custom Media Queries Usage
|
|
141
|
+
|
|
142
|
+
With this configuration, you can use Telegraph breakpoints in your CSS:
|
|
143
|
+
|
|
144
|
+
```css
|
|
145
|
+
/* Input CSS */
|
|
146
|
+
@custom-media --mobile-and-up (min-width: 480px);
|
|
147
|
+
@custom-media --tablet-and-up (min-width: 768px);
|
|
148
|
+
@custom-media --desktop-and-up (min-width: 1024px);
|
|
149
|
+
|
|
150
|
+
.component {
|
|
151
|
+
padding: 1rem;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@media (--tablet-and-up) {
|
|
155
|
+
.component {
|
|
156
|
+
padding: 2rem;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@media (--desktop-and-up) {
|
|
161
|
+
.component {
|
|
162
|
+
padding: 3rem;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Browser Support
|
|
168
|
+
|
|
169
|
+
The autoprefixer plugin ensures compatibility with:
|
|
170
|
+
|
|
171
|
+
- **Chrome**: Last 2 versions
|
|
172
|
+
- **Firefox**: Last 2 versions
|
|
173
|
+
- **Safari**: Last 2 versions
|
|
174
|
+
- **Edge**: Last 2 versions
|
|
175
|
+
- **iOS Safari**: Last 2 versions
|
|
176
|
+
|
|
177
|
+
## Performance Optimization
|
|
178
|
+
|
|
179
|
+
This configuration is optimized for performance:
|
|
180
|
+
|
|
181
|
+
- **Tree Shaking**: Only includes necessary PostCSS plugins
|
|
182
|
+
- **Build Speed**: Minimal plugin overhead
|
|
183
|
+
- **Output Size**: Removes empty rules and optimizes CSS
|
|
184
|
+
- **Caching**: PostCSS plugins support caching for faster rebuilds
|
|
185
|
+
|
|
186
|
+
## Troubleshooting
|
|
187
|
+
|
|
188
|
+
### Common Issues
|
|
189
|
+
|
|
190
|
+
**Plugin not found errors**
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
# Ensure all peer dependencies are installed
|
|
194
|
+
npm install postcss autoprefixer
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Custom media not working**
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
// Make sure @telegraph/tokens is installed
|
|
201
|
+
npm install @telegraph/tokens
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Autoprefixer not adding prefixes**
|
|
205
|
+
|
|
206
|
+
```js
|
|
207
|
+
// Check your browserslist configuration
|
|
208
|
+
// .browserslistrc or package.json "browserslist" field
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Debug Configuration
|
|
212
|
+
|
|
213
|
+
```js
|
|
214
|
+
// postcss.config.js
|
|
215
|
+
const { styleEnginePostCssConfig } = require("@telegraph/postcss-config");
|
|
216
|
+
|
|
217
|
+
console.log(
|
|
218
|
+
"PostCSS plugins:",
|
|
219
|
+
styleEnginePostCssConfig.plugins.map((p) => p.pluginName),
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
module.exports = styleEnginePostCssConfig;
|
|
13
223
|
```
|
|
14
224
|
|
|
225
|
+
## Examples
|
|
226
|
+
|
|
227
|
+
### Basic Setup
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
// postcss.config.js
|
|
231
|
+
const { styleEnginePostCssConfig } = require("@telegraph/postcss-config");
|
|
232
|
+
|
|
233
|
+
module.exports = styleEnginePostCssConfig;
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Advanced Build Pipeline
|
|
237
|
+
|
|
238
|
+
```js
|
|
239
|
+
// build.config.js
|
|
240
|
+
const { styleEnginePostCssConfig } = require("@telegraph/postcss-config");
|
|
241
|
+
const postcss = require("postcss");
|
|
242
|
+
const fs = require("fs");
|
|
243
|
+
|
|
244
|
+
async function buildCSS() {
|
|
245
|
+
const css = fs.readFileSync("src/styles.css", "utf8");
|
|
246
|
+
|
|
247
|
+
const result = await postcss(styleEnginePostCssConfig.plugins).process(css, {
|
|
248
|
+
from: "src/styles.css",
|
|
249
|
+
to: "dist/styles.css",
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
fs.writeFileSync("dist/styles.css", result.css);
|
|
253
|
+
|
|
254
|
+
if (result.map) {
|
|
255
|
+
fs.writeFileSync("dist/styles.css.map", result.map.toString());
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
buildCSS().catch(console.error);
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Monorepo Configuration
|
|
263
|
+
|
|
264
|
+
```js
|
|
265
|
+
// packages/shared/postcss.config.js
|
|
266
|
+
const { styleEnginePostCssConfig } = require("@telegraph/postcss-config");
|
|
267
|
+
|
|
268
|
+
// Shared configuration for all packages
|
|
269
|
+
module.exports = {
|
|
270
|
+
...styleEnginePostCssConfig,
|
|
271
|
+
plugins: [
|
|
272
|
+
...styleEnginePostCssConfig.plugins,
|
|
273
|
+
// Add monorepo-specific plugins
|
|
274
|
+
require("postcss-import")({
|
|
275
|
+
resolve: (id) => {
|
|
276
|
+
// Custom resolution for monorepo packages
|
|
277
|
+
if (id.startsWith("@company/")) {
|
|
278
|
+
return path.resolve(__dirname, `../${id.split("/")[1]}/src/styles`);
|
|
279
|
+
}
|
|
280
|
+
return id;
|
|
281
|
+
},
|
|
282
|
+
}),
|
|
283
|
+
],
|
|
284
|
+
};
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## References
|
|
288
|
+
|
|
289
|
+
- [PostCSS Documentation](https://postcss.org/)
|
|
290
|
+
- [Autoprefixer Documentation](https://github.com/postcss/autoprefixer)
|
|
291
|
+
- [Telegraph Tokens](../tokens/README.md)
|
|
292
|
+
|
|
293
|
+
## Contributing
|
|
294
|
+
|
|
295
|
+
See our [Contributing Guide](../../CONTRIBUTING.md) for more details.
|
|
296
|
+
|
|
297
|
+
## License
|
|
298
|
+
|
|
299
|
+
MIT License - see [LICENSE](../../LICENSE) for details.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telegraph/postcss-config",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"author": "@knocklabs",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/knocklabs/telegraph/tree/main/packages/postcss-config",
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
"format:check": "prettier \"src/**/*.{js,ts,tsx}\" --check"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@csstools/postcss-global-data": "^3.
|
|
22
|
-
"@telegraph/tokens": "^0.1.
|
|
21
|
+
"@csstools/postcss-global-data": "^3.1.0",
|
|
22
|
+
"@telegraph/tokens": "^0.1.2",
|
|
23
23
|
"autoprefixer": "^10.4.21",
|
|
24
24
|
"postcss": "^8.5.3",
|
|
25
25
|
"postcss-combine-duplicated-selectors": "^10.0.3",
|
|
26
|
-
"postcss-custom-media": "^11.0.
|
|
26
|
+
"postcss-custom-media": "^11.0.6",
|
|
27
27
|
"postcss-discard-empty": "^7.0.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@knocklabs/eslint-config": "^0.0.
|
|
30
|
+
"@knocklabs/eslint-config": "^0.0.5",
|
|
31
31
|
"@knocklabs/typescript-config": "^0.0.2",
|
|
32
32
|
"@telegraph/prettier-config": "^0.0.7",
|
|
33
33
|
"eslint": "^8.56.0",
|
|
34
|
-
"typescript": "^5.
|
|
34
|
+
"typescript": "^5.9.2"
|
|
35
35
|
}
|
|
36
36
|
}
|