forked from kawarimidoll/vuepress-plugin-tailwind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (32 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module.exports = (options = {}, ctx) => {
const { name } = require("./package");
const { options: voptions } = ctx;
const { tailwindConfig, ...others } = options;
const { logger } = require("@vuepress/utils");
const path = require("path");
const process = require("process");
const cwd = process.cwd();
const sourceDir = voptions.source;
const vuepressDir = path.resolve(voptions.source, ".vuepress");
const defaultTailwindConfig = () => {
try {
return require(`${cwd}/tailwind.config.js`);
} catch (e) {
const purge = {
content: [sourceDir, vuepressDir].map(
(dir) => `${dir}/**/*.@(js|ts|md|vue|html)`
),
};
return Object.assign({ purge }, others);
}
};
const plugins = [
require("tailwindcss")(tailwindConfig || defaultTailwindConfig()),
require("autoprefixer"),
];
voptions.bundlerConfig = Object.assign(voptions.bundlerConfig || {}, {
postcss: { postcssOptions: { plugins } },
});
logger.tip(`[${name}] tailwindcss is enabled`);
return { name };
};