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

Define custom pragma as global setting? #5152

Closed
FezVrasta opened this issue Sep 28, 2018 · 18 comments
Closed

Define custom pragma as global setting? #5152

FezVrasta opened this issue Sep 28, 2018 · 18 comments

Comments

@FezVrasta
Copy link
Contributor

Emotion 10 is going to provide a custom createElement function and to work, the app needs to use it as custom pragma.

emotion-js/emotion#637

Is there any way to override the default React createElement in a global manner to avoid to define the custom pragma on every single file?

@jgoux
Copy link

jgoux commented Oct 24, 2018

I'd like to second this.

I'm currently looking at a way to define it using a react-app-rewired approach but it seems that the option is burried deep. 🕳

I ended up here : https://github.com/facebook/create-react-app/blob/master/packages/babel-preset-react-app/create.js#L95-L103

It would be great to add the pragma option here and to give us a parameter / env variable to set it properly. 😄

This would be enough so we can hook into the webpack config and pass the option from a rewired plugin :

{
  "presets": [["react-app", { "flow": true, "typescript": false, pragma: 'myCustomPragma' }]]
}

EDIT :

We can actually make it works today by redefining @babel/transform-react-jsx in the webpack config as plugins are executed before presets (so before the react-app preset used by CRA). It requires react-app-rewired and customize-cra if you don't want to eject.

In term of dependencies to add :

yarn add --dev @wordpress/babel-plugin-import-jsx-pragma babel-plugin-emotion@next babel-plugin-transform-react-jsx

babel-plugin-emotion is not required.

Here is the config-overrides.js :

const { override, addBabelPlugin } = require('customize-cra')
module.exports = override(
  addBabelPlugin(['emotion', options]),
   addBabelPlugin([
      '@wordpress/babel-plugin-import-jsx-pragma',
      {
        scopeVariable: 'jsx',
        source: '@emotion/core',
        isDefault: false
      }
    ]),
   addBabelPlugin([
      '@babel/transform-react-jsx',
      {
        pragma: 'jsx'
      }
    ])
)

I still think it would be better to have a proper API from CRA rather than relying on webpack's execution priority.

@jgoux jgoux mentioned this issue Oct 24, 2018
14 tasks
@FezVrasta
Copy link
Contributor Author

FezVrasta commented Oct 25, 2018

I wonder if we could use the Yarn resolutions to override @babel/transform-react-jsx with a custom made "transform-emotion-jsx"?

"resolutions": {
  "@babel/transform-react-jsx": "@emotion/transform-emotion-jsx" // fake package name
}

@stale
Copy link

stale bot commented Nov 24, 2018

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Nov 24, 2018
@jgoux
Copy link

jgoux commented Nov 24, 2018

As of today there is still no easy solution to this issue.

@stale stale bot removed the stale label Nov 24, 2018
@stale
Copy link

stale bot commented Dec 24, 2018

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Dec 24, 2018
@FezVrasta
Copy link
Contributor Author

Hey stale bot stop with this shit.

@stale stale bot removed the stale label Dec 24, 2018
@FezVrasta
Copy link
Contributor Author

Anyway, for what is worth, if you don't make use of the css property, you can take advantage of most of the Emotion features using the @emotion/styled/macro and @emotion/css/macro Babel macros.

@coreyward
Copy link

@FezVrasta Is there an example of that somewhere?

@FezVrasta
Copy link
Contributor Author

@stale
Copy link

stale bot commented Feb 24, 2019

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Feb 24, 2019
@FezVrasta
Copy link
Contributor Author

FezVrasta commented Feb 24, 2019

I'm losing faith in the open source community with all these stale bots that close perfectly legit issues for no apparent reason...

I promise I will never add one to my own projects.

We went from the "+1" comments to the "no bot please don't close this" ones 🤷‍♂️

@stale stale bot removed the stale label Feb 24, 2019
@stale
Copy link

stale bot commented Mar 26, 2019

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Mar 26, 2019
@FezVrasta
Copy link
Contributor Author

FezVrasta commented Mar 26, 2019

NO STALE!

NO _ STALE

👏 IT 👏ISN'T 👏 STALE 👏

IT IS NOT STALE

@stale stale bot removed the stale label Mar 26, 2019
@iansu iansu closed this as completed Mar 26, 2019
@iansu
Copy link
Contributor

iansu commented Mar 26, 2019

We have no plans to implement this right now.

@FezVrasta
Copy link
Contributor Author

@iansu is there any particular reason you're able to share with us?

@iansu
Copy link
Contributor

iansu commented Mar 26, 2019

We don't want to add options to customize our webpack config and we avoid making changes to accommodate individual libraries or tools. You can still use Emotion, or countless other CSS-in-JS libraries, without this.

@FezVrasta
Copy link
Contributor Author

An option of this kind would allow to use also other React-like libraries such as Preact.

Honestly I wouldn't dismiss this issue that quickly, but I guess it's up to you.

@localjo
Copy link

localjo commented Mar 27, 2019

Something like https://github.com/sharegate/craco/ might enable the custom config you want.

@lock lock bot locked and limited conversation to collaborators Apr 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants