forked from Loopring/loopring-web-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
craco.config.cjs
189 lines (180 loc) · 8.03 KB
/
craco.config.cjs
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
const webpack = require('webpack')
const {addBeforeLoader, loaderByName, getLoader, addPlugins} = require('@craco/craco');
const CopyWebpackPlugin = require('copy-webpack-plugin')
// Try the environment variable, otherwise use root
const ASSET_PATH = process.env.ASSET_PATH || '/'
// const rewireLess = require('react-app-rewire-less')
// const { alias } = require('react-app-rewire-alias')
const path = require('path')
// const GitRevisionPlugin = require('git-revision-webpack-plugin')
// const gitRevisionPlugin = new GitRevisionPlugin()
const direct = './'
const packagesPath = './packages'
module.exports = function ({env}) {
const dev = env === 'development'
const prod = env === 'production'
return {
babel: {
presets: [ /* ... */],
plugins: [
[
"import",
{
libraryName: 'antd',
libraryDirectory: 'es',
style: true,
}
],
],
loaderOptions: { /* ... */},
loaderOptions: (babelLoaderOptions, {env, paths}) => {
const dev = env === 'development'
const prod = env === 'production'
// console.log(babelLoaderOptions)
return babelLoaderOptions;
},
},
webpack: {
alias: {
'@material-ui/core/Menu': '@mui/material/Menu',
'@material-ui/core': '@mui/material',
'@material-ui/core/Popover': '@mui/material/Popover',
process: "process/browser"
},
plugins: {
add: [
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, packagesPath, 'common-resources', 'assets'),
to: './static',
toType: 'dir',
},
],
}),
new webpack.DefinePlugin({
'process.env.TIME':
'"' + new Date().toLocaleString('en-US', {timeZone: 'Asia/Shanghai'}) + '/SH"',
}),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
],
},
configure: (config, {env, paths}) => {
const dev = env === 'development'
const prod = env === 'production'
config.ignoreWarnings = [/Failed to parse source map/];
config.resolve.fallback = Object.assign(config.resolve.fallback ?? {}, {
"crypto": require.resolve("crypto-browserify"),
"crypto-js": require.resolve('crypto-js'),
"crypto-js/sha256": require.resolve('crypto-js/sha256'),
"stream": require.resolve("stream-browserify"),
"assert": require.resolve("assert/"),
"http": require.resolve("stream-http"),
"https": require.resolve("https-browserify"),
"os": require.resolve("os-browserify"),
"url": require.resolve("url/"),
"util": require.resolve("util"),
"buffer": require.resolve("buffer"),
"timers": require.resolve("timers-browserify"),
'process/browser': require.resolve('process/browser')
// "fs": require.resolve('browserify-fs'),
})
config.node = {global: true}
console.log(config.node)
// node: { global: true, fs: 'empty'},
// config.packages({
// packages: [
// {
// name: 'crypto-js',
// location: 'path-to/bower_components/crypto-js',
// main: 'index'
// }
// ]
// });
var {isFound, match} = getLoader(config, loaderByName('babel-loader'));
if (isFound) {
console.log(match.loader)
match.loader.include = [
path.resolve(__dirname, packagesPath),
...[
path.resolve(
__dirname,
`${process.env.NODE_ENV === 'development' ? direct : direct}`,
`node_modules/@web3modal`,
),
path.resolve(
__dirname,
`${process.env.NODE_ENV === 'development' ? direct : direct}`,
`node_modules/@walletconnect`,
),
path.resolve(
__dirname,
`${process.env.NODE_ENV === 'development' ? direct : direct}`,
`node_modules/@metamask`,
),
path.resolve(
__dirname,
`${process.env.NODE_ENV === 'development' ? direct : direct}`,
`node_modules/@scure`,
),
path.resolve(
__dirname,
`${process.env.NODE_ENV === 'development' ? direct : direct}`,
`node_modules/@noble`,
),
path.resolve(
__dirname,
`${process.env.NODE_ENV === 'development' ? direct : direct}`,
`node_modules/@ethereumjs`,
),
path.resolve(
__dirname,
`${process.env.NODE_ENV === 'development' ? direct : direct}`,
`node_modules/micro-ftch`,
),
path.resolve(
__dirname,
`${process.env.NODE_ENV === 'development' ? direct : direct}`,
`node_modules/react-spring`,
),
path.resolve(
__dirname,
`${process.env.NODE_ENV === 'development' ? direct : direct}`,
`node_modules/@react-spring`,
),
path.resolve(
__dirname,
`${process.env.NODE_ENV === 'development' ? direct : direct}`,
`node_modules/@loopring-web/loopring-sdk`,
),
],
]
}
config.resolve.extensions.push('.html');
config.resolve.extensions.push('.md');
addBeforeLoader(config, loaderByName('babel-loader'), {
loader: 'html-loader',
test: /\.html$/i,
exclude: [/node_modules/, /index.html/i],
options: {
attrs: [':data-src'],
minimize: true,
removeComments: false,
collapseWhitespace: false,
},
});
addBeforeLoader(config, loaderByName('babel-loader'), {
test: /\.md$/,
use: 'raw-loader',
});
// }
return config;
},
},
};
};