How to use the @craco/craco.whenProd function in @craco/craco

To help you get started, we’ve selected a few @craco/craco examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spaxjs / spax / packages / boilerplate-grommet / craco.config.js View on Github external
const path = require("path");
const { whenProd } = require("@craco/craco");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");

const getAliasForCommonLibraries = (modules) => {
  return modules.reduce((obj, name) => {
    return Object.assign(obj, {
      [name]: path.resolve(__dirname, "node_modules", name)
    });
  }, {});
};

module.exports = {
  webpack: {
    plugins: whenProd([new BundleAnalyzerPlugin()], [])
  },
  plugins: [
    {
      plugin: {
        overrideWebpackConfig: ({ webpackConfig }) => {
          if (!webpackConfig.resolve) webpackConfig.resolve = {};
          if (!webpackConfig.resolve.alias) webpackConfig.resolve.alias = {};
          Object.assign(
            webpackConfig.resolve.alias,
            getAliasForCommonLibraries([
              "react",
              "react-dom",
              "react-hot-loader",
              "@types/node",
              "@types/react",
              "@types/react-dom"
github spaxjs / spax / examples / demo-mui / craco.config.js View on Github external
const path = require("path");
const { whenProd } = require("@craco/craco");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");

const getAliasForCommonLibraries = (modules) => {
  return modules.reduce((obj, name) => {
    return Object.assign(obj, {
      [name]: path.resolve(__dirname, "node_modules", name)
    });
  }, {});
};

module.exports = {
  webpack: {
    plugins: whenProd(() => [new BundleAnalyzerPlugin()], [])
  },
  plugins: [
    {
      plugin: {
        overrideWebpackConfig: ({ webpackConfig }) => {
          if (!webpackConfig.resolve) webpackConfig.resolve = {};
          if (!webpackConfig.resolve.alias) webpackConfig.resolve.alias = {};
          Object.assign(
            webpackConfig.resolve.alias,
            getAliasForCommonLibraries([
              "react",
              "react-dom",
              "react-hot-loader",
              "@material-ui/core",
              "@material-ui/styles",
              "@types/node",

@craco/craco

Create React App Configuration Override, an easy and comprehensible configuration layer for create-react-app.

Apache-2.0
Latest version published 1 year ago

Package Health Score

68 / 100
Full package analysis