webpack_manifest 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +6 -0
- data/README.md +49 -1
- data/lib/webpack_manifest/manifest.rb +19 -0
- data/lib/webpack_manifest/rails/helper.rb +41 -0
- data/lib/webpack_manifest/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3c84129d2cae2ae37bbae7b815e1ab134a6c2888
|
4
|
+
data.tar.gz: 40d2d9570f9c4062217e458fe611b1236448663d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f346cc44f955707241a230d7ee70a0b89b2b96e171c595811d8a61259bfb8e7228d5242fee13b2effb6ed45e72c6a12ac407d722c44123d36c71d847d7ca0add
|
7
|
+
data.tar.gz: e0a0c11b1ac4c5cda1b06592f5e6a8e4ac5c95922161aa07e3831cec2a58a353cd30398adc03943860359787d1ee983941ca785070bfdca84b32e36b73ea17c4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# 0.2.4 / 2019-03-25
|
2
|
+
|
3
|
+
## Enhancements:
|
4
|
+
|
5
|
+
* Added `javascript_bundles_with_chunks_tag` and `stylesheet_bundles_with_chunks_tag` helpers, which creates html tags for a pack and all the dependent chunks, when using splitChunks. (#7)
|
6
|
+
|
1
7
|
# 0.2.3 / 2018-11-18
|
2
8
|
|
3
9
|
* Support passing symbols to helper methods (#5) by @jmortlock
|
data/README.md
CHANGED
@@ -104,6 +104,54 @@ image_bundle_tag "icon.png", size: "16x10", alt: "Edit Entry"
|
|
104
104
|
height="10" alt="Edit Entry" />
|
105
105
|
```
|
106
106
|
|
107
|
+
|
108
|
+
#### `javascript_bundles_with_chunks_tag` and `stylesheet_bundles_with_chunks_tag`
|
109
|
+
|
110
|
+
**Experimental** These are the helpers, which are similar to Webpacker, to support `splitChunks` feature introduced since Webpack 4.
|
111
|
+
|
112
|
+
For the full configuration options of splitChunks, see the Webpack's [documentation](https://webpack.js.org/plugins/split-chunks-plugin/).
|
113
|
+
|
114
|
+
Then use the `javascript_bundles_with_chunks_tag` and `stylesheet_bundles_with_chunks_tag` helpers to include all
|
115
|
+
the transpiled packs with the chunks in your view, which creates html tags for all the chunks.
|
116
|
+
|
117
|
+
```
|
118
|
+
<%= javascript_bundles_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
|
119
|
+
|
120
|
+
<!-- Creates the following: -->
|
121
|
+
<script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
122
|
+
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
123
|
+
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
124
|
+
<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
125
|
+
<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
126
|
+
```
|
127
|
+
|
128
|
+
**Important:** Pass all your pack names to the helper otherwise you will get duplicated chunks on the page.
|
129
|
+
|
130
|
+
```
|
131
|
+
<%# DO %>
|
132
|
+
<%= javascript_bundles_with_chunks_tag 'calendar', 'map' %>
|
133
|
+
|
134
|
+
<%# DON'T %>
|
135
|
+
<%= javascript_bundles_with_chunks_tag 'calendar' %>
|
136
|
+
<%= javascript_bundles_with_chunks_tag 'map' %>
|
137
|
+
```
|
138
|
+
|
139
|
+
**Important:** Also, these helpers do not work with `webpack-manifest-plugin` npm because it has no support to generate a manifest with a set of of chunk entries https://github.com/danethurber/webpack-manifest-plugin/issues/133. Instead, [webpack-assets-manifest](https://github.com/webdeveric/webpack-assets-manifest) npm supports. Please change the plugin for manifest file generation if you wish to enable `splitChunks` feature.
|
140
|
+
|
141
|
+
```
|
142
|
+
const WebpackAssetsManifest = require('webpack-assets-manifest');
|
143
|
+
|
144
|
+
module.exports = {
|
145
|
+
// ...
|
146
|
+
plugins: [
|
147
|
+
new WebpackAssetsManifest({
|
148
|
+
entrypoints: true, // Please set this as true
|
149
|
+
})
|
150
|
+
],
|
151
|
+
// ...
|
152
|
+
}
|
153
|
+
```
|
154
|
+
|
107
155
|
## Advanced Configuration
|
108
156
|
|
109
157
|
### Hot Module Replacement in development
|
@@ -177,7 +225,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
177
225
|
|
178
226
|
## Contributing
|
179
227
|
|
180
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
228
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nikushi/webpack_manifest.
|
181
229
|
|
182
230
|
## License
|
183
231
|
|
@@ -17,6 +17,12 @@ module WebpackManifest
|
|
17
17
|
@cache = cache
|
18
18
|
end
|
19
19
|
|
20
|
+
def lookup_pack_with_chunks!(name, type: nil)
|
21
|
+
manifest_pack_type = manifest_type(name, type)
|
22
|
+
manifest_pack_name = manifest_name(name, manifest_pack_type)
|
23
|
+
find('entrypoints')&.dig(manifest_pack_name, manifest_pack_type) || handle_missing_entry(name)
|
24
|
+
end
|
25
|
+
|
20
26
|
def lookup!(name)
|
21
27
|
find(name) || handle_missing_entry(name)
|
22
28
|
end
|
@@ -56,6 +62,19 @@ module WebpackManifest
|
|
56
62
|
JSON.parse(data)
|
57
63
|
end
|
58
64
|
|
65
|
+
# The `manifest_name` method strips of the file extension of the name, because in the
|
66
|
+
# manifest hash the entrypoints are defined by their pack name without the extension.
|
67
|
+
# When the user provides a name with a file extension, we want to try to strip it off.
|
68
|
+
def manifest_name(name, pack_type)
|
69
|
+
return name if File.extname(name.to_s).empty?
|
70
|
+
File.basename(name, '.' + pack_type)
|
71
|
+
end
|
72
|
+
|
73
|
+
def manifest_type(name, pack_type)
|
74
|
+
return File.extname(name)[1..-1] if pack_type.nil?
|
75
|
+
pack_type.to_s
|
76
|
+
end
|
77
|
+
|
59
78
|
def handle_missing_entry(name)
|
60
79
|
raise MissingEntryError, <<~MSG
|
61
80
|
Can not find #{name} in #{@path}.
|
@@ -23,6 +23,25 @@ module WebpackManifest::Rails::Helper
|
|
23
23
|
javascript_include_tag(*sources_from_manifest(names, 'js', key: manifest), **options)
|
24
24
|
end
|
25
25
|
|
26
|
+
# Creates script tags that references the js chunks from entrypoints when using split chunks API.
|
27
|
+
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
28
|
+
# Example:
|
29
|
+
#
|
30
|
+
# <%= javascript_bundles_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %> # =>
|
31
|
+
# <script src="/packs/vendor-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
32
|
+
# <script src="/packs/calendar~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
33
|
+
# <script src="/packs/calendar-1016838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
34
|
+
# <script src="/packs/map~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
35
|
+
# <script src="/packs/map-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
36
|
+
# DO:
|
37
|
+
# <%= javascript_bundles_with_chunks_tag 'calendar', 'map' %>
|
38
|
+
# DON'T:
|
39
|
+
# <%= javascript_bundles_with_chunks_tag 'calendar' %>
|
40
|
+
# <%= javascript_bundles_with_chunks_tag 'map' %>
|
41
|
+
def javascript_bundles_with_chunks_tag(*names, manifest: nil, **options)
|
42
|
+
javascript_include_tag(*sources_from_manifest_entrypoints(names, 'js', key: manifest), **options)
|
43
|
+
end
|
44
|
+
|
26
45
|
# Examples:
|
27
46
|
#
|
28
47
|
# <%= stylesheet_bundle_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
|
@@ -36,6 +55,23 @@ module WebpackManifest::Rails::Helper
|
|
36
55
|
stylesheet_link_tag(*sources_from_manifest(names, 'css', key: manifest), **options)
|
37
56
|
end
|
38
57
|
|
58
|
+
# Creates link tags that references the css chunks from entrypoints when using split chunks API.
|
59
|
+
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
60
|
+
# Example:
|
61
|
+
#
|
62
|
+
# <%= stylesheet_bundles_with_chunks_tag 'calendar', 'map' %> # =>
|
63
|
+
# <link rel="stylesheet" media="screen" href="/packs/3-8c7ce31a.chunk.css" />
|
64
|
+
# <link rel="stylesheet" media="screen" href="/packs/calendar-8c7ce31a.chunk.css" />
|
65
|
+
# <link rel="stylesheet" media="screen" href="/packs/map-8c7ce31a.chunk.css" />
|
66
|
+
# DO:
|
67
|
+
# <%= stylesheet_bundles_with_chunks_tag 'calendar', 'map' %>
|
68
|
+
# DON'T:
|
69
|
+
# <%= stylesheet_bundles_with_chunks_tag 'calendar' %>
|
70
|
+
# <%= stylesheet_bundles_with_chunks_tag 'map' %>
|
71
|
+
def stylesheet_bundles_with_chunks_tag(*names, manifest: nil, **options)
|
72
|
+
stylesheet_link_tag(*sources_from_manifest_entrypoints(names, 'css', key: manifest), **options)
|
73
|
+
end
|
74
|
+
|
39
75
|
# Examples:
|
40
76
|
#
|
41
77
|
# <%= image_bundle_tag 'icon.png'
|
@@ -55,6 +91,11 @@ module WebpackManifest::Rails::Helper
|
|
55
91
|
names.map { |name| manifest.lookup!(name.to_s + '.' + ext) }
|
56
92
|
end
|
57
93
|
|
94
|
+
def sources_from_manifest_entrypoints(names, type, key: nil)
|
95
|
+
manifest = get_manifest_by_key(key)
|
96
|
+
names.map { |name| manifest.lookup_pack_with_chunks!(name, type: type) }.flatten.uniq
|
97
|
+
end
|
98
|
+
|
58
99
|
def get_manifest_by_key(key = nil)
|
59
100
|
repository = WebpackManifest::Rails.configuration.manifests
|
60
101
|
key.nil? ? repository.default : repository.get(key)
|
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.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nobuhiro Nikushi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-25 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.
|
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
|