-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcraco.config.js
107 lines (99 loc) · 3.26 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
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const devMode = process.env.NODE_ENV !== 'production';
module.exports = {
paths: {
appSrc: path.resolve(__dirname, './src'),
appIndexJs: path.resolve(__dirname, './src/index.tsx'),
},
babel: {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
plugins: [],
},
webpack: {
configure: (webpackConfig, { env, paths }) => {
// Modify the output filename for JavaScript bundles
webpackConfig.output.filename = 'index.js';
webpackConfig.output.chunkFilename = '[name].[contenthash:8].chunk.js';
webpackConfig.output.libraryTarget = 'umd';
webpackConfig.output.globalObject = 'this';
// Modify the output filename for CSS bundles (assuming you're using MiniCssExtractPlugin)
const miniCssPluginIndex = webpackConfig.plugins.findIndex(
(plugin) => plugin.constructor.name === 'MiniCssExtractPlugin'
);
if (miniCssPluginIndex !== -1) {
webpackConfig.plugins[miniCssPluginIndex].options.filename =
'[name].css';
}
// Add a rule for handling image files
webpackConfig.module.rules.push({
test: /\.(png|jpe?g|gif|svg)$/i,
use: [
{
loader: 'file-loader',
options: {
name: 'media/[name].[hash].[ext]', // Customize the output path for images
},
},
],
});
// Add your specific source-map-loader rule
webpackConfig.module.rules.push({
test: /\.js$/,
enforce: 'pre',
use: ['source-map-loader'],
});
// // Set the ignoreWarnings property
webpackConfig.ignoreWarnings = [/Failed to parse source map/];
// Add a rule for handling CSS files with postcss-loader and css-loader
webpackConfig.module.rules.push({
test: /\.css$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
mode: 'local',
auto: true,
exportGlobals: true,
localIdentName: '[path][name]__[local]--[hash:base64:5]',
localIdentContext: path.resolve(__dirname, 'src'),
localIdentHashSalt: 'bakrypt',
namedExport: true,
exportLocalsConvention: 'as-is',
exportOnlyLocals: false,
},
},
},
'postcss-loader',
],
include: [path.resolve(__dirname, 'not_exist_path')],
});
return webpackConfig;
},
},
jest: {
verbose: true,
configure: (jestConfig, { env, paths, resolve, rootDir }) => {
/* ... */
jestConfig.preset = 'ts-jest';
jestConfig.transform = {
'^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest',
};
jestConfig.transformIgnorePatterns = [
'./node_modules/',
'/node_modules/',
];
jestConfig.moduleNameMapper = {
'^axios$': 'axios/dist/node/axios.cjs',
'\\.(css|less)$': `${rootDir}/src/jest/__mocks__/styleMock.js`,
};
return jestConfig;
},
},
};