• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

joshukraine/middleman-gulp: A Middleman 4 template using Gulp.js via the externa ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

joshukraine/middleman-gulp

开源软件地址(OpenSource Url):

https://github.com/joshukraine/middleman-gulp

开源编程语言(OpenSource Language):

Ruby 42.9%

开源软件介绍(OpenSource Introduction):

Middleman 4 + Gulp.js

Build Status

This is a Middleman template which implements Gulp.js using the new external pipeline feature introduced in Middleman 4.

Features

Requirements

Usage

  1. Start a new Middleman site using this template.

     $ middleman init my_new_site -T joshukraine/middleman-gulp
    
  2. Change into the project root and execute the setup script.

     $ cd my_new_site
     $ chmod +x bin/* # Make sure we can run included scripts
     $ bin/setup
    
  3. Start the Middleman server. Note that this will also invoke Gulp via the external pipeline.

     $ bundle exec middleman server
    
  4. Initialize a new Git repo.

     $ git init
     $ git add --all
     $ git commit -m "Initial commit"
     $ git remote add origin https://[your-repo-url]
     $ git push -u origin master
    

Deployment

I recommend Amazon S3 for deployment. It's very simple and surprisingly cost effective. Here's how to deploy your site to S3.

  1. Read Amazon's guide on Hosting a Static Website

  2. In the Gemfile, uncomment and install middleman-s3_sync

  3. Configure your deployment configs in environments/production.rb and environments/staging.rb.

  4. To deploy, run the deploy script, passing your desired environment as an argument.

     $ bin/deploy production
    
     # OR...
     $ bin/deploy staging
    

BONUS: If you deploy with Amazon, you can get a free ssl certificate for your site!

Environments

Middleman has two default environments: development and production. This template is configured to run the external pipeline (Gulp in our case) in both. There are times, however, when the external pipeline should not run. Two good examples are tests and the console. We therefore define two additional environments: test and console.

Custom environments can be invoked on the command line with -e flag like so:

# Start the console in the console enviroment
$ bundle exec middleman console -e console

Code for custom environments is stored in environments/<your-custom-env>.rb. Note that custom environments can be invoked without the existence of a corresponding file in the environments/ directory. If, for example, you merely wanted to start a server without the default development configs, you could run middleman server -e <anything-here>.

For completeness, all five environments used in this template have corresponding files:

environments/
├── console.rb
├── development.rb
├── production.rb
├── staging.rb
└── test.rb

Middleman vs. Gulp

As I initially experimented with Gulp and Middleman, it was sometimes difficult to determine which tool should handle which tasks. The problem is that, while Gulp and Middleman are very different, they have a fair amount of overlapping functionality. For example, Middleman can minify your CSS and JavaScript right out of the box. So can Gulp. Middleman can also minify your HTML, gzip your files, and automatically reload your browser using LiveReload. And Gulp can do all these things too.

So how do you decide who does what? I think most people would be inclined to have Gulp do it all. That's what it was designed for, and it makes sense to keep all these asset-related tasks in one place. However, since we're using Gulp inside of Middleman - a robust static site generator - I think there are some tasks that are better left to Middleman. Here's how I've broken it down in this template:

Middleman Gulp
HTML Templating
Minify HTML
Gzip Files
Preprocess CSS
Minify CSS
Minify Javascript
Sourcemaps
Autoprefixer
Bundle JavaScript
Compress Images
Copy web fonts
Browser Reload

Tests

Testing is done with Rspec. A few basic tests are provided as an example. Run your test suite like so:

$ bin/rspec spec/

Aliases

Consider adding the following to your .bashrc or .zshrc file:

mm='bundle exec middleman'
mmb='bundle exec middleman build --clean'
mmc='bundle exec middleman console -e console'
mms='bundle exec middleman server'

Acknowledgements

The following repos were very helpful in setting up this template.

Reference

License

Copyright © 2018 Joshua Steele. MIT License




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
sindresorhus/gulp-rework: Preprocess CSS with Rework发布时间:2022-06-21
下一篇:
jairtrejo/simple-gulp-template: A bare gulpjs template发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap