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

asset_host + jQuery producing invalid javascript? #1873

Closed
joshukraine opened this issue Apr 7, 2016 · 8 comments
Closed

asset_host + jQuery producing invalid javascript? #1873

joshukraine opened this issue Apr 7, 2016 · 8 comments

Comments

@joshukraine
Copy link

I have a couple of MM4 projects which use Gulp in conjunction with the new external_pipeline. Both projects require jQuery. I've noticed that if I activate the asset_host feature in config.rb as outlined in the Middleman docs, the javascript bundle generated by middleman build is invalid. (The error from eslint, for example, is Parsing error: Unexpected token * A similar error is displayed in the browser console in production.)

screenshot 2016-04-07 08 55 53

The following two repos illustrate this issue. The first uses Webpack to bundle the js, the second uses Browserify. Both use Gulp and both require jQuery.

  1. Webpack example: https://github.com/joshukraine/middleman-gulp-starter
  2. Browserify example: https://github.com/joshukraine/mm4-example

I've discussed this issue at some length with Craig Dennis (author of middleman-gulp-starter), and it would appear that the asset host URL is not being properly quoted in the bundled javascript.

screenshot 2016-04-06 21 17 00

If I remove the asset_host setting, the javascript bundle is valid. Also, if I don't require jQuery, the javascript bundle is valid. But if I combine the two, I get syntax errors. Any thoughts?

Thank you.

@joshukraine
Copy link
Author

Video walkthrough illustrating steps to reproduce the issue: https://youtu.be/xRlU38q-QxU

Updated example repo with full instructions in README: https://github.com/joshukraine/asset-host-jquery-issue

@joshukraine
Copy link
Author

It would appear this is related to #1780.

@joshukraine
Copy link
Author

UPDATE: Found a possible workaround. Adding the :rewrite_ignore option to config.rb tells Middleman not to insert asset host URLs in specified file types.

# config.rb

configure :build do
  activate :asset_host,
    :host => '//YOURDOMAIN.cloudfront.net',
    :rewrite_ignore => ["*.js"]

  # More configs...
end

Reference:

@tdreyno
Copy link
Member

tdreyno commented Apr 8, 2016

Thanks. There's definitely a regex issue I need to look into

@tdreyno
Copy link
Member

tdreyno commented Apr 12, 2016

I can't reproduce with MM github master. Can you take a look?

@tdreyno
Copy link
Member

tdreyno commented Apr 12, 2016

Wait, nm, forgot to remove the ignore line

@tdreyno
Copy link
Member

tdreyno commented Apr 12, 2016

Okay, give master a shot now

tacticiankerala added a commit to multunus/multunus-website that referenced this issue Apr 13, 2016
@joshukraine
Copy link
Author

@tdreyno Yep, working for me. Thanks for the fix!

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

2 participants