webpack-rails-react 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0da8cf4f7d6b95ba1a7cb9da36e7404392bb7bd9
4
- data.tar.gz: 805c1c43baab1db2c655ed4b059b8788df501f5a
3
+ metadata.gz: 0666af5c95adea9310b4b46f5a79fb08ab91c89f
4
+ data.tar.gz: c7a947c1895d8df2d6e03b5ae1a54f4cf03e07a4
5
5
  SHA512:
6
- metadata.gz: b23afced5ca978ba91d38bb3914ee2ad591d4ae33616b052381082410f1043cfe8cf3510968f8a055d60600258bf891c9b4d12077e3179f22e852ef7cc103de8
7
- data.tar.gz: f221bbbe50ce4d88c8f8991d1c29eb52d8a7c73c959ef678c79d0f3f079d69888387723a4f0e80acc854c2d5c2bd812c0f89577b7fc260bd981e5affcb7822fe
6
+ metadata.gz: 3df17e31cd4c474108d35037d4c8ee68d81ec7cfce060d8e8e0643ede832cda05b6c12971d2f491b75a152989ae715ab445b04eacdabe0c954908917fd42d388
7
+ data.tar.gz: 77c527eab7a0c5ccbac5043fdb039d6b60e2a8b6688bbf12c0c34b33a5eab5ace67ec1b732d7c1b20bcc641f0401ae9d13e1f80fee86c15d41c40d4b5e6679fd
data/README.md CHANGED
@@ -101,6 +101,15 @@ If you're using `[chunkhash]` in your build asset filenames (which you should be
101
101
  * Add eslint to client
102
102
  * Integration tests
103
103
 
104
+
105
+ ## Experimental
106
+ A view generator has been added.
107
+
108
+ 1.Generate a controller
109
+ 2.Add at least an index route for the controller
110
+ 3.rails g webpack_rails_react:view name_of_view (should be singular and match controller)
111
+
112
+
104
113
  ## Contributing
105
114
 
106
115
  Pull requests & issues welcome. Advice & criticism regarding webpack config approach also welcome.
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+
3
+ const Placeholder = () => (
4
+ <div>
5
+ </div>
6
+ )
7
+
8
+ export default Placeholder;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import Placeholder from './containers/Placeholder';
4
+
5
+ ReactDOM.render(
6
+ <Placeholder />,
7
+ document.getElementById('react')
8
+ );
@@ -0,0 +1,5 @@
1
+ <% content_for(:body_attributes) do %>
2
+ data-no-turbolink="true"
3
+ <% end %>
4
+ <div id="react"></div>
5
+ <%= javascript_include_tag *webpack_asset_paths('placeholder') %>
data/example/package.json CHANGED
@@ -2,6 +2,10 @@
2
2
  "name": "webpack-rails",
3
3
  "version": "0.0.1",
4
4
  "license": "MIT",
