Skip to content

Commit 13ff5ba

Browse files
committed
inject own postcss config before original config
1 parent 74a4fb8 commit 13ff5ba

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

generator/index.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
function loadModule(src, filename) {
5+
var Module = module.constructor;
6+
var m = new Module();
7+
m._compile(src, filename);
8+
return m.exports;
9+
}
10+
11+
function readPostcssConfig(generator) {
12+
const filename = 'postcss.config.js';
13+
const file = generator.files[filename];
14+
15+
if (file) {
16+
const filePath = path.join(generator.context, filename);
17+
fs.writeFileSync(filePath, '');
18+
return loadModule(file, filename);
19+
}
20+
21+
const config = generator.originalPkg.postcss;
22+
if (config) {
23+
const copy = { ...config };
24+
delete config.plugins;
25+
return copy;
26+
}
27+
28+
return {};
29+
}
30+
131
module.exports = (api, options) => {
32+
const postcss = readPostcssConfig(api.generator);
233
const configs = {
334
postcss: {
435
plugins: {
@@ -7,13 +38,9 @@ module.exports = (api, options) => {
738
},
839
},
940
};
10-
api.addConfigTransform('postcss', {
11-
file: {
12-
js: ['postcss.config.js'],
13-
json: ['.postcssrc.json', '.postcssrc'],
14-
yaml: ['.postcssrc.yaml', '.postcssrc.yml'],
15-
},
16-
});
41+
42+
configs.postcss.plugins = { ...configs.postcss.plugins, ...postcss.plugins };
43+
1744
api.extendPackage(configs);
1845

1946
api.injectImports(api.entryFile, `import './assets/tailwind.css'`);

0 commit comments

Comments
 (0)