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

split up base JS into vendor/app #860

Closed
wants to merge 1 commit into from
Closed

split up base JS into vendor/app #860

wants to merge 1 commit into from

Conversation

tilsammans
Copy link
Contributor

This pattern is quite common for Webpack and it makes a lot of sense to me too.

We split up application.js into a vendor part and an app part. The engine precompiles both. They are meant to be included separately into the html . Vendor won't change nearly as often and so will remain cached for longer.

It's backwards compatible with the current way. I'll update docs etc if you think this is a good idea.

@tilsammans tilsammans requested a review from tf September 7, 2017 06:07
@tilsammans tilsammans self-assigned this Sep 7, 2017
return (window.location.href.indexOf('debug=true') >= 0);
}
};
pageflow.log("Rails Asset Pipeline: <pageflow/base> is deprecated and will be removed from Pageflow. Use separate vendor and app assets.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

//= require_tree ./widgets
//= require ./react

pageflow = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read only.

@tilsammans
Copy link
Contributor Author

The way HTTP/2 streams all assets together makes the enormous asset bundles obsolete IMO.

@coveralls
Copy link

Coverage Status

Coverage decreased (-4.8%) to 94.326% when pulling 5fbe5eb on scrollytelling:vendor-app-javascript into b3d492b on codevise:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-4.8%) to 94.326% when pulling 5fbe5eb on scrollytelling:vendor-app-javascript into b3d492b on codevise:master.

Copy link
Member

@tf tf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Still, since Pageflow renders the script tags itself, I'd suggest inserting a script tag for pageflow/vendor.js there. We can then remove vendor related stuff from pageflow/base.js but keep everything else as is. That way pageflow/applications.js files in host apps do not have to change at all. Only the //= require pageflow/base directive will pull in a lot less stuff.

@@ -88,5 +88,9 @@ class Engine < ::Rails::Engine
FactoryGirl.definition_file_paths.unshift(Engine.root.join('spec', 'factories'))
end
end

initializer "pageflow.assets.precompile" do |app|
app.config.assets.precompile += %w( vendor.js app.js )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use spaces inside percent literal delimiters.

@@ -88,5 +88,9 @@ class Engine < ::Rails::Engine
FactoryGirl.definition_file_paths.unshift(Engine.root.join('spec', 'factories'))
end
end

initializer "pageflow.assets.precompile" do |app|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.

end
end

app.config.assets.precompile << lambda do |path, filename|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected.

pageflow/vendor.js
video-js.swf vjs.eot vjs.svg vjs.ttf vjs.woff)

app.config.assets.precompile << lambda do |path, _filename|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected.

pageflow/print_view.css
pageflow/lt_ie9.js pageflow/lt_ie9.css pageflow/ie9.js pageflow/ie9.css
pageflow/vendor.js
video-js.swf vjs.eot vjs.svg vjs.ttf vjs.woff)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

pageflow/application_with_simulated_media_queries.css
pageflow/print_view.css
pageflow/lt_ie9.js pageflow/lt_ie9.css pageflow/ie9.js pageflow/ie9.css
pageflow/vendor.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

