create-react-app craco配置参考
    https://juejin.cn/post/6896304919851368461#heading-10

    webpackConfig的配置,可以用 configure覆盖
    webpackConfig.png

    暴露的 Api

    1. const { when, whenDev, whenProd, whenTest, ESLINT_MODES, POSTCSS_MODES } = require("@craco/craco");
    2. module.exports = {
    3. reactScriptsVersion: "react-scripts" /* (default value) */,
    4. style: {
    5. modules: {
    6. localIdentName: ""
    7. },
    8. css: {
    9. loaderOptions: { /* Any css-loader configuration options: https://github.com/webpack-contrib/css-loader. */ },
    10. loaderOptions: (cssLoaderOptions, { env, paths }) => { return cssLoaderOptions; }
    11. },
    12. sass: {
    13. loaderOptions: { /* Any sass-loader configuration options: https://github.com/webpack-contrib/sass-loader. */ },
    14. loaderOptions: (sassLoaderOptions, { env, paths }) => { return sassLoaderOptions; }
    15. },
    16. postcss: {
    17. mode: "extends" /* (default value) */ || "file",
    18. plugins: [],
    19. env: {
    20. autoprefixer: { /* Any autoprefixer options: https://github.com/postcss/autoprefixer#options */ },
    21. stage: 3, /* Any valid stages: https://cssdb.org/#staging-process. */
    22. features: { /* Any CSS features: https://preset-env.cssdb.org/features. */ }
    23. },
    24. loaderOptions: { /* Any postcss-loader configuration options: https://github.com/postcss/postcss-loader. */ },
    25. loaderOptions: (postcssLoaderOptions, { env, paths }) => { return postcssLoaderOptions; }
    26. }
    27. },
    28. eslint: {
    29. enable: true /* (default value) */,
    30. mode: "extends" /* (default value) */ || "file",
    31. configure: { /* Any eslint configuration options: https://eslint.org/docs/user-guide/configuring */ },
    32. configure: (eslintConfig, { env, paths }) => { return eslintConfig; },
    33. loaderOptions: { /* Any eslint-loader configuration options: https://github.com/webpack-contrib/eslint-loader. */ },
    34. loaderOptions: (eslintOptions, { env, paths }) => { return eslintOptions; }
    35. },
    36. babel: {
    37. presets: [],
    38. plugins: [],
    39. loaderOptions: { /* Any babel-loader configuration options: https://github.com/babel/babel-loader. */ },
    40. loaderOptions: (babelLoaderOptions, { env, paths }) => { return babelLoaderOptions; }
    41. },
    42. typescript: {
    43. enableTypeChecking: true /* (default value) */
    44. },
    45. webpack: {
    46. alias: {},
    47. plugins: [],
    48. configure: { /* Any webpack configuration options: https://webpack.js.org/configuration */ },
    49. configure: (webpackConfig, { env, paths }) => { return webpackConfig; }
    50. },
    51. jest: {
    52. babel: {
    53. addPresets: true, /* (default value) */
    54. addPlugins: true /* (default value) */
    55. },
    56. configure: { /* Any Jest configuration options: https://jestjs.io/docs/en/configuration. */ },
    57. configure: (jestConfig, { env, paths, resolve, rootDir }) => { return jestConfig; }
    58. },
    59. devServer: { /* Any devServer configuration options: https://webpack.js.org/configuration/dev-server/#devserver. */ },
    60. devServer: (devServerConfig, { env, paths, proxy, allowedHost }) => { return devServerConfig; },
    61. plugins: [
    62. {
    63. plugin: {
    64. overrideCracoConfig: ({ cracoConfig, pluginOptions, context: { env, paths } }) => { return cracoConfig; },
    65. overrideWebpackConfig: ({ webpackConfig, cracoConfig, pluginOptions, context: { env, paths } }) => { return webpackConfig; },
    66. overrideDevServerConfig: ({ devServerConfig, cracoConfig, pluginOptions, context: { env, paths, proxy, allowedHost } }) => { return devServerConfig; },
    67. overrideJestConfig: ({ jestConfig, cracoConfig, pluginOptions, context: { env, paths, resolve, rootDir } }) => { return jestConfig },
    68. },
    69. options: {}
    70. }
    71. ]
    72. };