-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharco.env.config.js
77 lines (72 loc) · 2.13 KB
/
arco.env.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
const path = require('path');
const glob = require('glob');
const fs = require('fs-extra');
const ArcoWebpackPlugin = require('@arco-plugins/webpack-react');
function collectPackageResolveAliasForWebpack() {
const packageJsonPaths = glob.sync(path.resolve(__dirname, 'packages/*/package.json'));
const result = {};
for (const packageJsonPath of packageJsonPaths) {
const { name: packageName } = fs.readJsonSync(packageJsonPath);
const srcPath = path.resolve(path.dirname(packageJsonPath), 'src');
if (fs.pathExistsSync(srcPath)) {
result[`${packageName}$`] = srcPath;
}
}
return result;
}
module.exports = function defineConfig() {
const webpackConfigTransformer = (config) => {
const mdxLoader = config.raw.module.rules
.find((rule) => rule.oneOf)
?.oneOf?.find((rule) => rule.test.test('.mdx'))
?.use?.find(({ loader }) => loader.indexOf('/mdx/loader') > -1);
// Auto import component style to __docs__/index.mdx
if (mdxLoader) {
mdxLoader.options.preProcessFile = ({ path: filePath, content }) => {
const componentStyleEntry = '../style/index.ts';
if (fs.existsSync(path.resolve(path.dirname(filePath), componentStyleEntry))) {
return `${content}\nimport '${componentStyleEntry}';`;
}
return content;
};
}
return config.merge({
plugins: [
new ArcoWebpackPlugin({
webpackImplementation: config.webpack,
include: 'packages',
}),
],
resolve: {
alias: {
react: require.resolve('react'),
...collectPackageResolveAliasForWebpack(),
},
},
});
};
return {
jest: {
jestConfigPath: path.resolve(__dirname, './jest.config.js'),
},
webpack: {
previewConfig: [webpackConfigTransformer],
devServerConfig: [webpackConfigTransformer],
},
typescript: {
buildConfig: [
(config) => {
return config;
},
],
},
less: {
// specify options for less.render
lessOptions: {},
},
sass: {
// specify options for sass.compile
sassOptions: {},
},
};
};