-
Notifications
You must be signed in to change notification settings - Fork 0
/
craco.config.js
116 lines (113 loc) · 3.37 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const path = require('path');
const fs = require('fs');
const CracoAlias = require('craco-alias');
const CracoLessPlugin = require('craco-less');
// const { POSTCSS_MODES } = require('@craco/craco');
const { DefinePlugin } = require('webpack');
const OfflinePackagePlugin = require('./OfflinePackagePlugin.js');
const apiHost = process.env.API_HOST || 'dev';
const proxyConfig = {
local: {
'/api': {
target: 'http://127.0.0.1:8100',
secure: false,
changeOrigin: true,
logLevel: 'debug',
pathRewrite: { '^/api': '' },
},
},
};
module.exports = {
style: {
postcss: {
// https://github.com/gsoft-inc/craco/blob/d9b4aae99dd8267311b86ad034f93e5c84040a7d/packages/craco/README.md
loaderOptions: (postcssLoaderOptions, { env, paths }) => {
// postcssLoaderOptions.postcssOptions.plugins =
// postcssLoaderOptions.postcssOptions.plugins.concat([['flex-gap-polyfill', {}]]);
return postcssLoaderOptions;
},
mode: 'extends',
},
},
babel: {
plugins: [
['@babel/plugin-proposal-private-methods', { loose: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-private-property-in-object', { loose: true }],
['react-activation/babel'],
],
presets: [
[
'@babel/preset-env',
{
targets: {
chrome: '49',
ios: '10',
},
},
],
],
},
webpack: {
alias: {
src: path.resolve(__dirname, 'src/'),
'styled-components': path.resolve(__dirname, 'node_modules', 'styled-components'),
},
plugins: [
new DefinePlugin({
'process.env.VERSION': JSON.stringify(require('./package.json').version),
'process.env.WEB': process.env.WEB,
'process.env.TOKEN':
process.env.WEB &&
JSON.stringify(
fs.readFileSync(path.join(__dirname, './.token'), {
encoding: 'utf8',
})
),
}),
new OfflinePackagePlugin({
packageName: 'Leadigital Mobile App',
}),
],
configure: (webpackConfig) => {
// remove ModuleScopePlugin for importing files outside src folder
const scopePluginIndex = webpackConfig.resolve.plugins.findIndex(
({ constructor }) => constructor && constructor.name === 'ModuleScopePlugin'
);
webpackConfig.resolve.plugins.splice(scopePluginIndex, 1);
// Remove sourcemap warning for pinyin
webpackConfig.ignoreWarnings = [
function ignoreSourcemapsloaderWarnings(warning) {
return (
warning.module &&
warning.module.resource.includes('node_modules') &&
warning.details &&
warning.details.includes('source-map-loader')
);
},
];
return webpackConfig;
},
},
devServer: (devServerConfig, { env, paths, proxy, allowedHost }) => {
return {
...devServerConfig,
proxy: proxyConfig[apiHost],
};
},
plugins: [
{
plugin: CracoAlias,
options: {
source: 'tsconfig',
// baseUrl SHOULD be specified
// plugin does not take it from tsconfig
baseUrl: '.',
/* tsConfigPath should point to the file where "baseUrl" and "paths"
are specified*/
tsConfigPath: './tsconfig.paths.json',
},
},
{ plugin: CracoLessPlugin },
],
};