Microbundle: Support JSX ?

Created on 13 Dec 2017  Â·  16Comments  Â·  Source: developit/microbundle

Hi, i wonder if it's possible to use JSX in the source code.
This is a test repo : https://github.com/wcastand/test-microbundle
I have a small repo to test it out and right now i get an error from nodent :

▲ test-microbundle at master ✔ yarn build
yarn run v1.3.2
$ microbundle --jsx
SyntaxError: Unexpected token (4:2) /Users/willoo/Documents/Projects/test-microbundle/src/index.js (nodent)
  <div>
--^
✨  Done in 0.50s.

In the source code you have an options for jsx in buble options.jsx but nodent is before buble.

bug help wanted

Most helpful comment

Adding a package to your peerDepenencies will make it external, no flags needed.

All 16 comments

I think we can pass this to nodent:

nodent({
  parser: {
    plugins: {
      jsx: require('acorn-jsx')
    }
  }
})

Is there a way to add this in my project or i make a PR to include jsx parsing by default in nodent ? or we add an options to include jsx ?

I think we should just support it out-of-the-box.

There was a release just before this was merged.
Any idea when it will be published ?

Thank for your work and reactivity :)

Hi, I cant seem to get JSX to work either, just installed:

$ microbundle
SyntaxError: Unexpected token (37:8) /Users/albinekb/Devel/Projects/react-native-net-info-hoc/src/components/withNetInfo.js (nodent)
        <ComposedComponent {...this.props} connection={{ ...this.state }} />
--------^
✨  Done in 1.41s.

It wasn't pushed to npm yet :)
the PR was merged 1 hour after the last release so i think he waits to get more change before pushing a new version :)

Curious if this is out.

about to be.

Actually, I’m seeing some errors.
I cloned this master, ran build and installed into my project. Everything worked as expected, but then I tried to plug in, created bundle into another prohect and it threw with h is undefined.
Looks like it compiled <h1> into h(‘h1’, ... with h not being defined anywhere.

I can provide more details when I get to the computer.

That seems correct. The default pragma is h(), you can change it to anything you want:

microbundle --jsx React.createElement

btw - this is released as 0.3.0 if you want to test it out that way.

So it's passing arguments to rollup? Or --jsx is just undocumented feature?
Thanks, I'll test it.

Btw, another thing that is somewhat confusing:

--external

microbundle --jsx React.createElement --compress false --external electron --output lib src/index.js

(node:11195) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: 'ipcRenderer' is not exported by node_modules/electron/index.js
(node:11195) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
'ipcRenderer' is not exported by node_modules/electron/index.js

It still tries to pull in electron dependency

Does work with --external all though.

Seems working with --jsx React.createElement flag. Thanks.

A note for other users: as of 0.4.3 (might be other versions, but that's where I am), the --external flag has two requirements:

  1. If --external all, your external modules must be installed as dependencies
  2. If --external <name>, your external module must be installed as peerDependencies

Adding a package to your peerDepenencies will make it external, no flags needed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yaymukund picture yaymukund  Â·  4Comments

belozer picture belozer  Â·  3Comments

rdmurphy picture rdmurphy  Â·  3Comments

rzkhosroshahi picture rzkhosroshahi  Â·  5Comments

jlkiri picture jlkiri  Â·  4Comments