snabbdom / snabbdom-to-html

Render Snabbdom Vnode’s to HTML strings
91 stars 21 forks source link

Issue with running through uglify-js #6

Closed TylorS closed 8 years ago

TylorS commented 8 years ago

I recently made an update to cycle-snabbdom and I added support for server-side rendering there with this library, of course.

I decided that I would like to create dist/ builds for users to include in <script> tags, which goes through well enough for browserify + babelify. However when trying to minimize the generated file with uglifiy-js (latest version) this line here throws a parsing error regarding the backticks, because files in your node_modules are not also passed through browserify+babelify in the same fashion.

TylorS commented 8 years ago

Also the arrow function here

Backticks here and here

And that seems to be everything. If I manually make the changes the build works. I'll gladly make the adjustments if that is something you would like.

SkaterDad commented 8 years ago

I ran into this today as well, using Webpack's production build settings (which use uglify).

To solve it for now, I told Webpack to run snabbdom-to-html through Babel.

It feels so counter-productive to do this for the client-side bundle, since uglify is going to delete the code again anyway...

TylorS commented 8 years ago

@SkaterDad FWIW I'm using the global flag for babel. https://github.com/TylorS/cycle-snabbdom/blob/master/package.json#L11

TylorS commented 8 years ago

Oops. I apologize. Thats a babelify only option.

SkaterDad commented 8 years ago

Here's the part of my webpack config file which handles .js files. Typically I just exclude the entire node_modules folder, but put in this weird regex for now.

I only do this in the client-side bundle's "production" build setup, since it's the only one I'm minimizing.

loaders: [
            {
                test: /\.js$/,
                loaders: ['babel?cacheDirectory=true&presets=es2015'],
                exclude: /node_modules.((?!snabbdom-to-html)).*/ //webpack pulls in snabbdom-to-html as part of cycle-snabbdom.  Uflify doesn't like es6 code.
                //exclude: /node_modules/
            }
]
acstll commented 8 years ago

Hey there, sorry for the late reply. @TylorS @SkaterDad (for some reason I'm not getting any emails from GitHub)

I understand the problem but I'm no sure how we should fix this. This library is targeting node v4 and up where inline templates and arrow functions work ok.

Would it help having a transpiled (to ES5) version of the library meant for browser use?

SkaterDad commented 8 years ago

@acstll I think including a transpiled version for browsers would solve this. I assume the bundlers are smart enough to handle that.

This could allow some cool things like a site which shows live previews of the conversion.

acstll commented 8 years ago

This could allow some cool things like a site which shows live previews of the conversion.

That's a really nice idea. :+1:

I know Browserify takes into account the browser key on package.json, I have no idea about Webpack, I'll do some research.

This is the plan then

TylorS commented 8 years ago

Seems like a solid plan :+1:

acstll commented 8 years ago

I plan to cut a release with this and #7 (plus thunks) this afternoon, I wanted to do this earlier but I haven't been able to… :sweat: :blush: