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

How does it work with CRA #5

Closed
baurine opened this issue May 15, 2020 · 5 comments
Closed

How does it work with CRA #5

baurine opened this issue May 15, 2020 · 5 comments

Comments

@baurine
Copy link

baurine commented May 15, 2020

Hi @egoist , how does this loader work for a react app created by CRA (and TS), I tried but failed, here is my config-overrides.js:

const useEsBuild = () => (config) => {
  const rules = config.module.rules.find((rule) => Array.isArray(rule.oneOf))
    .oneOf
  const jsRule = rules.find(
    (rule) =>
      rule.loader &&
      rule.loader.endsWith('babel-loader/lib/index.js') &&
      rule.include
  )
  if (jsRule) {
    jsRule.loader = 'esbuild-loader'
    jsRule.options = {
      // ...jsRule.options,
      // All options are optional
      target: 'es2015', // default, or 'es20XX', 'esnext'
      jsxFactory: 'React.createElement',
      jsxFragment: 'React.Fragment',
      sourceMap: false, // Enable sourcemap
    }
    addWebpackPlugin(new ESBuildPlugin())(config)
  }

  return config
}


module.exports = override(
  ...,
  useEsBuild()
)

It reports error about Error parsing bundle asset ...:

Error parsing bundle asset ".../build/static/js/0.df163045.chunk.js": no such file
Error parsing bundle asset ".../build/static/js/1.ab303cfe.chunk.js": no such file
Error parsing bundle asset ".../build/static/js/11.7c137ba2.chunk.js": no such file
Error parsing bundle asset ".../build/static/js/12.9a6799eb.chunk.js": no such file
Error parsing bundle asset ".../build/static/js/13.a4ecc160.chunk.js": no such file
Error parsing bundle asset ".../build/static/js/14.78ed2e9d.chunk.js": no such file 
...

It would be very appreciated if you can supply an example, thanks in advance!

@shenzhongkang
Copy link

I tried with react-boilerplate, failed too : ( . Maybe there're some other configs need to be added.

@egoist
Copy link
Contributor

egoist commented May 18, 2020

I don't use CRA nor react-boilerolate, anyone could provide a repo so I can test?

@baurine
Copy link
Author

baurine commented May 19, 2020

Thank you! I will do that when I am free this week.

@baurine
Copy link
Author

baurine commented May 22, 2020

Erhm, I just did a very simple test, use the esbuild-loader in a bare CRA project, it works fine, although the build time doesn't change. I will do some more tests later, for example, use less css style. The test repo is here: https://github.com/baurine/test-es-build

update: works fine with less css as well.

@privatenumber
Copy link
Owner

I don't use CRA either, but seems like it's working fine.

Feel free to re-open if there's anything outstanding

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

No branches or pull requests

4 participants