Skip to content

Commit 286f094

Browse files
authored
fix(postcss-atomizer): Avoid duplicate CSS (#970)
1 parent a04431d commit 286f094

File tree

7 files changed

+52
-14
lines changed

7 files changed

+52
-14
lines changed

.changeset/metal-flies-look.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"postcss-atomizer": major
3+
---
4+
5+
fix: postcss atomizer to avoid duplicate CSS

docs/integrations/nextjs.md

+16
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ module.exports = {
5555

5656
<p class="noteBox info">Plugin options are available in the <a href="https://github.com/acss-io/atomizer/tree/main/packages/postcss-atomizer">postcss-atomizer</a> README.</p>
5757

58+
## Create the atomizer css file
59+
60+
```css
61+
/* atomizer.css */
62+
@atomizer;
63+
```
64+
65+
## Reference the atomizer.css from your Layout
66+
67+
Update the `./src/app/layout.js` to use the Atomizer css
68+
69+
```js
70+
import './atomizer.css';
71+
// ...
72+
```
73+
5874
## Begin using Atomizer
5975

6076
Update the `./src/app/page.js` file to start adding Atomizer classes to your code base.

docs/integrations/postcss.md

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ module.exports = {
3030

3131
<p class="noteBox info">Option information and an example is available in the <a href="https://github.com/acss-io/atomizer/tree/main/packages/postcss-atomizer">postcss-atomizer</a> repository.</p>
3232

33+
## Add Atomizer to your main.css file
34+
35+
```css
36+
/* main.css */
37+
@atomizer;
38+
```
39+
3340
## Start your dev setup
3441

3542
Run your build setup as configured in your project's `./package.json`.

packages/postcss-atomizer/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ module.exports = {
2323
};
2424
```
2525

26+
Create a css file for the generated atomizer CSS:
27+
28+
```css
29+
/* atomizer.css */
30+
@atomizer;
31+
```
32+
2633
The plugin will automatically execute Atomizer based on your project's [`atomizer.config.js`](https://acss-io.github.io/atomizer/configuration.html) file and pass the rendered CSS to any additional plugins you configure.
2734

2835
### Options

packages/postcss-atomizer/example/__tests__/postcss.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { join } = require('path');
44

55
describe('postcss', () => {
66
it('should create post css', async () => {
7-
const input = '/* dummy test */';
7+
const input = '/* dummy test */@atomizer';
88
const output = '';
99
const atomizer = atomizerPlugin({
1010
config: join(__dirname, '..', 'atomizer.config.js'),
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/* Stub css file for postcss */
2+
@atomizer;

packages/postcss-atomizer/src/index.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@ module.exports = (options = {}) => {
1212
return {
1313
postcssPlugin: 'postcss-atomizer',
1414
Root(root, { result }) {
15-
const config = getConfig(finalOptions.config);
16-
const files = findFiles(config.content);
15+
root.walkAtRules('atomizer', (atRule) => {
16+
const config = getConfig(finalOptions.config);
17+
const files = findFiles(config.content);
1718

18-
// register dependency so atomizer is re-run when the file changes
19-
// @see https://postcss.org/docs/writing-a-postcss-plugin#step-change-nodes
20-
for (const file of files) {
21-
result.messages.push({
22-
file: resolve(file),
23-
parent: result.opts.from,
24-
plugin: 'atomizer',
25-
type: 'dependency',
26-
});
27-
}
19+
// register dependency so atomizer is re-run when the file changes
20+
// @see https://postcss.org/docs/writing-a-postcss-plugin#step-change-nodes
21+
for (const file of files) {
22+
result.messages.push({
23+
file: resolve(file),
24+
parent: result.opts.from,
25+
plugin: 'atomizer',
26+
type: 'dependency',
27+
});
28+
}
2829

29-
root.append(buildAtomicCss(files, config, finalOptions));
30+
atRule.replaceWith(buildAtomicCss(files, config, finalOptions));
31+
});
3032
},
3133
};
3234
};

0 commit comments

Comments
 (0)