forked from commaai/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
craco.config.js
73 lines (68 loc) · 2.06 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 { loaderByName, addBeforeLoader } = require('@craco/craco');
const SentryCliPlugin = require('@sentry/webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const zlib = require('zlib');
const eslintConfig = require('./.eslintrc');
module.exports = ({ env }) => {
let sentryPlugin;
if (env === 'production' && process.env.SENTRY_AUTH_TOKEN) {
sentryPlugin = new SentryCliPlugin({
include: './build/',
ignoreFile: '.sentrycliignore',
ignore: ['node_modules', 'webpack.config.js', 'craco.config.js'],
configFile: 'sentry.properties',
});
}
let compressionPlugin;
if (env === 'production') {
compressionPlugin = new CompressionPlugin({
filename: '[path][base].br',
algorithm: 'brotliCompress',
test: /\.(js|css|html|svg)$/,
compressionOptions: {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
},
},
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false,
});
}
return {
eslint: {
enable: false,
config: eslintConfig,
},
webpack: {
plugins: [
sentryPlugin,
compressionPlugin,
].filter(Boolean),
configure: (webpackConfig) => {
webpackConfig.output.globalObject = 'this';
addBeforeLoader(webpackConfig, loaderByName('babel-loader'), {
test: /\.worker\.js/,
use: { loader: 'worker-loader' },
});
webpackConfig.optimization.minimizer.forEach((plugin) => {
if (plugin.constructor.name !== 'TerserPlugin') {
return;
}
plugin.options.terserOptions = { keep_fnames: true };
});
return webpackConfig;
},
},
jest: {
configure: (jestConfig) => ({
...jestConfig,
moduleNameMapper: {
'^@commaai/(.+)$': '<rootDir>/node_modules/@commaai/$1/dist/index.js',
},
testPathIgnorePatterns: ['node_modules', 'src/__puppeteer__'],
transformIgnorePatterns: ['node_modules/(?!(@commaai/(.+))/)'],
}),
},
};
};