webpack-assets gem is a lightweight
integration. It provides the necessary view helpers to completely replace Rails
Asset Pipeline with webpack. Any custom webpack configuration should be
supported if it satisfies the assumptions described in
the corresponding section.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install webpack-assets
Minimal configuration (
Webpack.configure do |config| config.port = 4000 config.public_path = '/assets' config.static_path = 'front/static' end
port- the port webpack dev server is running on.
public_path- the base path for assets.
static_path- the root path for static files.
use_server- whether webpack dev server is being used (
extract_css- whether css is extracted to a separate file (
host- the host with the port webpack dev server is running on (can be used instead of
cdn_host- the CDN host (will be prepended to URLs for all files).
Webpack.configure do |config| if ENV['WEBPACK_HOST'] config.host = ENV['WEBPACK_HOST'] else config.port = 4000 end end
webpack_js_tagis a replacement for
webpack_css_tagis a replacement for
webpack_static_file_urlresolves paths to static files (assets used directly from HTML), e.g.:
<%= image_tag webpack_static_file_url('img/logo.png') %>
webpack-assets makes several assumptions:
assets-webpack-pluginis used to prepare
static-files-webpack-pluginis used to prepare
After checking out the repo, run
bundle install to install dependencies. Then, run
rake spec to run the tests.
To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number in
version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the
.gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/toptal/webpack-assets. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.