-
Notifications
You must be signed in to change notification settings - Fork 0
/
.rescriptsrc.js
70 lines (63 loc) · 1.99 KB
/
.rescriptsrc.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const fs = require("fs");
const path = require("path");
const lessToJs = require("less-vars-to-js");
const AntDesignThemePlugin = require("./lib/antd-theme-webpack-plugin");
const generatorColorLess = require("./lib/generatorColorLess");
module.exports = [
["use-babel-config", ".babelrc"],
["use-eslint-config", ".eslintrc"],
config => {
const newConfig = config;
let rule = newConfig.module.rules.find(rule => rule.oneOf);
const paletteLess = fs.readFileSync("./src/styles/variables.less", "utf8");
const variables = lessToJs(paletteLess);
// 生成 color less
generatorColorLess();
// 生成 initialValue
const colorLessBase = fs.readFileSync(
"./node_modules/antd/lib/style/color/colors.less",
"utf8"
);
const colorBase = lessToJs(colorLessBase);
const themesLessBase = fs.readFileSync(
"./node_modules/antd/lib/style/themes/default.less",
"utf8"
);
const themesBase = lessToJs(themesLessBase);
let baseLess = { ...colorBase, ...themesBase, ...variables };
fs.writeFileSync(
path.join(__dirname, "./src/initialValue.js"),
`export default ${JSON.stringify(baseLess)};`
);
const options = {
antDir: path.join(__dirname, "./node_modules/antd"),
stylesDir: path.join(__dirname, "./src/styles"),
varFile: path.join(__dirname, "./src/styles/variables.less"),
mainLessFile: path.join(__dirname, "./src/styles/index.less"),
themeVariables: Object.keys(baseLess),
indexFileName: "index.html",
generateOnce: false
};
const themePlugin = new AntDesignThemePlugin(options);
rule.oneOf.unshift({
test: /\.less$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader"
},
{
loader: "less-loader",
options: {
javascriptEnabled: true,
modifyVars: variables
}
}
]
});
config.plugins.push(themePlugin);
return newConfig;
}
];