forked from subscan-explorer/subscan-multisig-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
craco.config.js
102 lines (98 loc) · 3.61 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
95
96
97
98
99
100
101
102
const AntDesignThemePlugin = require('antd-theme-webpack-plugin');
const path = require('path');
const antdVarsPath = './src/theme/antd/vars.less';
const CracoAntDesignPlugin = require('craco-antd');
const { getLessVars } = require('antd-theme-generator');
const themeVariables = getLessVars(path.join(__dirname, antdVarsPath));
const defaultVars = getLessVars(path.join(__dirname, './node_modules/antd/lib/style/themes/default.less'));
const darkVars = {
...getLessVars(path.join(__dirname, './node_modules/antd/lib/style/themes/dark.less')),
'@primary-color': defaultVars['@primary-color'],
'@picker-basic-cell-active-with-range-color': 'darken(@primary-color, 20%)',
};
const lightVars = {
...getLessVars(path.join(__dirname, './node_modules/antd/lib/style/themes/compact.less')),
'@primary-color': defaultVars['@primary-color'],
};
const { alias, configPaths } = require('react-app-rewire-alias');
// just for dev purpose, use to compare vars in different theme.
// fs.writeFileSync('./ant-theme-vars/dark.json', JSON.stringify(darkVars));
// fs.writeFileSync('./ant-theme-vars/light.json', JSON.stringify(lightVars));
// fs.writeFileSync('./ant-theme-vars/theme.json', JSON.stringify(themeVariables));
const options = {
antDir: path.join(__dirname, './node_modules/antd'),
stylesDir: path.join(__dirname, './src'),
varFile: path.join(__dirname, antdVarsPath),
themeVariables: Array.from(
new Set([...Object.keys(darkVars), ...Object.keys(lightVars), ...Object.keys(themeVariables)])
),
indexFileName: './public/index.html',
generateOnce: false,
publicPath: '',
customColorRegexArray: [],
};
const themePlugin = new AntDesignThemePlugin(options);
module.exports = {
babel: {
presets: [
[
'@babel/preset-env',
{
modules: false, // 对ES6的模块文件不做转化,以便使用tree shaking、sideEffects等
useBuiltIns: 'entry', // browserslist环境不支持的所有垫片都导入
// https://babeljs.io/docs/en/babel-preset-env#usebuiltins
// https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md
corejs: {
version: 3, // 使用core-js@3
proposals: true,
},
},
],
],
plugins: [
['@babel/plugin-proposal-private-methods', { loose: true }],
// 配置 babel-plugin-import
// ['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }, 'antd'],
// 配置解析器
// ['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
// ['babel-plugin-styled-components', { displayName: true }],
],
loaderOptions: (babelLoaderOptions, { env, paths }) => {
return babelLoaderOptions;
},
},
style: {
postcss: {
plugins: [require('tailwindcss'), require('autoprefixer')],
},
},
plugins: [
{
plugin: CracoAntDesignPlugin,
options: {
customizeThemeLessPath: path.join(__dirname, 'src/theme/antd/vars.less'),
},
},
],
webpack: {
plugins: {
add: [themePlugin],
},
// .
// add mjs compatibility configuration
configure: (webpackConfig) => {
webpackConfig.module.rules.push({
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
});
webpackConfig.module.rules.push({
test: /\.js$/,
loader: require.resolve('@open-wc/webpack-import-meta-loader'),
});
const config = alias(configPaths(path.join(__dirname, './tsconfig.paths.json')))(webpackConfig);
return config;
},
},
};