webpack_manifest 0.2.1 → 0.2.2

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
- SHA256:
3
- metadata.gz: f921dccf167c3824b5b4be27adbbd0dafe54bb7334fc4ca2569d03cd18a6874f
4
- data.tar.gz: 52cc757897893892813beffd7b41fe69f98392466409cb0f681b23f3e07417db
2
+ SHA1:
3
+ metadata.gz: 94b6f1ca07113997a519c7df6ea709bd8738a1b1
4
+ data.tar.gz: d3080e24d148ef749589c257251c78d22709a148
5
5
  SHA512:
6
- metadata.gz: 821d92a75d9f50206124c7f32063bb547b7419f01312355b7493b5b8481bc8dc2df99ec9eb7f939199395814f11f45fc6ca30089bb7e8513ca7ea6953b0aa611
7
- data.tar.gz: f22f3e0a9b465d6b7b915cd4a5703e1f3877f6085e23e9eada3a1485485acf8ef5f1e7325a4aedb7be343dd865f53ea9acd37c4f77c62fcc0ca08cf1746654f6
6
+ metadata.gz: 844abcff5624053ea4e095415b99c10f15b74583189eb76128b545ea74c14bea96d087f0aeb4a19ba049beb89843005fbda9fc2b3f46477da8415cfc7714a393
7
+ data.tar.gz: e7ad9abb3e50eb55fd506af86957c180fbfb3debcc81e08680fc99a7f1564007de63e4a55df81a1e65ca0be30f900f16a20251e63f98d77f6d74e9d78c444f72
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.2.2 / 2018-11-05
2
+
3
+ ## Enhancements
4
+
5
+ * Support reading manifest.json from an uri (#4)
6
+
1
7
  # 0.2.1 / 2018-10-18
2
8
 
3
9
  * Improve exceptional case handling
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # WebpackManifest [![Build Status](https://travis-ci.org/nikushi/webpack_manifest.svg?branch=master)](https://travis-ci.org/nikushi/webpack_manifest) [![Gem Version](https://badge.fury.io/rb/webpack_manifest.svg)](https://badge.fury.io/rb/webpack_manifest)
2
2
 
3
- WebpackManifest is a gem that integrates Rails with npm's [webpack-manifest-plugin](https://www.npmjs.com/package/webpack-manifest-plugin) without [webpacker](https://github.com/rails/webpacker).
3
+ WebpackManifest is a gem that integrates Rails with npm's [webpack-manifest-plugin](https://www.npmjs.com/package/webpack-manifest-plugin) without [Webpacker](https://github.com/rails/webpacker).
4
4
 
5
5
  ## Features
6
6
 
7
- * Rails view helpers to access assets which are built by webpack according a manifest file.
7
+ * Rails view helpers to resolve paths to assets which are built by webpack according to a manifest file.
8
8
  * Multiple manifest files support
9
9
 
10
10
  ## Installation
@@ -23,6 +23,22 @@ Or install it yourself as:
23
23
 
24
24
  $ gem install webpack_manifest
25
25
 
26
+ ## Configuration
27
+
28
+ After installed, configure your Rails app below as a new file `config/initializers/webpack_manifest.rb`.
29
+
30
+ ```rb
31
+ WebpackManifest::Rails.configuration do |c|
32
+ # By default c.cache is set to `false`, which means an application always parses a
33
+ # manifest.json. In development, you should set cache false usually.
34
+ # Instead, setting it `true` which caches the manifest in memory is recommended basically.
35
+ c.cache = !Rails.env.development?
36
+
37
+ # Register a path to a manifest file here.
38
+ c.manifest = Rails.root.join('public', 'assets', 'manifest.json')
39
+ end
40
+ ```
41
+
26
42
  ## Usage
27
43
 
28
44
  ### Rails view helpers
@@ -31,7 +47,7 @@ Or install it yourself as:
31
47
 
32
48
  This is a wrapper of [asset_path](https://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html#method-i-asset_path). You can set any options of `asset_path`.
33
49
 
34
- Given entry point name is resolved according to definition of manifest.
50
+ A given entry point name is resolved according to definition of manifest.
35
51
 
36
52
  ```ruby
37
53
  asset_bundle_path 'calendar.css'
@@ -60,7 +76,7 @@ javascript_bundle_tag 'orders/app'
60
76
 
61
77
  This is a wrapper of [stylesheet_link_tag](https://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-stylesheet_link_tag). You can set any options of `stylesheet_link_tag`.
62
78
 
63
- Given entry point name is resolved according to definition of manifest.
79
+ A given entry point name is resolved according to definition of manifest.
64
80
 
65
81
  ```ruby
66
82
  stylesheet_bundle_tag 'calendar', 'data-turbolinks-track': 'reload'
@@ -77,7 +93,7 @@ stylesheet_bundle_tag 'orders/style'
77
93
 
78
94
  This is a wrapper of [image_tag](https://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-image_tag). You can set any options of `image_tag`.
79
95
 
80
- Given entry point name is resolved according to definition of manifest.
96
+ A given entry point name is resolved according to definition of manifest.
81
97
 
82
98
  ```ruby
83
99
  image_bundle_tag 'icon.png'
@@ -88,27 +104,31 @@ image_bundle_tag "icon.png", size: "16x10", alt: "Edit Entry"
88
104
  height="10" alt="Edit Entry" />
89
105
  ```
90
106
 
91
- ### Configuration
107
+ ## Advanced Configuration
92
108
 
93
- After installed, configure your Rails app by adding a new file `config/initializers/webpack_manifest.rb` as below.
109
+ ### Hot Module Replacement in development
110
+
111
+ Optionally you can integrate the gem with [webpack-dev-server](https://github.com/webpack/webpack-dev-server) to enable live reloading by setting an manifest url served by webpack-dev-server, instead of a local file path. This should be used for development only.
112
+
113
+ Note that WebpackManifest itself does not launches webpack-dev-server, so it must be started along with Rails server by yourself.
94
114
 
95
115
  ```rb
96
116
  WebpackManifest::Rails.configuration do |c|
97
- # By default c.cache is `false`, which means application always parses given
98
- # manifest json. Disableing cache is useful in development.
99
- # Set `true` if you would like to cache manifest in memory, for example in production.
100
117
  c.cache = !Rails.env.development?
101
118
 
102
- # Register a path to a manifest file here.
103
- c.manifest = Rails.root.join('public', 'assets', 'manifest.json')
119
+ c.manifest = if Rails.env.development?
120
+ 'http://localhost:8080/packs/manifest.json'
121
+ else
122
+ Rails.root.join('public', 'assets', 'manifest.json')
123
+ end
104
124
  end
105
125
  ```
106
126
 
107
127
  ### Multiple manifest files support
108
128
 
109
- This is optional. You can register multiple manifest files for the view helpers. This feature must be useful if your Rails project have several sites, then asset bundling process is separated.
129
+ This is optional. You can register multiple manifest files for the view helpers. This feature must be useful if your Rails project serves for several sites, then asset bundling process is isolated every site.
110
130
 
111
- For example, your project serve for two sites, `shop` and `admin` from each separated manifest file. You can register each as below.
131
+ For example, your project serve for two sites, `shop` and `admin` from each individual manifest file. You can register each as
112
132
 
113
133
  ```rb
114
134
  # In config/initializers/webpack_manifest.rb
@@ -116,7 +136,7 @@ For example, your project serve for two sites, `shop` and `admin` from each sepa
116
136
  WebpackManifest::Rails.configuration do |c|
117
137
  c.cache = !Rails.env.development?
118
138
 
119
- # If you have manifest files more than one, register them by `c.add` instead
139
+ # In order for Raild to handle multiple manifests, you must call `c.add` instead
120
140
  # of `c.manifest=`. Note that the first registered one(e.g. `shop` in this
121
141
  # example) is recognized as a default manifest.
122
142
  c.add :shop, Rails.root.join('public', 'assets', 'manifest-shop.json')
@@ -124,7 +144,7 @@ WebpackManifest::Rails.configuration do |c|
124
144
  end
125
145
  ```
126
146
 
127
- Then you can resolve paths with view helpers by passing `manifest:` option.
147
+ Then you can resolve a path with view helpers by passing `manifest:` option.
128
148
 
129
149
  ```
130
150
  # This resolves a path by shop's manifest json.
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
- require 'pathname'
4
+ require 'open-uri'
5
+ require 'uri'
5
6
 
6
7
  module WebpackManifest
7
8
  class Manifest
@@ -12,7 +13,7 @@ module WebpackManifest
12
13
  attr_writer :cache
13
14
 
14
15
  def initialize(path, cache: false)
15
- @path = Pathname.new(path)
16
+ @path = path.to_s
16
17
  @cache = cache
17
18
  end
18
19
 
@@ -43,8 +44,16 @@ module WebpackManifest
43
44
  end
44
45
 
45
46
  def load_data
46
- raise(FileNotFoundError, "#{@path}: no such manifest found") unless File.exist?(@path)
47
- JSON.parse(File.read(@path))
47
+ u = URI.parse(@path)
48
+ data = nil
49
+ if u.scheme == 'file' || u.path == @path # file path
50
+ raise(FileNotFoundError, "#{@path}: no such manifest found") unless File.exist?(@path)
51
+ data = File.read(@path)
52
+ else
53
+ # http url
54
+ data = u.read
55
+ end
56
+ JSON.parse(data)
48
57
  end
49
58
 
50
59
  def handle_missing_entry(name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebpackManifest
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpack_manifest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobuhiro Nikushi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-18 00:00:00.000000000 Z
11
+ date: 2018-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  requirements: []
108
108
  rubyforge_project:
109
- rubygems_version: 2.7.7
109
+ rubygems_version: 2.6.8
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: WebpackManifest is a gem that integrates Rails with npm's webpack-manifest-plugin