Skip to content

Commit 32ec3b3

Browse files
authored
chore: add css params in json format (#549)
this will be used to enable using JSON imports for theming parameters now there is either an inline .js import or a .css import which bundlers might try to inject in the head
1 parent 0127c2f commit 32ec3b3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/main/config/postcss.bundles/postcss.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const postcssImport = require('postcss-import');
22
const combineSelectors = require('postcss-combine-duplicated-selectors');
33
const postcssCSStoESM = require('../../lib/postcss-css-to-esm/index.js');
4+
const postcssCSStoJSON = require('../../lib/postcss-css-to-json/index.js');
45
const postcssDerivedColors = require('../../lib/postcss-process-derived-colors/index');
56
const cssnano = require('cssnano');
67
const postcssAddFallback = require('../../lib/postcss-add-fallback/index.js');
@@ -19,5 +20,6 @@ module.exports = {
1920
},
2021
]}, ),
2122
postcssCSStoESM(),
23+
postcssCSStoJSON(),
2224
]
2325
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const postcss = require('postcss');
2+
const fs = require('fs');
3+
const path = require('path');
4+
const mkdirp = require('mkdirp');
5+
6+
module.exports = postcss.plugin('add css to JSON transform plugin', function (opts) {
7+
opts = opts || {};
8+
9+
return function (root) {
10+
const css = root.toString();
11+
const targetFile = root.source.input.from.replace("/src/", "/dist/").replace("\\src\\", "\\dist\\");
12+
13+
mkdirp.sync(path.dirname(targetFile));
14+
15+
const filePath = `${targetFile}.json`;
16+
17+
fs.writeFileSync(filePath, JSON.stringify({_: css}));
18+
19+
}
20+
});

0 commit comments

Comments
 (0)