5
+ "scripts": {
6
+ "dev_server": "./node_modules/.bin/webpack-dev-server --config config/webpack.config.js",
7
+ "build": "webpack --config=config/webpack.config.js -p"
8
+ },
5
9
  "dependencies": {
6
10
  "react": "^15.1.0",
7
11
  "react-dom": "^15.1.0",
@@ -7,18 +7,6 @@ module WebpackRailsReact
7
7
  class_option :router, type: :boolean, default: false, description: 'Add React Router'
8
8
  class_option :redux, type: :boolean, default: false, description: 'Add Redux'
9
9
 
10
- def add_foreman_to_gemfile
11
- gem 'foreman'
12
- end
13
-
14
- def copy_procfile
15
- if File.exists? "Procfile"
16
- append_file "Procfile", "webpack: ./node_modules/.bin/webpack-dev-server --config config/webpack.config.js"
17
- else
18
- copy_file "Procfile", "Procfile"
19
- end
20
- end
21
-
22
10
  def copy_package_json
23
11
  copy_file "package.json", "package.json"
24
12
 
@@ -82,17 +70,23 @@ module WebpackRailsReact
82
70
  copy_file "boilerplate/App.js", "webpack/containers/App.js"
83
71
  end
84
72
 
85
- insert_into_file 'app/views/layouts/application.html.erb', before: /<\/body>/ do
86
- <<-'RUBY'
87
- <%= javascript_include_tag *webpack_asset_paths('application') %>
88
- RUBY
89
- end
90
- insert_into_file 'app/views/layouts/application.html.erb', before: /<\/head>/ do
91
- <<-'RUBY'
92
- <% if Rails.env.development? %>
93
- <script src="http://localhost:3808/webpack-dev-server.js"></script>
94
- <% end %>
95
- RUBY
73
+ application_view = 'app/views/layouts/application.html.erb'
74
+
75
+ if File.exists? application_view
76
+ insert_into_file 'app/views/layouts/application.html.erb', before: /<\/body>/ do
77
+ <<-'RUBY'
78
+ <%= ja vascript_include_tag *webpack_asset_paths('application') %>
79
+ RUBY
80
+ end
81
+ insert_into_file 'app/views/layouts/application.html.erb', before: /<\/head>/ do
82
+ <<-'RUBY'
83
+ <% if Rails.env.development? %>
84
+ <script src="http://localhost:3808/webpack-dev-server.js"></script>
85
+ <% end %>
86
+ RUBY
87
+ end
88
+ else
89
+ puts "\n\n***WARNING*** HAML NOT SUPPORTED IN applictaion.html additional steps required\n\n"
96
90
  end
97
91
  end
98
92
 
@@ -110,10 +104,6 @@ module WebpackRailsReact
110
104
  run "npm install" if yes?("Would you like us to run 'npm install' for you?")
111
105
  end
112
106
 
113
- def run_bundle_install
114
- run "bundle install" if yes?("Would you like us to run 'bundle install' for you?")
115
- end
116
-
117
107
  def whats_next
118
108
  puts <<-EOF.strip_heredoc
119
109
 
@@ -122,8 +112,9 @@ module WebpackRailsReact
122
112
 
123
113
  1. Add an element with an id of 'app' to your layout
124
114
  2. To disable hot module replacement remove <script src="http://localhost:3808/webpack-dev-server.js"></script> from layout
125
- 3. Run 'foreman start' to run the webpack-dev-server and rails server
126
- 4. If you are using react-router and want to sync server routes add:
115
+ 3. Run 'npm run dev_server' to run the webpack-dev-server
116
+ 4. Run 'bundle exec rails s' to run the rails server (both servers must be running)
117
+ 5. If you are using react-router and want to sync server routes add:
127
118
  get '*unmatched_route', to: <your client controller>#<default action>
128
119
  This must be the very last route in your routes.rb file
129
120
  e.g. get '*unmatched_route', to: 'home#index'
@@ -0,0 +1,45 @@
1
+ module WebpackRailsReact
2
+ # :nodoc:
3
+ class ViewGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path("../../../../example", __FILE__)
5
+
6
+ desc "Generate a view with webpack entry / rails view / and webpack container"
7
+
8
+ def normalize_view_name
9
+ raise "View name argument missing" if args.length == 0
10
+ @view = args[0]
11
+ end
12
+
13
+ def update_webpack_entry
14
+ name = @view.downcase.gsub(/ /, "_")
15
+ path = "'#{name}': './webpack/#{name}.js',"
16
+ insert_into_file 'config/webpack.config.js', after: /entry: {\n/ do
17
+ <<-CONFIG
18
+ #{path}
19
+ CONFIG
20
+ end
21
+ end
22
+
23
+ def create_entry_file
24
+ file = "webpack/#{@view.gsub(/ /, '')}.js"
25
+ name = @view.titleize.gsub(/ /, '')
26
+ copy_file "boilerplate/views/ViewTemplate.js", file
27
+ gsub_file file, /Placeholder/, name
28
+ end
29
+
30
+ def create_container
31
+ name = @view.titleize.gsub(/ /, '')
32
+ file = "webpack/containers/#{name}.js"
33
+ copy_file "boilerplate/views/ContainerTemplate.js", file
34
+ gsub_file file, /Placeholder/, name
35
+ end
36
+
37
+ def create_rails_view
38
+ name = @view.downcase.gsub(/ /, '_')
39
+ empty_directory "app/views/#{name.pluralize}"
40
+ file = "app/views/#{name.pluralize}/index.html.erb"
41
+ copy_file "boilerplate/views/rails_view.html.erb", file
42
+ gsub_file file, /placeholder/, name
43
+ end
44
+ end
45
+ end
@@ -33,4 +33,4 @@ module Webpack
33
33
  end
34
34
  end
35
35
  end
36
- end
36
+ end
@@ -2,7 +2,7 @@ module Webpack
2
2
  # :nodoc:
3
3
  module Rails
4
4
  module React
5
- VERSION = "1.0.8"
5
+ VERSION = "1.0.9"
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpack-rails-react
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Jungst
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-11 00:00:00.000000000 Z
12
+ date: 2016-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -50,10 +50,14 @@ files:
50
50
  - example/boilerplate/router_redux/reducers.js
51
51
  - example/boilerplate/router_redux/store.js
52
52
  - example/boilerplate/routes.js
53
+ - example/boilerplate/views/ContainerTemplate.js
54
+ - example/boilerplate/views/ViewTemplate.js
55
+ - example/boilerplate/views/rails_view.html.erb
53
56
  - example/dot_gitignore
54
57
  - example/package.json
55
58
  - example/webpack.config.js
56
59
  - lib/generators/webpack_rails_react/install_generator.rb
60
+ - lib/generators/webpack_rails_react/view_generator.rb
57
61
  - lib/tasks/webpack.rake
58
62
  - lib/webpack-rails-react.rb
59
63
  - lib/webpack/rails.rb
@@ -81,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
85
  version: '0'
82
86
  requirements: []
83
87
  rubyforge_project:
84
- rubygems_version: 2.5.1
88
+ rubygems_version: 2.4.5
85
89
  signing_key:
86
90
  specification_version: 4
87
91
  summary: Webpack / Rails / React