webpack-rails-react 0.9.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -24
- data/example/package.json +1 -1
- data/lib/generators/{webpack_rails → webpack_rails_react}/install_generator.rb +2 -2
- data/lib/{webpack-rails.rb → webpack-rails-react.rb} +0 -0
- data/lib/webpack/rails.rb +2 -2
- data/lib/webpack/rails/react/helper.rb +36 -0
- data/lib/webpack/rails/react/manifest.rb +91 -0
- data/lib/webpack/rails/{version.rb → react/version.rb} +3 -1
- data/lib/webpack/railtie.rb +3 -3
- metadata +11 -8
- data/lib/webpack/rails/helper.rb +0 -32
- data/lib/webpack/rails/manifest.rb +0 -89
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d23277a4284c9caef4383ca8d2bda3752ff30011
|
4
|
+
data.tar.gz: afd4a1123d9adebbbc20f78049983e7a9a73c487
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b306c9405d3358b76914c6f139f0314c48b30ef031797ac186e6c354c67a1deab5caa39916bad5df86ec0e69da87206ecc6aba4d8926a743a10b8a0141ade174
|
7
|
+
data.tar.gz: b5c6a79127db665d8f381c3a22155d244507a3d6690dc031ec88e8ebadddef654cbb343687f39b3ae45789179db7b4e2de257bbd4b1ee1ea3e4b44deb560179e
|
data/README.md
CHANGED
@@ -1,28 +1,22 @@
|
|
1
|
-
|
1
|
+
# webpack-rails-react
|
2
2
|
|
3
|
-
|
3
|
+
**webpack-rails-react** gives you tools to integrate Webpack and React in to an existing Ruby on Rails application.
|
4
4
|
|
5
|
-
**webpack-rails**
|
6
|
-
|
7
|
-
It will happily co-exist with sprockets but does not use it for production fingerprinting or asset serving. **webpack-rails** is designed with the assumption that if you're using Webpack you treat Javascript as a first-class citizen. This means that you control the webpack config, package.json, and use npm to install Webpack & its plugins.
|
5
|
+
It will happily co-exist with sprockets but does not use it for production fingerprinting or asset serving. **webpack-rails-react** is designed with the assumption that if you're using Webpack you treat Javascript as a first-class citizen. This means that you control the webpack config, package.json, and use npm to install Webpack & its plugins.
|
8
6
|
|
9
7
|
In development mode [webpack-dev-server](http://webpack.github.io/docs/webpack-dev-server.html) is used to serve webpacked entry points and offer hot module reloading. In production entry points are built in to `public/webpack`. **webpack-rails** uses [stats-webpack-plugin](https://www.npmjs.com/package/stats-webpack-plugin) to translate entry points in to asset paths.
|
10
8
|
|
11
|
-
It was
|
12
|
-
|
13
|
-
Our examples show **webpack-rails** co-existing with sprockets (as that's how environment works), but sprockets is not used or required for development or production use of this gem.
|
9
|
+
It was forked from the [Marketplacer](http://www.marketplacer.com) repo: (https://github.com/mipearson/webpack-rails) and support for React / Babel / ES6 was added.
|
14
10
|
|
15
11
|
This gem has been tested against Rails 4.2 and Ruby 2.2. Earlier versions of Rails (>= 3.2) and Ruby (>= 1.9) may work, but we haven't tested them.
|
16
12
|
|
17
|
-
## Using webpack-rails
|
18
|
-
|
19
|
-
**We have a demo application: [webpack-rails-demo](https://github.com/mipearson/webpack-rails-demo)**
|
13
|
+
## Using webpack-rails-react
|
20
14
|
|
21
15
|
### Installation
|
22
16
|
|
23
|
-
1. Add `webpack-rails` to your gemfile
|
17
|
+
1. Add `webpack-rails-react` to your gemfile
|
24
18
|
1. Run `bundle install` to install the gem
|
25
|
-
1. Run `bundle exec rails generate
|
19
|
+
1. Run `bundle exec rails generate webpack_rails_react:install` to copy across example files
|
26
20
|
1. Run `foreman start` to start `webpack-dev-server` and `rails server` at the same time
|
27
21
|
1. Add the webpack entry point to your layout (see next section)
|
28
22
|
1. Edit `client/application.js` and write some code
|
@@ -46,14 +40,6 @@ If you're using the webpack dev server's live reload feature (not the React hot
|
|
46
40
|
<script src="http://localhost:3808/webpack-dev-server.js"></script>
|
47
41
|
```
|
48
42
|
|
49
|
-
### How it works
|
50
|
-
|
51
|
-
Have a look at the files in the `examples` directory. Of note:
|
52
|
-
|
53
|
-
* We use [foreman](https://github.com/ddollar/foreman) and a `Procfile` to run our rails server & the webpack dev server in development at the same time
|
54
|
-
* The webpack and gem configuration must be in sync - look at our railtie for configuration options
|
55
|
-
* We require that **stats-webpack-plugin** is loaded to automatically generate a production manifest & resolve paths during development
|
56
|
-
|
57
43
|
### Configuration Defaults
|
58
44
|
|
59
45
|
* Webpack configuration lives in `config/webpack.config.js`
|
@@ -96,6 +82,5 @@ Please ensure that pull requests pass both rubocop & rspec. New functionality sh
|
|
96
82
|
|
97
83
|
## Acknowledgements
|
98
84
|
|
99
|
-
*
|
100
|
-
*
|
101
|
-
* Clark Dave for [How to use Webpack with Rails](http://clarkdave.net/2015/01/how-to-use-webpack-with-rails/)
|
85
|
+
* mipearson for his [webpack-rails](https://github.com/mipearson/webpack-rails) gem which inspired this implementation
|
86
|
+
* David Jungst for his fork of [webpack-rails](https://github.com/wdjungst/webpack-rails-react) and idea / implementation to add React / Babel / ES6 boilerplate.
|
data/example/package.json
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module WebpackRailsReact
|
2
2
|
# :nodoc:
|
3
3
|
class InstallGenerator < ::Rails::Generators::Base
|
4
4
|
source_root File.expand_path("../../../../example", __FILE__)
|
@@ -31,7 +31,7 @@ module WebpackRails
|
|
31
31
|
|
32
32
|
ReactDOM.render(
|
33
33
|
<App />,
|
34
|
-
|
34
|
+
document.getElementById('app')
|
35
35
|
)
|
36
36
|
EOF
|
37
37
|
end
|
File without changes
|
data/lib/webpack/rails.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require 'webpack/rails/version'
|
2
|
-
require 'webpack/railtie' if defined? ::Rails::Railtie
|
1
|
+
require 'webpack/rails/react/version'
|
2
|
+
require 'webpack/railtie' if defined? ::Rails::Railtie
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'webpack/rails/react/manifest'
|
3
|
+
|
4
|
+
module Webpack
|
5
|
+
module Rails
|
6
|
+
module React
|
7
|
+
# Asset path helpers for use with webpack
|
8
|
+
module Helper
|
9
|
+
# Return asset paths for a particular webpack entry point.
|
10
|
+
#
|
11
|
+
# Response may either be full URLs (eg http://localhost/...) if the dev server
|
12
|
+
# is in use or a host-relative URl (eg /webpack/...) if assets are precompiled.
|
13
|
+
#
|
14
|
+
# Will raise an error if our manifest can't be found or the entry point does
|
15
|
+
# not exist.
|
16
|
+
def webpack_asset_paths(source, extension: nil)
|
17
|
+
return "" unless source.present?
|
18
|
+
|
19
|
+
paths = Webpack::Rails::React::Manifest.asset_paths(source)
|
20
|
+
paths = paths.select {|p| p.ends_with? ".#{extension}" } if extension
|
21
|
+
|
22
|
+
host = ::Rails.configuration.webpack.dev_server.host
|
23
|
+
port = ::Rails.configuration.webpack.dev_server.port
|
24
|
+
|
25
|
+
if ::Rails.configuration.webpack.dev_server.enabled
|
26
|
+
paths.map! do |p|
|
27
|
+
"//#{host}:#{port}#{p}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
paths
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Webpack
|
5
|
+
module Rails
|
6
|
+
module React
|
7
|
+
# Webpack manifest loading, caching & entry point retrieval
|
8
|
+
class Manifest
|
9
|
+
# Raised if we can't read our webpack manifest for whatever reason
|
10
|
+
class ManifestLoadError < StandardError
|
11
|
+
def initialize(message, orig)
|
12
|
+
super "#{message} (original error #{orig})"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Raised if a supplied entry point does not exist in the webpack manifest
|
17
|
+
class EntryPointMissingError < StandardError
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
# :nodoc:
|
22
|
+
def asset_paths(source)
|
23
|
+
paths = manifest["assetsByChunkName"][source]
|
24
|
+
if paths
|
25
|
+
# Can be either a string or an array of strings.
|
26
|
+
# Do not include source maps as they are not javascript
|
27
|
+
[paths].flatten.reject { |p| p =~ /.*\.map$/ }.map do |p|
|
28
|
+
"/#{::Rails.configuration.webpack.public_path}/#{p}"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
raise EntryPointMissingError, "Can't find entry point '#{source}' in webpack manifest"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def manifest
|
38
|
+
if ::Rails.configuration.webpack.dev_server.enabled
|
39
|
+
# Don't cache if we're in dev server mode, manifest may change ...
|
40
|
+
load_manifest
|
41
|
+
else
|
42
|
+
# ... otherwise cache at class level, as JSON loading/parsing can be expensive
|
43
|
+
@manifest ||= load_manifest
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def load_manifest
|
48
|
+
data = if ::Rails.configuration.webpack.dev_server.enabled
|
49
|
+
load_dev_server_manifest
|
50
|
+
else
|
51
|
+
load_static_manifest
|
52
|
+
end
|
53
|
+
JSON.parse(data)
|
54
|
+
end
|
55
|
+
|
56
|
+
def load_dev_server_manifest
|
57
|
+
http = Net::HTTP.new(
|
58
|
+
"localhost",
|
59
|
+
::Rails.configuration.webpack.dev_server.port)
|
60
|
+
http.use_ssl = ::Rails.configuration.webpack.dev_server.https
|
61
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
62
|
+
http.get(dev_server_path).body
|
63
|
+
rescue => e
|
64
|
+
raise ManifestLoadError.new("Could not load manifest from webpack-dev-server at #{dev_server_url} - is it running, and is stats-webpack-plugin loaded?", e)
|
65
|
+
end
|
66
|
+
|
67
|
+
def load_static_manifest
|
68
|
+
File.read(static_manifest_path)
|
69
|
+
rescue => e
|
70
|
+
raise ManifestLoadError.new("Could not load compiled manifest from #{static_manifest_path} - have you run `rake webpack:compile`?", e)
|
71
|
+
end
|
72
|
+
|
73
|
+
def static_manifest_path
|
74
|
+
::Rails.root.join(
|
75
|
+
::Rails.configuration.webpack.output_dir,
|
76
|
+
::Rails.configuration.webpack.manifest_filename
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def dev_server_path
|
81
|
+
"/#{::Rails.configuration.webpack.public_path}/#{::Rails.configuration.webpack.manifest_filename}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def dev_server_url
|
85
|
+
"http://localhost:#{::Rails.configuration.webpack.dev_server.port}#{dev_server_path}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/webpack/railtie.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require 'rails/railtie'
|
3
|
-
require 'webpack/rails/helper'
|
3
|
+
require 'webpack/rails/react/helper'
|
4
4
|
|
5
5
|
module Webpack
|
6
6
|
# :nodoc:
|
7
7
|
class Railtie < ::Rails::Railtie
|
8
8
|
config.after_initialize do
|
9
9
|
ActiveSupport.on_load(:action_view) do
|
10
|
-
include Webpack::Rails::Helper
|
10
|
+
include Webpack::Rails::React::Helper
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -30,4 +30,4 @@ module Webpack
|
|
30
30
|
load "tasks/webpack.rake"
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webpack-rails-react
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Jugnst
|
8
|
+
- Jake Sorce
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
@@ -28,6 +29,7 @@ description: Production-tested, JavaScript-first tooling to use webpack within y
|
|
28
29
|
Rails application
|
29
30
|
email:
|
30
31
|
- djungst@gmail.com
|
32
|
+
- jakesorce@gmail.com
|
31
33
|
executables: []
|
32
34
|
extensions: []
|
33
35
|
extra_rdoc_files: []
|
@@ -39,15 +41,15 @@ files:
|
|
39
41
|
- example/dot_gitignore
|
40
42
|
- example/package.json
|
41
43
|
- example/webpack.config.js
|
42
|
-
- lib/generators/
|
44
|
+
- lib/generators/webpack_rails_react/install_generator.rb
|
43
45
|
- lib/tasks/webpack.rake
|
44
|
-
- lib/webpack-rails.rb
|
46
|
+
- lib/webpack-rails-react.rb
|
45
47
|
- lib/webpack/rails.rb
|
46
|
-
- lib/webpack/rails/helper.rb
|
47
|
-
- lib/webpack/rails/manifest.rb
|
48
|
-
- lib/webpack/rails/version.rb
|
48
|
+
- lib/webpack/rails/react/helper.rb
|
49
|
+
- lib/webpack/rails/react/manifest.rb
|
50
|
+
- lib/webpack/rails/react/version.rb
|
49
51
|
- lib/webpack/railtie.rb
|
50
|
-
homepage: https://github.com/
|
52
|
+
homepage: https://github.com/jakesorce/webpack-rails-react
|
51
53
|
licenses:
|
52
54
|
- MIT
|
53
55
|
metadata: {}
|
@@ -59,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
61
|
requirements:
|
60
62
|
- - ">="
|
61
63
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
64
|
+
version: 2.0.0
|
63
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
66
|
requirements:
|
65
67
|
- - ">="
|
@@ -72,3 +74,4 @@ signing_key:
|
|
72
74
|
specification_version: 4
|
73
75
|
summary: Webpack / Rails / React
|
74
76
|
test_files: []
|
77
|
+
has_rdoc:
|
data/lib/webpack/rails/helper.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'action_view'
|
2
|
-
require 'webpack/rails/manifest'
|
3
|
-
|
4
|
-
module Webpack
|
5
|
-
module Rails
|
6
|
-
# Asset path helpers for use with webpack
|
7
|
-
module Helper
|
8
|
-
# Return asset paths for a particular webpack entry point.
|
9
|
-
#
|
10
|
-
# Response may either be full URLs (eg http://localhost/...) if the dev server
|
11
|
-
# is in use or a host-relative URl (eg /webpack/...) if assets are precompiled.
|
12
|
-
#
|
13
|
-
# Will raise an error if our manifest can't be found or the entry point does
|
14
|
-
# not exist.
|
15
|
-
def webpack_asset_paths(source)
|
16
|
-
return "" unless source.present?
|
17
|
-
|
18
|
-
paths = Webpack::Rails::Manifest.asset_paths(source)
|
19
|
-
host = ::Rails.configuration.webpack.dev_server.host
|
20
|
-
port = ::Rails.configuration.webpack.dev_server.port
|
21
|
-
|
22
|
-
if ::Rails.configuration.webpack.dev_server.enabled
|
23
|
-
paths.map! do |p|
|
24
|
-
"//#{host}:#{port}#{p}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
paths
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
module Webpack
|
5
|
-
module Rails
|
6
|
-
# Webpack manifest loading, caching & entry point retrieval
|
7
|
-
class Manifest
|
8
|
-
# Raised if we can't read our webpack manifest for whatever reason
|
9
|
-
class ManifestLoadError < StandardError
|
10
|
-
def initialize(message, orig)
|
11
|
-
super "#{message} (original error #{orig})"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Raised if a supplied entry point does not exist in the webpack manifest
|
16
|
-
class EntryPointMissingError < StandardError
|
17
|
-
end
|
18
|
-
|
19
|
-
class << self
|
20
|
-
# :nodoc:
|
21
|
-
def asset_paths(source)
|
22
|
-
paths = manifest["assetsByChunkName"][source]
|
23
|
-
if paths
|
24
|
-
# Can be either a string or an array of strings.
|
25
|
-
# Do not include source maps as they are not javascript
|
26
|
-
[paths].flatten.reject { |p| p =~ /.*\.map$/ }.map do |p|
|
27
|
-
"/#{::Rails.configuration.webpack.public_path}/#{p}"
|
28
|
-
end
|
29
|
-
else
|
30
|
-
raise EntryPointMissingError, "Can't find entry point '#{source}' in webpack manifest"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def manifest
|
37
|
-
if ::Rails.configuration.webpack.dev_server.enabled
|
38
|
-
# Don't cache if we're in dev server mode, manifest may change ...
|
39
|
-
load_manifest
|
40
|
-
else
|
41
|
-
# ... otherwise cache at class level, as JSON loading/parsing can be expensive
|
42
|
-
@manifest ||= load_manifest
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def load_manifest
|
47
|
-
data = if ::Rails.configuration.webpack.dev_server.enabled
|
48
|
-
load_dev_server_manifest
|
49
|
-
else
|
50
|
-
load_static_manifest
|
51
|
-
end
|
52
|
-
JSON.parse(data)
|
53
|
-
end
|
54
|
-
|
55
|
-
def load_dev_server_manifest
|
56
|
-
http = Net::HTTP.new(
|
57
|
-
"localhost",
|
58
|
-
::Rails.configuration.webpack.dev_server.port)
|
59
|
-
http.use_ssl = ::Rails.configuration.webpack.dev_server.https
|
60
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
61
|
-
http.get(dev_server_path).body
|
62
|
-
rescue => e
|
63
|
-
raise ManifestLoadError.new("Could not load manifest from webpack-dev-server at #{dev_server_url} - is it running, and is stats-webpack-plugin loaded?", e)
|
64
|
-
end
|
65
|
-
|
66
|
-
def load_static_manifest
|
67
|
-
File.read(static_manifest_path)
|
68
|
-
rescue => e
|
69
|
-
raise ManifestLoadError.new("Could not load compiled manifest from #{static_manifest_path} - have you run `rake webpack:compile`?", e)
|
70
|
-
end
|
71
|
-
|
72
|
-
def static_manifest_path
|
73
|
-
::Rails.root.join(
|
74
|
-
::Rails.configuration.webpack.output_dir,
|
75
|
-
::Rails.configuration.webpack.manifest_filename
|
76
|
-
)
|
77
|
-
end
|
78
|
-
|
79
|
-
def dev_server_path
|
80
|
-
"/#{::Rails.configuration.webpack.public_path}/#{::Rails.configuration.webpack.manifest_filename}"
|
81
|
-
end
|
82
|
-
|
83
|
-
def dev_server_url
|
84
|
-
"http://localhost:#{::Rails.configuration.webpack.dev_server.port}#{dev_server_path}"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|