-
Notifications
You must be signed in to change notification settings - Fork 0
/
craco.config.js
94 lines (88 loc) · 2.49 KB
/
craco.config.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const path = require('path')
const CracoAntDesignPlugin = require('craco-antd')
const CracoAlias = require('craco-alias')
const CracoLessPlugin = require('craco-less')
const cracoPluginStyleResourcesLoader = require('craco-plugin-style-resources-loader')
const isDevelopmentMode = process.env.NODE_ENV === 'development'
module.exports = {
// 允许使用装饰器语法
// https://babeljs.io/docs/en/babel-plugin-proposal-decorators#legacy
babel: {
assumptions: {
setPublicClassFields: true,
},
plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]],
},
plugins: [
// 使用路径别名
{
plugin: CracoAlias,
options: {
// 从 '/jsconfig.json' 中的获取配置
source: 'jsconfig',
},
},
// 使用 antd
{
plugin: CracoAntDesignPlugin,
options: {
// 自定义样式 .less 文件路径
customizeThemeLessPath: path.resolve(__dirname, './src/antd.customize.less'),
babelPluginImportOptions: {
libraryName: 'antd',
libraryDirectory: 'es',
style: true,
},
},
},
// 使用 less, 并支持 css-module
{
// 1. 一般的'.less'
plugin: CracoLessPlugin,
options: {
lessLoaderOptions: {
lessOptions: {
javascriptEnabled: true,
},
},
modifyLessRule: function (lessRule, _context) {
lessRule.test = /\.less$/
lessRule.exclude = /\.module\.less$/
return lessRule
},
},
},
{
// 2.使用 css-module 的'.module.less'
plugin: CracoLessPlugin,
options: {
lessLoaderOptions: {
lessOptions: {
javascriptEnabled: true,
},
},
modifyLessRule: function (lessRule, _context) {
lessRule.test = /\.module\.less$/
lessRule.exclude = undefined
return lessRule
},
cssLoaderOptions: {
modules: {
localIdentName: isDevelopmentMode
? '[path]__[name]__[local]_[hash:base64:5]' // 开发模式,显示完整的less文件路径,方便调试
: '[hash:base64:10]',
},
},
},
},
// 全局 less 变量/混入
// 注意: 需要配置在 'CracoAntDesignPlugin' 的后面,否则会报错
{
plugin: cracoPluginStyleResourcesLoader,
options: {
patterns: path.join(__dirname, './src/styles/*.less'),
styleType: 'less',
},
},
],
}