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

Override babel compact option? #6

Closed
primerano opened this issue Jul 19, 2016 · 3 comments
Closed

Override babel compact option? #6

primerano opened this issue Jul 19, 2016 · 3 comments

Comments

@primerano
Copy link

Currently this gem runs with the default babel setting of

compact "auto"

The problem with this is when a js file exceeds 100k it logs an error to console

` if (format.compact === "auto") {
format.compact = code.length > 100000; // 100KB

  if (format.compact) {
    console.error("[BABEL] " + messages.get("codeGeneratorDeopt", opts.filename, "100KB"));
  }
}`

but since there is no console, the call to error fails and processing stops. (seems like an info message but since there is no console the point is moot)

If I could set compact to true my processing would complete.

@jamiebuilds
Copy link
Contributor

This is an issue with Babel itself. You'll have to open an issue over there: https://phabricator.babeljs.io/

@primerano
Copy link
Author

The babel folks have already said they will not support runtimes that lack console.

i was hoping you could allow babel options to be passed in from this gem.

for example. Adding these lines to my _config.yml

babel_js_options: 
  compact: true
  comments: false

and then capture those options and pass them to the transform command in the jekyll-babel gem

diff --git a/lib/jekyll/converters/babel.rb b/lib/jekyll/converters/babel.rb
index f6b1db2..041d59d 100644
--- a/lib/jekyll/converters/babel.rb
+++ b/lib/jekyll/converters/babel.rb
@@ -5,7 +5,8 @@ module Jekyll
       priority :low

       DEFAULT_CONFIGURATION = {
-        'babel_js_extensions' => 'js, es6, babel, jsx'
+        'babel_js_extensions' => 'js, es6, babel, jsx',
+        'babel_js_options' => {}
       }

       def initialize(config = {})
@@ -21,7 +22,7 @@ module Jekyll
       end

       def convert(content)
-        ::Babel::Transpiler.transform(content)['code']
+        ::Babel::Transpiler.transform(content, @config['babel_js_options'])['code']
       end

This worked fine for me. If you think this is in scope I'll send you a PR.

Let me know

@arthurvasconcelos
Copy link

arthurvasconcelos commented Sep 30, 2016

I have the same issue that @primerano had... Would be awesome if his solution could be merged...

EDIT:

Btw I've implemented in my fork, @primerano's solution and worked fine for me as well.

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

3 participants