Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRA Example #23

Closed
amcdnl opened this issue Dec 16, 2020 · 2 comments
Closed

CRA Example #23

amcdnl opened this issue Dec 16, 2020 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@amcdnl
Copy link

amcdnl commented Dec 16, 2020

It would be worth showing how to set this up with CRA ( create-react-app ).

It can be accomplished by using craco ( https://github.com/gsoft-inc/craco < tailwind also suggests this approach for their custom stuff you have to add ). Then the code just looks like:

craco.config.js

module.exports = {
  babel: {
    plugins: [
      '@fullstory/babel-plugin-annotate-react'
    ]
  }
};
@patrick-fs patrick-fs added the documentation Improvements or additions to documentation label Dec 18, 2020
@patrick-fs
Copy link
Member

Good suggestion, thanks Austin.

@matheuseabra
Copy link

matheuseabra commented Sep 1, 2023

Hey @amcdnl and @patrick-fs, thanks for sharing this.

I also have a CRA app that is using Craco, I followed your instructions by adding the snippet above to craco.config.js, however it didn't work, I'm not able to see the data-component or data-element in the rendered DOM.

Shouldn't I also add a rule object to the webpack.module.rules array as shown in the single-app sample on webpack.config.js from line 407 to 438?

// webpack.config.js

module = {
  rules: [{
              test: /\.(js|mjs|jsx|ts|tsx)$/,
              include: paths.appSrc,
              loader: require.resolve('babel-loader'),
              options: {
                customize: require.resolve(
                  'babel-preset-react-app/webpack-overrides'
                ),
                presets: [
                  [
                    require.resolve('babel-preset-react-app'),
                    {
                      runtime: hasJsxRuntime ? 'automatic' : 'classic',
                    },
                  ],
                ],
                plugins: [
                   // This is the local reference @fullstory/babel-plugin-annotate-react
                  // To use in your projects you would replace '../..' with '@fullstory/babel-plugin-annotate-react'
                  '../..',
                  isEnvDevelopment &&
                    shouldUseReactRefresh &&
                    require.resolve('react-refresh/babel'),
                ].filter(Boolean),
                // This is a feature of `babel-loader` for webpack (not Babel itself).
                // It enables caching results in ./node_modules/.cache/babel-loader/
                // directory for faster rebuilds.
                cacheDirectory: true,
                // See #6846 for context on why cacheCompression is disabled
                cacheCompression: false,
                compact: isEnvProduction,
              },
            }]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants