This repository has been archived by the owner on Feb 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcraco.config.js
73 lines (68 loc) · 1.87 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
const { ESLINT_MODES } = require('@craco/craco');
const path = require('path');
const SassRuleRewirer = require('react-app-rewire-sass-rule');
const LessPlugin = require('craco-less');
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
const styleVariables = require('./src/styleVariables');
function withCustomScssLoader({ webpackConfig, context }) {
return new SassRuleRewirer()
.withRuleOptions({
use: [
{
loader: '@epegzz/sass-vars-loader',
options: {
syntax: 'scss',
vars: styleVariables,
},
},
],
})
.withLoaderOptions({
includePaths: [path.resolve(__dirname, './src')],
})
.rewire(webpackConfig, context.env);
}
function withFilterWarningsPluginForCssImportOrderConflict({ webpackConfig }) {
const filterOrderConflictWarnings = new FilterWarningsPlugin({
exclude: /Conflicting order between:/,
});
webpackConfig.plugins.push(filterOrderConflictWarnings);
return webpackConfig;
}
function makeOverrideWebpackPlugin(overrideFunction) {
return {
plugin: {
overrideWebpackConfig: overrideFunction,
},
};
}
module.exports = {
babel: {
plugins: [
['import', { libraryName: 'antd', libraryDirectory: 'es', style: 'css' }],
],
},
eslint: {
mode: ESLINT_MODES.file,
},
plugins: [
makeOverrideWebpackPlugin(withCustomScssLoader),
makeOverrideWebpackPlugin(
withFilterWarningsPluginForCssImportOrderConflict
),
{
plugin: LessPlugin,
options: {
lessLoaderOptions: {
javascriptEnabled: true,
modifyVars: Object.entries(styleVariables)
.map(([name, value]) => [`@${name}`, value])
.reduce((lessVars, [name, value]) => {
lessVars[name] = value;
return lessVars;
}),
},
},
},
],
};