Skip to content

Commit c2e6ebc

Browse files
authored
fix(postcss-atomizer): register file dependency to re-run atomizer on changes (#651)
1 parent 0508da3 commit c2e6ebc

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

.changeset/long-emus-sit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"postcss-atomizer": patch
3+
---
4+
5+
fix(postcss-atomizer): register file dependency to re-run atomizer on changes

docs/integrations/nextjs.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ module.exports = {
3131
content: [
3232
'./components/**/*.{js,ts,jsx,tsx}',
3333
'./pages/**/*.{js,ts,jsx,tsx}',
34+
35+
// Or if using `src` directory:
36+
'./src/**/*.{js,ts,jsx,tsx}'
3437
],
3538
}
3639
```
@@ -43,26 +46,18 @@ After following their guide, you will add the Atomizer PostCSS plugin like so.
4346

4447
```js
4548
module.exports = {
46-
plugins: {
47-
'postcss-atomizer': {},
48-
// ...
49-
},
49+
plugins: [
50+
// mandatory next.js plugins ...
51+
'postcss-atomizer',
52+
],
5053
}
5154
```
5255

5356
<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>
5457

55-
## Start your build process
56-
57-
Run your build setup as configured in your project's `package.json`.
58-
59-
```shell
60-
npm run dev
61-
```
62-
6358
## Begin using Atomizer
6459

65-
Update the `pages/index.js` file to start adding Atomizer classes to your code base.
60+
Update the `src/app/page.js` file to start adding Atomizer classes to your code base.
6661

6762
```js
6863
export default function Home() {
@@ -71,3 +66,11 @@ export default function Home() {
7166
)
7267
}
7368
```
69+
70+
## Start your build process
71+
72+
Run your build setup as configured in your project's `package.json`.
73+
74+
```shell
75+
npm run dev
76+
```

packages/postcss-atomizer/src/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { buildAtomicCss, getConfig, findFiles } = require('atomizer/src/build.js');
2+
const { resolve } = require('path');
23

34
/**
45
* @type {import('postcss').PluginCreator}
@@ -8,11 +9,23 @@ module.exports = (options = {}) => {
89
quiet: true,
910
...options,
1011
};
11-
const config = getConfig(finalOptions.config);
12-
const files = findFiles(config.content);
1312
return {
1413
postcssPlugin: 'postcss-atomizer',
15-
Root(root) {
14+
Root(root, { result }) {
15+
const config = getConfig(finalOptions.config);
16+
const files = findFiles(config.content);
17+
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+
}
28+
1629
root.append(buildAtomicCss(files, config, finalOptions));
1730
},
1831
};

0 commit comments

Comments
 (0)