npm-pipeline-rails 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +7 -0
- data/README.md +51 -19
- data/docs/brunch.md +13 -43
- data/docs/gulp.md +60 -0
- data/docs/motivation.md +35 -0
- data/lib/generators/npm_pipeline/brunch_generator.rb +1 -0
- data/lib/generators/npm_pipeline/gulp/gulpfile.js +24 -0
- data/lib/generators/npm_pipeline/gulp/package.json +16 -0
- data/lib/generators/npm_pipeline/gulp_generator.rb +42 -0
- data/lib/npm-pipeline-rails/railtie.rb +1 -4
- data/lib/npm-pipeline-rails/version.rb +1 -1
- data/npm-pipeline-rails.gemspec +1 -1
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf569c96c85c02b65915d854b5ed6023012bc7aa
|
4
|
+
data.tar.gz: d0e38db04bb99ed44153f96d65740caddda891a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ef48bbe254b7960785f489b19401423419baa51776ebbe69837810c9bc78094fcd95107fc28376ca7a3b00f82a9b48b96d000c550fce141f5b57fa7ca5378ed
|
7
|
+
data.tar.gz: b8f655d71c5eab1cd5b1ecc7bd1fc8832a44e035fae1435b2e16fd9e7ee36d0315fcf2a1d2183f7ab7902ac239bab37809b348777a10b03946e423f7ce9bfbf6
|
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -2,36 +2,49 @@
|
|
2
2
|
|
3
3
|
> Use npm as part of your Rails asset pipeline
|
4
4
|
|
5
|
-
npm-pipeline-rails allows you to use any toolchain to bulid your asset files. This allows you to:
|
5
|
+
npm-pipeline-rails allows you to use any toolchain to bulid your asset files in [Rails] 4.2+. This allows you to:
|
6
6
|
|
7
|
-
- Use [
|
8
|
-
- Use [
|
9
|
-
- Use [
|
7
|
+
- Use [Brunch][] with Rails ([instructions](docs/brunch.md))
|
8
|
+
- Use [Gulp][] with Rails ([instructions](docs/gulp.md))
|
9
|
+
- Use [Grunt][] with Rails
|
10
|
+
- Use [Webpack][] with Rails
|
11
|
+
- Use [Browserify][] with Rails
|
10
12
|
- Use any other asset tool with Rails
|
11
13
|
|
12
|
-
[
|
13
|
-
[
|
14
|
-
[
|
14
|
+
[Rails]: http://rubyonrails.org/
|
15
|
+
[Webpack]: https://webpack.github.io/
|
16
|
+
[Brunch]: http://brunch.io/
|
17
|
+
[Browserify]: http://browserify.org/
|
18
|
+
[Gulp]: http://gulpjs.com/
|
19
|
+
[Grunt]: http://gruntjs.com/
|
15
20
|
|
16
|
-
>
|
21
|
+
<br>
|
17
22
|
|
18
|
-
|
23
|
+
![](docs/screenshots/full.png)
|
24
|
+
|
25
|
+
> _See [§ How it Works](#how-it-works) for an explanation of the diagram above._
|
19
26
|
|
20
|
-
|
27
|
+
<br>
|
21
28
|
|
22
|
-
|
23
|
-
gem 'npm-pipeline-rails'
|
24
|
-
```
|
29
|
+
## Usage
|
25
30
|
|
26
|
-
|
31
|
+
Add this line below to your `Gemfile`. After that, proceed with an automated or manual setup.
|
27
32
|
|
28
|
-
|
29
|
-
|
33
|
+
```rb
|
34
|
+
gem 'npm-pipeline-rails'
|
35
|
+
```
|
30
36
|
|
31
|
-
|
37
|
+
#### Automated setup
|
32
38
|
|
33
39
|
* Run `./bin/rails generate npm_pipeline:brunch` to add a sample integration with [Brunch]. ([info](docs/brunch.md))
|
34
40
|
|
41
|
+
#### Manual setup
|
42
|
+
|
43
|
+
* Create a `package.json` with `start` and `build` scripts. ([See example](lib/generators/npm_pipeline/brunch/package.json))
|
44
|
+
* Add your expected compiled assets to `.gitignore`.
|
45
|
+
|
46
|
+
<br>
|
47
|
+
|
35
48
|
## Configuration
|
36
49
|
|
37
50
|
npm-pipeline-rails provides these configuration options:
|
@@ -43,7 +56,7 @@ Rails.application.configure do
|
|
43
56
|
# Command to install dependencies
|
44
57
|
config.npm.install = ['npm install']
|
45
58
|
|
46
|
-
# Command to build production
|
59
|
+
# Command to build production assets
|
47
60
|
config.npm.build = ['npm run build']
|
48
61
|
|
49
62
|
# Command to start a file watcher
|
@@ -57,10 +70,14 @@ Rails.application.configure do
|
|
57
70
|
end
|
58
71
|
```
|
59
72
|
|
73
|
+
<br>
|
74
|
+
|
60
75
|
## How it works
|
61
76
|
|
62
77
|
npm-pipeline-rails allows you to hook certain commands, usually npm scripts, during the Rails app lifecycle. It assumes that your tool will build plain JS and CSS files into `vendor/assets`, allowing it to be picked up by Rails's asset pipeline.
|
63
78
|
|
79
|
+
It does __not__ replace the Rails asset pipeline, but rather it works with it. The files you build with your npm pipeline will be available as regular files in the Rails asset pipeline.
|
80
|
+
|
64
81
|
#### In development
|
65
82
|
|
66
83
|
When starting a Rails development server (`bundle exec rails s`), it runs the `install` command. After that, it starts a background process that runs your `watch` command.
|
@@ -69,10 +86,25 @@ When starting a Rails development server (`bundle exec rails s`), it runs the `i
|
|
69
86
|
|
70
87
|
When running `rake assets:precompile`, it will first run the `install` command then the `build` command.
|
71
88
|
|
89
|
+
#### More info
|
90
|
+
|
91
|
+
Consult [railtie.rb](https://github.com/rstacruz/npm-pipeline-rails/blob/master/lib/npm-pipeline-rails/railtie.rb) for the actual code that makes all these happen.
|
92
|
+
|
93
|
+
<br>
|
94
|
+
|
72
95
|
## Integration examples
|
73
96
|
|
74
97
|
* [Brunch](docs/brunch.md)
|
75
|
-
|
98
|
+
|
99
|
+
<br>
|
100
|
+
|
101
|
+
## Motivation
|
102
|
+
|
103
|
+
Rails's asset pipeline was a great step forward for Rails 3. For today's requirements however, it doesn't always come with all the tools you need. npm-pipeline-rails lets you outsource asset building complexities to Node.js-based tools.
|
104
|
+
|
105
|
+
> __[Read more →](docs/motivation.md)__
|
106
|
+
|
107
|
+
<br>
|
76
108
|
|
77
109
|
## Thanks
|
78
110
|
|
data/docs/brunch.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Brunch
|
1
|
+
# Brunch integration
|
2
2
|
|
3
3
|
Run `./bin/rails generate npm_pipeline:brunch`.
|
4
4
|
|
@@ -6,57 +6,27 @@ Run `./bin/rails generate npm_pipeline:brunch`.
|
|
6
6
|
|
7
7
|
If you don't want to use the generator, here's what it does.
|
8
8
|
|
9
|
-
###
|
9
|
+
### brunch-config.js
|
10
10
|
|
11
11
|
Set it up to watch source files in `app/brunch`, then put built files into `vendor/assets`.
|
12
|
+
[See example.](../lib/generators/npm_pipeline/brunch/brunch-config.js)
|
12
13
|
|
13
|
-
|
14
|
-
// See http://brunch.io for documentation.
|
15
|
-
module.exports = {
|
16
|
-
paths: {
|
17
|
-
watched: ['app/brunch'],
|
18
|
-
public: 'vendor/assets'
|
19
|
-
},
|
20
|
-
|
21
|
-
files: {
|
22
|
-
javascripts: {joinTo: 'javascripts/brunch/app.js'},
|
23
|
-
stylesheets: {joinTo: 'stylesheets/brunch/app.css'}
|
24
|
-
}
|
25
|
-
}
|
26
|
-
```
|
14
|
+
### package.json
|
27
15
|
|
28
|
-
|
29
|
-
|
30
|
-
```js
|
31
|
-
{
|
32
|
-
"name": "brunch-app",
|
33
|
-
"description": "Description",
|
34
|
-
"author": "Your Name",
|
35
|
-
"version": "0.1.0",
|
36
|
-
"scripts": {
|
37
|
-
"start": "brunch watch",
|
38
|
-
"build": "brunch build --production"
|
39
|
-
},
|
40
|
-
"dependencies": {},
|
41
|
-
"devDependencies": {
|
42
|
-
"brunch": "^2.5.1",
|
43
|
-
"javascript-brunch": "^2.0.0",
|
44
|
-
"css-brunch": "^2.0.0",
|
45
|
-
"auto-reload-brunch": "^2.0.0"
|
46
|
-
}
|
47
|
-
}
|
48
|
-
```
|
16
|
+
Set it up with `brunch` and some basic plugins.
|
17
|
+
[See example.](../lib/generators/npm_pipeline/brunch/package.json)
|
49
18
|
|
50
|
-
###
|
19
|
+
### .gitignore
|
51
20
|
|
52
21
|
Set it up to ignore Brunch's built files.
|
53
22
|
|
54
23
|
```
|
55
|
-
/
|
56
|
-
/vendor/assets/
|
24
|
+
/node_modules
|
25
|
+
/vendor/assets/stylesheets/brunch
|
26
|
+
/vendor/assets/javascripts/brunch
|
57
27
|
```
|
58
28
|
|
59
|
-
###
|
29
|
+
### app/assets/stylesheets/application.css
|
60
30
|
|
61
31
|
Set it up to include Brunch's built files. This will load from `vendor/assets/stylesheets`, as built by Brunch.
|
62
32
|
|
@@ -66,7 +36,7 @@ Set it up to include Brunch's built files. This will load from `vendor/assets/st
|
|
66
36
|
*/
|
67
37
|
```
|
68
38
|
|
69
|
-
###
|
39
|
+
### app/assets/javascripts/application.js
|
70
40
|
|
71
41
|
Set it up to include Brunch's built files. This will load from `vendor/assets/javascripts`, as built by Brunch.
|
72
42
|
|
@@ -74,7 +44,7 @@ Set it up to include Brunch's built files. This will load from `vendor/assets/ja
|
|
74
44
|
//= require brunch/app
|
75
45
|
```
|
76
46
|
|
77
|
-
###
|
47
|
+
### app/brunch/
|
78
48
|
|
79
49
|
Put your source files into `app/brunch`. For instance:
|
80
50
|
|
data/docs/gulp.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Gulp integration
|
2
|
+
|
3
|
+
Run `./bin/rails generate npm_pipeline:gulp`.
|
4
|
+
|
5
|
+
## Manual setup
|
6
|
+
|
7
|
+
If you don't want to use the generator, here's what it does.
|
8
|
+
|
9
|
+
### package.json
|
10
|
+
|
11
|
+
Set up `gulp`, `gulp-cli`, and some basic Gulp plugins.
|
12
|
+
[See example.](../lib/generators/npm_pipeline/gulp/package.json)
|
13
|
+
|
14
|
+
### gulpfile.js
|
15
|
+
|
16
|
+
Set it up to watch source files in `app/gulp`, then put built files into `vendor/assets`. [See example.](../lib/generators/npm_pipeline/gulp/gulpfile.js)
|
17
|
+
|
18
|
+
### .gitignore
|
19
|
+
|
20
|
+
Set it up to ignore Gulp's built files.
|
21
|
+
|
22
|
+
```
|
23
|
+
/node_modules
|
24
|
+
/vendor/assets/stylesheets/gulp
|
25
|
+
/vendor/assets/javascripts/gulp
|
26
|
+
```
|
27
|
+
|
28
|
+
### app/assets/stylesheets/application.css
|
29
|
+
|
30
|
+
Set it up to include Gulp's built files. This will load from `vendor/assets/stylesheets/gulp/app.css`, as built by Gulp.
|
31
|
+
|
32
|
+
```css
|
33
|
+
/*
|
34
|
+
*= require gulp/app
|
35
|
+
*/
|
36
|
+
```
|
37
|
+
|
38
|
+
### app/assets/javascripts/application.js
|
39
|
+
|
40
|
+
Set it up to include Gulp's built files. This will load from `vendor/assets/javascripts/gulp/app.js`, as built by Gulp.
|
41
|
+
|
42
|
+
```css
|
43
|
+
//= require gulp/app
|
44
|
+
```
|
45
|
+
|
46
|
+
### app/gulp/
|
47
|
+
|
48
|
+
Put your source files into `app/gulp`. For instance:
|
49
|
+
|
50
|
+
* `app/brunch/example.css`
|
51
|
+
|
52
|
+
```css
|
53
|
+
* { color: blue }
|
54
|
+
```
|
55
|
+
|
56
|
+
* `app/brunch/example.js`
|
57
|
+
|
58
|
+
```js
|
59
|
+
alert('it works!')
|
60
|
+
```
|
data/docs/motivation.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Motivation
|
2
|
+
|
3
|
+
Rails's asset pipeline was a great step forward for Rails 3. For today's requirements however, it doesn't always come with all the tools you need. Here's a portrait of Rails's shortcomings with respect to CSS/JS development in 2016:
|
4
|
+
|
5
|
+
* __npm assets:__ Frontend packages are now usually hosted in [npm], but there's no easy solution to integrate npm with Rails. Putting files into `vendor/assets` should be a thing of the past.
|
6
|
+
|
7
|
+
* __Auto-reload:__ Automatic CSS reloading can be done with [guard-livereload], but is unwieldy at best. They require too much configuration and mental overhead to maintain.
|
8
|
+
|
9
|
+
* __Modern CSS tools:__ Integrating modern CSS tools like [libsass] and [postcss] can be done, but is hackish and slow. It has to invoke a separate Node.js process for each CSS file rather than keeping those tools running in the background. Some newer CSS pre/post processors like [Myth](http://www.myth.io/) don't have production-grade integrations with Rails.
|
10
|
+
|
11
|
+
* __Modern JS tools:__ Working with complex frontends typically need [Webpack] or [Browserify]. While integrations for these exist, they can be slow and unreliable.
|
12
|
+
|
13
|
+
## Using Node.js
|
14
|
+
|
15
|
+
npm-pipeline-rails lets you outsource asset building complexities to Node.js-based tools, which is the gold stardard for asset tooling nowadays.
|
16
|
+
|
17
|
+
It doesn't lock you into one specific solution; you can use npm-pipeline-rails for any task manager. I recommend [Brunch] for its ease-of-use and familiarity with Rails's asset pipeline's features. [Gulp] and [Grunt] are also popular choices.
|
18
|
+
|
19
|
+
## Brunch
|
20
|
+
|
21
|
+
You can use [Brunch] with Rails with ease using npm-pipeline-rails. With Brunch, you get [automatic code reloading][auto-reload-brunch], easier integration with [postcss][postcss-brunch], `require()` support, and more. You may even hook [Browserify][browserify-brunch] if you need it.
|
22
|
+
|
23
|
+
[guard-livereload]: http://rubygems.org/gems/guard-livereload
|
24
|
+
[npm]: http://npmjs.com/
|
25
|
+
[libsass]: http://sass-lang.com/libsass
|
26
|
+
[postcss]: https://github.com/postcss/postcss
|
27
|
+
[auto-reload-brunch]: https://www.npmjs.com/package/auto-reload-brunch
|
28
|
+
[postcss-brunch]: https://www.npmjs.com/package/postcss-brunch
|
29
|
+
[browserify-brunch]: https://www.npmjs.com/package/browserify-brunch
|
30
|
+
[Grunt]: http://gruntjs.com/
|
31
|
+
[Webpack]: https://webpack.github.io/
|
32
|
+
[Brunch]: http://brunch.io/
|
33
|
+
[Browserify]: http://browserify.org/
|
34
|
+
[Gulp]: http://gulpjs.com/
|
35
|
+
[Grunt]: http://gruntjs.com/
|
@@ -0,0 +1,24 @@
|
|
1
|
+
var gulp = require('gulp')
|
2
|
+
var concat = require('gulp-concat')
|
3
|
+
|
4
|
+
gulp.task('build:js', function () {
|
5
|
+
return gulp.src('app/gulp/js/**/*.js')
|
6
|
+
.pipe(concat('app.js'))
|
7
|
+
.pipe(gulp.dest('vendor/assets/javascripts/gulp/'))
|
8
|
+
})
|
9
|
+
|
10
|
+
gulp.task('build:css', function () {
|
11
|
+
return gulp.src('app/gulp/css/**/*.css')
|
12
|
+
.pipe(gulp.dest('vendor/assets/stylesheets/gulp/'))
|
13
|
+
})
|
14
|
+
|
15
|
+
gulp.task('watch:js', function () {
|
16
|
+
gulp.watch('app/gulp/js/**/*.js', ['build:js'])
|
17
|
+
})
|
18
|
+
|
19
|
+
gulp.task('watch:css', function () {
|
20
|
+
gulp.watch('app/gulp/css/**/*.css', ['build:css'])
|
21
|
+
})
|
22
|
+
|
23
|
+
gulp.task('watch', ['watch:js', 'watch:css'])
|
24
|
+
gulp.task('build', ['build:js', 'build:css'])
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"name": "gulp-app",
|
3
|
+
"description": "Description",
|
4
|
+
"author": "Your Name",
|
5
|
+
"version": "0.1.0",
|
6
|
+
"scripts": {
|
7
|
+
"start": "gulp watch",
|
8
|
+
"build": "gulp build"
|
9
|
+
},
|
10
|
+
"dependencies": {},
|
11
|
+
"devDependencies": {
|
12
|
+
"gulp": "^3.9.1",
|
13
|
+
"gulp-cli": "^1.2.1",
|
14
|
+
"gulp-concat": "^2.6.0"
|
15
|
+
}
|
16
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module NpmPipeline
|
4
|
+
module Generators
|
5
|
+
class GulpGenerator < Rails::Generators::Base
|
6
|
+
desc 'Creates'
|
7
|
+
source_root File.expand_path('../gulp', __FILE__)
|
8
|
+
|
9
|
+
def create_package_json
|
10
|
+
template 'package.json', 'package.json'
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_gulpfile
|
14
|
+
template 'gulpfile.js', 'gulpfile.js'
|
15
|
+
end
|
16
|
+
|
17
|
+
def update_assets
|
18
|
+
append_to_file 'app/assets/stylesheets/application.css',
|
19
|
+
"/*\n *= require gulp/app\n */\n"
|
20
|
+
append_to_file 'app/assets/javascripts/application.js',
|
21
|
+
"//= require gulp/app\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_sample_css
|
25
|
+
create_file 'app/gulp/css/example.css',
|
26
|
+
%(html:before { content: 'Gulp assets added successfully! Edit app/gulp/example.css or remove it.'; display: block; padding: 20px; background: #ffc; color: #111; position: fixed; top: 16px; right: 16px; max-width: 600px; z-index: 10000; font-family: sans-serif; font-size: 14px; line-height: 1.6; }\n)
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_sample_js
|
30
|
+
create_file 'app/gulp/js/example.js',
|
31
|
+
"alert('Gulp works!')"
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_gitignore
|
35
|
+
append_to_file '.gitignore',
|
36
|
+
"/node_modules\n" +
|
37
|
+
"/vendor/assets/stylesheets/gulp\n" +
|
38
|
+
"/vendor/assets/javascripts/gulp\n"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -7,7 +7,6 @@ module NpmPipelineRails
|
|
7
7
|
[*commands].each do |cmd|
|
8
8
|
system cmd
|
9
9
|
exit $? unless $? == 0
|
10
|
-
|
11
10
|
end
|
12
11
|
end
|
13
12
|
end
|
@@ -16,14 +15,13 @@ module NpmPipelineRails
|
|
16
15
|
include ::NpmPipelineRails::Utils
|
17
16
|
|
18
17
|
config.npm = ActiveSupport::OrderedOptions.new
|
19
|
-
|
20
18
|
config.npm.build = ['npm run build']
|
21
19
|
config.npm.watch = ['npm run start']
|
22
20
|
config.npm.install = ['npm install']
|
23
21
|
|
24
22
|
rake_tasks do |app|
|
25
23
|
namespace :assets do
|
26
|
-
desc 'Build
|
24
|
+
desc 'Build asset prerequisites using npm'
|
27
25
|
task :npm_build do
|
28
26
|
do_system app.config.npm.install
|
29
27
|
do_system app.config.npm.build
|
@@ -36,7 +34,6 @@ module NpmPipelineRails
|
|
36
34
|
initializer 'npm_pipeline.watch' do |app|
|
37
35
|
if ::Rails.env.development? && ::Rails.const_defined?(:Server)
|
38
36
|
do_system app.config.npm.install
|
39
|
-
exit $? unless $? == 0
|
40
37
|
[*app.config.npm.watch].each do |cmd|
|
41
38
|
fork { do_system [cmd] }
|
42
39
|
end
|
data/npm-pipeline-rails.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = 'https://github.com/rstacruz/npm-pipeline-rails'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(examples|test|spec|features)/}) }
|
18
18
|
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: npm-pipeline-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rico Sta. Cruz
|
@@ -106,12 +106,17 @@ files:
|
|
106
106
|
- HISTORY.md
|
107
107
|
- README.md
|
108
108
|
- docs/brunch.md
|
109
|
+
- docs/gulp.md
|
110
|
+
- docs/motivation.md
|
109
111
|
- docs/screenshots/build.png
|
110
112
|
- docs/screenshots/full.png
|
111
113
|
- docs/screenshots/server.png
|
112
114
|
- lib/generators/npm_pipeline/brunch/brunch-config.js
|
113
115
|
- lib/generators/npm_pipeline/brunch/package.json
|
114
116
|
- lib/generators/npm_pipeline/brunch_generator.rb
|
117
|
+
- lib/generators/npm_pipeline/gulp/gulpfile.js
|
118
|
+
- lib/generators/npm_pipeline/gulp/package.json
|
119
|
+
- lib/generators/npm_pipeline/gulp_generator.rb
|
115
120
|
- lib/npm-pipeline-rails.rb
|
116
121
|
- lib/npm-pipeline-rails/railtie.rb
|
117
122
|
- lib/npm-pipeline-rails/version.rb
|