在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):vigetlabs/gulp-rails-pipeline开源软件地址(OpenSource Url):https://github.com/vigetlabs/gulp-rails-pipeline开源编程语言(OpenSource Language):Ruby 50.5%开源软件介绍(OpenSource Introduction):Use Blendid!DEPRECATED:The work done in this repo has been rolled into a single dependency solution: Blendid!. You can set up your Rails project with the The Gulp Asset Pipeline on Rails
Production Environment Demo (notice the revisioned asset filenames for caching) This repo is only meant to be an example. You should fork and customize it with your own Rails setup and relevant Gulp tasks, or copy the relevant files into an existing project. To understand more about individual modules, read the documentation on their respective websites and repositories. Based on gulp-starter. Running the DemoClone the repository
Enter into the directory and run bundle install
Install javascript dependencies. Once npm install runs, the
Start the rails server.
Run gulp and rejoice! This will start watching and recompiling files on the fly, as well as open a browser with BrowserSync running.
Try editing Asset File Structuregulp/assetsThis is where all your source files will live. Your source icons for icon fonts, sass files, js modules, and images. Anything that needs to get processed by Gulp. All assets are set up to compile to public/assetsThe destination of your compiled and processed assets. The app/assetsThe old default asset directory should only include manifest files, which are necessary if you need to require gem installed assets (e.g., jquery_ujs, turbolinks) with Sprockets. The manifest files pull in gem assets, as well as our compiled js and css files from Rails setup notes:config/application.rb# Make public assets requireable in manifest files
config.assets.paths << Rails.root.join("public", "assets", "stylesheets")
config.assets.paths << Rails.root.join("public", "assets", "javascripts") If you plan on continuing to use Sprockets to config/environments/development.rbconfig.assets.debug = true
config.assets.digest = false To fully take advantage of BrowserSync's live stylesheet injection, be sure to configure the two values above. Setting package.json"scripts": {
"postinstall": "gulp build"
},
"dependencies": {...} After running gulp/tasks/build.js// line 6
if(process.env.RAILS_ENV === 'production') tasks.push('rev'); If the RAILS_ENV is set to app/helpers/application_helper.rbdef gulp_asset_path(path)
path = REV_MANIFEST[path] if defined?(REV_MANIFEST)
"/assets/#{path}"
end Because we're storing our assets outside of the Rails Asset Pipeline, we need to re-implement the config/initializers/rev_manifest.rbrev_manifest_path = 'public/assets/rev-manifest.json'
if File.exist?(rev_manifest_path)
REV_MANIFEST = JSON.parse(File.read(rev_manifest_path))
end You'll notice this constant referenced in the DeployingTo avoid git messiness and redundant rebases and merge conflicts, it's usually a good idea to
These steps must complete before starting the Rails server. HerokuHeroku makes deploying SUPER easy, but there are a couple of things you'll need to do to get this running. Since we're using Ruby (to run Rails) AND Node (to compile our assets with Gulp) in our setup, we need both running on our server. Heroku will automatically detect ONE of these at a time based on the presense of a heroku buildpacks # view current buildpacks
heroku buildpacks:clear # clear current buildpacks, if necessary
heroku buildpacks:add heroku/nodejs # add the buildpacks we want ...
heroku buildpacks:add heroku/ruby # ... in the order we want them Now, when we deploy to Heroku, first Take note of the following: #production.rb line 25
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? Heroku requires CapistranoAll we need to do is add a task to run The example below shows an example of using nvm (node version manager) to use the specified node version for your application. # ./config/deploy.rb
before "deploy:assets:precompile", "deploy:npm_install"
namespace :deploy do
desc "Run npm install"
task :npm_install do
invoke_command "bash -c '. /home/deploy/.nvm/nvm.sh && cd #{release_path} && npm install'"
end
end Original Blog Post: viget.com/extend/gulp-rails-asset-pipeline Visit code.viget.com to see more projects from Viget. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论