webpack-rails 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -2
- data/example/webpack.config.js +2 -2
- data/lib/tasks/webpack.rake +4 -3
- data/lib/webpack/rails/helper.rb +6 -3
- data/lib/webpack/rails/manifest.rb +14 -5
- data/lib/webpack/rails/version.rb +1 -1
- data/lib/webpack/railtie.rb +14 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfcf45814f51f113a5689c534a745ded9c30f0df
|
4
|
+
data.tar.gz: 3dd10a9be3d3c47a5c6571512096a0ca9d819da7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76391a93c60234bbd447bf0e71753d70759709db801a5447365736a98deaa9a5b8c0247294561741cc1ed150518d340b821933029621da10dfed3906699f6372
|
7
|
+
data.tar.gz: 11223b1c5d1eea5809581ab573b9b9c0140d607b0bbf12e14c9af38e57fc48b5ae135413c7da931302fccf321a4354b899741ece9b29324eb9bdb25a0231a188
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ It was designed for use at [Marketplacer](http://www.marketplacer.com) to assist
|
|
12
12
|
|
13
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.
|
14
14
|
|
15
|
-
This gem has been tested against Rails 4.2 and Ruby 2.2. Earlier versions of Rails (>= 3.2) and Ruby (>=
|
15
|
+
This gem has been tested against Rails 4.2 and Ruby 2.2. Earlier versions of Rails (>= 3.2) and Ruby (>= 2.0) may work, but we haven't tested them.
|
16
16
|
|
17
17
|
## Using webpack-rails
|
18
18
|
|
@@ -70,6 +70,22 @@ Have a look at the files in the `examples` directory. Of note:
|
|
70
70
|
* Webpacked assets will be compiled to `public/webpack`
|
71
71
|
* The manifest file is named `manifest.json`
|
72
72
|
|
73
|
+
#### Dynamic host
|
74
|
+
|
75
|
+
To have the host evaluated at request-time, set `host` to a proc:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
config.webpack.dev_server.host = proc { request.host }
|
79
|
+
```
|
80
|
+
|
81
|
+
This is useful when accessing your Rails app over the network (remember to bind both your Rails app and your WebPack server to `0.0.0.0`).
|
82
|
+
|
83
|
+
#### Use with docker-compose
|
84
|
+
|
85
|
+
If you're running `webpack-dev-server` as part of docker compose rather than `foreman`, you might find that the host and port that rails needs to use to retrieve the manifest isn't the same as the host and port that you'll be giving to the browser to retrieve the assets.
|
86
|
+
|
87
|
+
If so, you can set the `manifest_host` and `manifest_port` away from their default of `localhost` and port 3808.
|
88
|
+
|
73
89
|
### Working with browser tests
|
74
90
|
|
75
91
|
In development, we make sure that the `webpack-dev-server` is running when browser tests are running.
|
@@ -79,13 +95,17 @@ In development, we make sure that the `webpack-dev-server` is running when brows
|
|
79
95
|
In CI, we manually run `webpack` to compile the assets to public and set `config.webpack.dev_server.enabled` to `false` in our `config/environments/test.rb`:
|
80
96
|
|
81
97
|
``` ruby
|
82
|
-
|
98
|
+
config.webpack.dev_server.enabled = !ENV['CI']
|
83
99
|
```
|
84
100
|
|
85
101
|
### Production Deployment
|
86
102
|
|
87
103
|
Add `rake webpack:compile` to your deployment. It serves a similar purpose as Sprockets' `assets:precompile` task. If you're using Webpack and Sprockets (as we are at Marketplacer) you'll need to run both tasks - but it doesn't matter which order they're run in.
|
88
104
|
|
105
|
+
If you deploy to Heroku, you can add the special
|
106
|
+
[webpack-rails-buildpack](https://github.com/febeling/webpack-rails-buildpack)
|
107
|
+
in order to perform this rake task on each deployment.
|
108
|
+
|
89
109
|
If you're using `[chunkhash]` in your build asset filenames (which you should be, if you want to cache them in production), you'll need to persist built assets between deployments. Consider in-flight requests at the time of deployment: they'll receive paths based on the old `manifest.json`, not the new one.
|
90
110
|
|
91
111
|
## TODO
|
data/example/webpack.config.js
CHANGED
@@ -8,8 +8,8 @@ var StatsPlugin = require('stats-webpack-plugin');
|
|
8
8
|
// must match config.webpack.dev_server.port
|
9
9
|
var devServerPort = 3808;
|
10
10
|
|
11
|
-
// set
|
12
|
-
var production = process.env.
|
11
|
+
// set NODE_ENV=production on the environment to add asset fingerprints
|
12
|
+
var production = process.env.NODE_ENV === 'production';
|
13
13
|
|
14
14
|
var config = {
|
15
15
|
entry: {
|
data/lib/tasks/webpack.rake
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
namespace :webpack do
|
2
2
|
desc "Compile webpack bundles"
|
3
3
|
task compile: :environment do
|
4
|
-
ENV["TARGET"] = 'production'
|
4
|
+
ENV["TARGET"] = 'production' # TODO: Deprecated, use NODE_ENV instead
|
5
|
+
ENV["NODE_ENV"] = 'production'
|
5
6
|
webpack_bin = ::Rails.root.join(::Rails.configuration.webpack.binary)
|
6
7
|
config_file = ::Rails.root.join(::Rails.configuration.webpack.config_file)
|
7
8
|
|
@@ -13,7 +14,7 @@ namespace :webpack do
|
|
13
14
|
raise "Can't find our webpack config file at #{config_file}"
|
14
15
|
end
|
15
16
|
|
16
|
-
result =
|
17
|
-
raise result unless
|
17
|
+
result = `#{webpack_bin} --bail --config #{config_file} 2>&1`
|
18
|
+
raise result unless $CHILD_STATUS == 0
|
18
19
|
end
|
19
20
|
end
|
data/lib/webpack/rails/helper.rb
CHANGED
@@ -16,14 +16,17 @@ module Webpack
|
|
16
16
|
return "" unless source.present?
|
17
17
|
|
18
18
|
paths = Webpack::Rails::Manifest.asset_paths(source)
|
19
|
-
paths = paths.select {|p| p.ends_with? ".#{extension}" } if extension
|
19
|
+
paths = paths.select { |p| p.ends_with? ".#{extension}" } if extension
|
20
20
|
|
21
|
-
host = ::Rails.configuration.webpack.dev_server.host
|
22
21
|
port = ::Rails.configuration.webpack.dev_server.port
|
22
|
+
protocol = ::Rails.configuration.webpack.dev_server.https ? 'https' : 'http'
|
23
|
+
|
24
|
+
host = ::Rails.configuration.webpack.dev_server.host
|
25
|
+
host = instance_eval(&host) if host.respond_to?(:call)
|
23
26
|
|
24
27
|
if ::Rails.configuration.webpack.dev_server.enabled
|
25
28
|
paths.map! do |p|
|
26
|
-
"
|
29
|
+
"#{protocol}://#{host}:#{port}#{p}"
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
@@ -12,6 +12,13 @@ module Webpack
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
# Raised if webpack couldn't build one of your entry points
|
16
|
+
class WebpackError < StandardError
|
17
|
+
def initialize(errors)
|
18
|
+
super "Error in webpack compile, details follow below:\n#{errors.join("\n\n")}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
15
22
|
# Raised if a supplied entry point does not exist in the webpack manifest
|
16
23
|
class EntryPointMissingError < StandardError
|
17
24
|
end
|
@@ -19,6 +26,8 @@ module Webpack
|
|
19
26
|
class << self
|
20
27
|
# :nodoc:
|
21
28
|
def asset_paths(source)
|
29
|
+
raise WebpackError, manifest["errors"] if manifest["errors"].present?
|
30
|
+
|
22
31
|
paths = manifest["assetsByChunkName"][source]
|
23
32
|
if paths
|
24
33
|
# Can be either a string or an array of strings.
|
@@ -53,14 +62,14 @@ module Webpack
|
|
53
62
|
end
|
54
63
|
|
55
64
|
def load_dev_server_manifest
|
56
|
-
|
57
|
-
|
58
|
-
|
65
|
+
host = ::Rails.configuration.webpack.dev_server.manifest_host
|
66
|
+
port = ::Rails.configuration.webpack.dev_server.manifest_port
|
67
|
+
http = Net::HTTP.new(host, port)
|
59
68
|
http.use_ssl = ::Rails.configuration.webpack.dev_server.https
|
60
69
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
61
70
|
http.get(dev_server_path).body
|
62
71
|
rescue => e
|
63
|
-
raise ManifestLoadError.new("Could not load manifest from webpack-dev-server at #{
|
72
|
+
raise ManifestLoadError.new("Could not load manifest from webpack-dev-server at http://#{host}:#{port}#{dev_server_path} - is it running, and is stats-webpack-plugin loaded?", e)
|
64
73
|
end
|
65
74
|
|
66
75
|
def load_static_manifest
|
@@ -81,7 +90,7 @@ module Webpack
|
|
81
90
|
end
|
82
91
|
|
83
92
|
def dev_server_url
|
84
|
-
"http
|
93
|
+
"http://#{::Rails.configuration.webpack.dev_server.host}:#{::Rails.configuration.webpack.dev_server.port}#{dev_server_path}"
|
85
94
|
end
|
86
95
|
end
|
87
96
|
end
|
data/lib/webpack/railtie.rb
CHANGED
@@ -12,12 +12,24 @@ module Webpack
|
|
12
12
|
end
|
13
13
|
|
14
14
|
config.webpack = ActiveSupport::OrderedOptions.new
|
15
|
+
config.webpack.dev_server = ActiveSupport::OrderedOptions.new
|
16
|
+
|
15
17
|
config.webpack.config_file = 'config/webpack.config.js'
|
16
18
|
config.webpack.binary = 'node_modules/.bin/webpack'
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
+
# Host & port to use when generating asset URLS in the manifest helpers in dev
|
21
|
+
# server mode. Defaults to the requested host rather than localhost, so
|
22
|
+
# that requests from remote hosts work.
|
23
|
+
config.webpack.dev_server.host = proc { respond_to?(:request) ? request.host : 'localhost' }
|
20
24
|
config.webpack.dev_server.port = 3808
|
25
|
+
|
26
|
+
# The host and port to use when fetching the manifest
|
27
|
+
# This is helpful for e.g. docker containers, where the host and port you
|
28
|
+
# use via the web browser is not the same as those that the containers use
|
29
|
+
# to communicate among each other
|
30
|
+
config.webpack.dev_server.manifest_host = 'localhost'
|
31
|
+
config.webpack.dev_server.manifest_port = 3808
|
32
|
+
|
21
33
|
config.webpack.dev_server.https = false # note - this will use OpenSSL::SSL::VERIFY_NONE
|
22
34
|
config.webpack.dev_server.binary = 'node_modules/.bin/webpack-dev-server'
|
23
35
|
config.webpack.dev_server.enabled = !::Rails.env.production?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webpack-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Pearson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|