app.config.assets.precompile += %w(pageflow/editor.js pageflow/editor.css
pageflow/application_with_simulated_media_queries.css
pageflow/print_view.css
pageflow/lt_ie9.js pageflow/lt_ie9.css pageflow/ie9.js pageflow/ie9.css

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.
Line is too long. [108/100]

initializer 'pageflow.assets.precompile' do |app|
app.config.assets.precompile += %w(pageflow/editor.js pageflow/editor.css
pageflow/application_with_simulated_media_queries.css
pageflow/print_view.css

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

# provided by the main app.
initializer 'pageflow.assets.precompile' do |app|
app.config.assets.precompile += %w(pageflow/editor.js pageflow/editor.css
pageflow/application_with_simulated_media_queries.css

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

end
end

app.config.assets.precompile << lambda do |path, filename|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected.

pageflow/vendor.js
video-js.swf vjs.eot vjs.svg vjs.ttf vjs.woff)

app.config.assets.precompile << lambda do |path, _filename|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected.

pageflow/print_view.css
pageflow/lt_ie9.js pageflow/lt_ie9.css pageflow/ie9.js pageflow/ie9.css
pageflow/vendor.js
video-js.swf vjs.eot vjs.svg vjs.ttf vjs.woff)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

pageflow/application_with_simulated_media_queries.css
pageflow/print_view.css
pageflow/lt_ie9.js pageflow/lt_ie9.css pageflow/ie9.js pageflow/ie9.css
pageflow/vendor.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

app.config.assets.precompile += %w(pageflow/editor.js pageflow/editor.css
pageflow/application_with_simulated_media_queries.css
pageflow/print_view.css
pageflow/lt_ie9.js pageflow/lt_ie9.css pageflow/ie9.js pageflow/ie9.css

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.
Line is too long. [108/100]

initializer 'pageflow.assets.precompile' do |app|
app.config.assets.precompile += %w(pageflow/editor.js pageflow/editor.css
pageflow/application_with_simulated_media_queries.css
pageflow/print_view.css

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

# provided by the main app.
initializer 'pageflow.assets.precompile' do |app|
app.config.assets.precompile += %w(pageflow/editor.js pageflow/editor.css
pageflow/application_with_simulated_media_queries.css

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

end
end

app.config.assets.precompile << lambda do |path, filename|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected.

pageflow/vendor.js
video-js.swf vjs.eot vjs.svg vjs.ttf vjs.woff)

app.config.assets.precompile << lambda do |path, _filename|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected.

pageflow/print_view.css
pageflow/lt_ie9.js pageflow/lt_ie9.css pageflow/ie9.js pageflow/ie9.css
pageflow/vendor.js
video-js.swf vjs.eot vjs.svg vjs.ttf vjs.woff)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

pageflow/application_with_simulated_media_queries.css
pageflow/print_view.css
pageflow/lt_ie9.js pageflow/lt_ie9.css pageflow/ie9.js pageflow/ie9.css
pageflow/vendor.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

app.config.assets.precompile += %w(pageflow/editor.js pageflow/editor.css
pageflow/application_with_simulated_media_queries.css
pageflow/print_view.css
pageflow/lt_ie9.js pageflow/lt_ie9.css pageflow/ie9.js pageflow/ie9.css

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.
Line is too long. [108/100]

initializer 'pageflow.assets.precompile' do |app|
app.config.assets.precompile += %w(pageflow/editor.js pageflow/editor.css
pageflow/application_with_simulated_media_queries.css
pageflow/print_view.css

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

# provided by the main app.
initializer 'pageflow.assets.precompile' do |app|
app.config.assets.precompile += %w(pageflow/editor.js pageflow/editor.css
pageflow/application_with_simulated_media_queries.css

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

@tilsammans
Copy link
Contributor Author

@tf changes done & rebased

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.169% when pulling ffd21ea on scrollytelling:vendor-app-javascript into a8a53e5 on codevise:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.169% when pulling ffd21ea on scrollytelling:vendor-app-javascript into a8a53e5 on codevise:master.

Copy link
Member

@tf tf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specs are failing since Teaspoon does not load the new vendor.js file.

filename.start_with?(Engine.root.join('app/assets').to_s) &&
!['.js', '.css', ''].include?(File.extname(path))
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What difference does wrapping the code in an initializer block make here? Can we fix indentation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just following the documented API for engine asset precompilation. Pretty sure this will handle a tweaked asset pipeline better.

Indentation fixed.

@@ -0,0 +1,16 @@
// vendor stylesheet for Pageflow.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"stylesheet" is a typo.

end

app.config.assets.precompile << lambda do |path, filename|
filename.start_with?(Engine.root.join('app/assets').to_s) && !['.js', '.css', ''].include?(File.extname(path))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [118/100]

@tilsammans
Copy link
Contributor Author

@tf

Specs are failing since Teaspoon does not load the new vendor.js file.

I am not too familiar with Teaspoon, how do I fix that?

Other changes are done.

@tf
Copy link
Member

tf commented Oct 16, 2017

Tried to push a commit to the PR, but maybe the option is not set. Here's the diff, that makes teaspoon pass: https://github.com/scrollytelling/pageflow/compare/vendor-app-javascript...tf:vendor-app-javascript

@tilsammans
Copy link
Contributor Author

I've merged in your commits.

@tf
Copy link
Member

tf commented Oct 17, 2017

Travis appears to be stuck somehow...

These will be compiled separately. Since they change less often,
the idea is that these assets will remain in cache for longer.
@tilsammans
Copy link
Contributor Author

@tf squashed all the commits (including yours).

@tf
Copy link
Member

tf commented Oct 20, 2017

Thanks. I'd totally merge, but I want the green check mark on the PR first ;) I don't know why Travis stopped picking up changes, but worst case we'll have to create a fresh PR from the same branch.

@tilsammans
Copy link
Contributor Author

I'll create a new PR tomorrow if it doesn't go through today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants