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

Babel preset #7

Closed
sindresorhus opened this issue Jul 7, 2017 · 7 comments
Closed

Babel preset #7

sindresorhus opened this issue Jul 7, 2017 · 7 comments
Labels
documentation Improvements or additions to documentation

Comments

@sindresorhus
Copy link

Would be nice if there was a babel-preset-dom-chef that set everything up for you.

Should contain:


From refined-github/refined-github#558 (comment)

@fregante
Copy link
Collaborator

fregante commented Jul 7, 2017

If someone actually makes a babel plugin out of dom-chef I'd love to actually see JSX converted into plain DOM calls like Svelte does. That stuff is amazing:

<h1>Hello {{name}}!</h1>
// ...
create: function () {
	h1 = createElement( 'h1' );
	text = createText( "Hello " );
	text_1 = createText( text_1_value = state.name );
	text_2 = createText( "!" );
},

mount: function ( target, anchor ) {
	insertNode( h1, target, anchor );
	appendNode( text, h1 );
	appendNode( text_1, h1 );
	appendNode( text_2, h1 );
},
// ...

Svelte unfortunately adds a little unnecessary boilerplate to keep it dynamic and app-like, otherwise I'd have used that in Refined GitHub instead.

@fregante
Copy link
Collaborator

fregante commented Jul 7, 2017

Bingo: https://github.com/treycordova/nativejsx and https://github.com/treycordova/nativejsx-loader

export const check = <svg aria-hidden="true" class="octicon octicon-check" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"></path></svg>;
export const check = function () {
    const _a = document.createElement('svg');
    _a.setAttribute('aria-hidden', 'true');
    _a.setAttribute('class', 'octicon octicon-check');
    _a.setAttribute('height', '16');
    _a.setAttribute('version', '1.1');
    _a.setAttribute('viewBox', '0 0 12 16');
    _a.setAttribute('width', '12');
    const _b = document.createElement('path');
    _b.setAttribute('d', 'M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z');
    _a.appendChild(_b);
    return _a;
}.call(this);

Two issues:

@vadimdemedes
Copy link
Owner

@sindresorhus Great idea! Agree with every point.

@bfred-it That stuff is great, I'll keep that in mind.

@fregante
Copy link
Collaborator

fregante commented Mar 26, 2020

Apparently babel 7.9.0 automatically imports React:

https://babeljs.io/blog/2020/03/16/7.9.0#a-new-jsx-transform-11154-https-githubcom-babel-babel-pull-11154

Due to:

https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md#auto-import

I think our config would be:

    [
      "@babel/preset-react",
      {
        "pragma": "h",
        "pragmaFrag": "DocumentFragment",
        "runtime": "automatic", // enables auto-import
        "importSource": "dom-chef"
      }
    ]
  ]

From: https://babeljs.io/docs/en/babel-preset-react#with-a-configuration-file-recommended

So now this is a documentation-only issue, which would follow #56 and then #57

@fregante fregante added documentation Improvements or additions to documentation and removed enhancement labels Mar 26, 2020
@dankotov
Copy link

dankotov commented Feb 10, 2023

Apologies for a perhaps noob question, however, according to babel docs, pragma and pragmaFrag cannot be set with runtime: "automatic". Is dom-chef therefore not compatible with automatic runtime?

docs: https://babeljs.io/docs/en/babel-preset-react#with-a-configuration-file-recommended

@fregante
Copy link
Collaborator

@dankotov correct. That's #57

@dankotov
Copy link

@fregante understood! appreciate the prompt reply

@fregante fregante closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2023
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