asset_mapper 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +44 -39
- data/README.md +174 -23
- data/Rakefile +1 -1
- data/asset_mapper.gemspec +6 -6
- data/bin/setup +25 -0
- data/docs/parcel2.md +137 -0
- data/lib/asset_mapper/configuration.rb +67 -0
- data/lib/asset_mapper/manifest.rb +74 -0
- data/lib/asset_mapper/manifest_generator.rb +65 -0
- data/lib/asset_mapper/version.rb +1 -1
- data/lib/asset_mapper.rb +12 -22
- data/packages/asset-mapper-esbuild/CHANGELOG.md +12 -0
- data/packages/asset-mapper-esbuild/esbuild.config.js +37 -0
- data/packages/asset-mapper-esbuild/package.json +41 -0
- data/packages/asset-mapper-esbuild/pnpm-lock.yaml +1506 -0
- data/packages/asset-mapper-esbuild/src/index.js +184 -0
- data/packages/asset-mapper-esbuild/tsconfig-cjs.json +7 -0
- data/packages/asset-mapper-esbuild/tsconfig.json +29 -0
- data/packages/asset-mapper-esbuild/yarn.lock +146 -0
- data/yarn.lock +4 -0
- metadata +24 -12
- data/lib/asset_mapper/types.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70001032fe042a996e8cd5be6001be5c578328b9284b299e86d6ba1514e1a068
|
4
|
+
data.tar.gz: d81ac7eb6cdb92334b11e8033304d1404919ce7c460e4d27e2c05c460dc3f439
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79c421afd329f21c8eb68636fd4379eee07d0c80b162308dca9171b3cb53de135909937d1278758ff4eee94178408b924814667ccedd17cab9429a55cf8aaa49
|
7
|
+
data.tar.gz: 8cd97df7a9501aa77a12c29e9f01037e198550416d6b0416d04bbccb6176182f105a9aece09f98566d0e5f2b56a89934e5da36c9b849f85bf43b860d13afc572
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
asset_mapper (0.0
|
5
|
-
dry-configurable (~>
|
6
|
-
dry-files (~>
|
4
|
+
asset_mapper (1.0.0)
|
5
|
+
dry-configurable (~> 1.0)
|
6
|
+
dry-files (~> 1.0)
|
7
7
|
dry-initializer (~> 3.0)
|
8
8
|
dry-types (~> 1.5)
|
9
9
|
rake (>= 10)
|
@@ -13,58 +13,63 @@ GEM
|
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
15
|
ast (2.4.2)
|
16
|
-
concurrent-ruby (1.1.
|
17
|
-
dry-configurable (0.
|
16
|
+
concurrent-ruby (1.1.10)
|
17
|
+
dry-configurable (1.0.1)
|
18
|
+
dry-core (~> 1.0, < 2)
|
19
|
+
zeitwerk (~> 2.6)
|
20
|
+
dry-core (1.0.0)
|
18
21
|
concurrent-ruby (~> 1.0)
|
19
|
-
|
20
|
-
dry-
|
22
|
+
zeitwerk (~> 2.6)
|
23
|
+
dry-files (1.0.1)
|
24
|
+
dry-inflector (1.0.0)
|
25
|
+
dry-initializer (3.1.1)
|
26
|
+
dry-logic (1.5.0)
|
21
27
|
concurrent-ruby (~> 1.0)
|
22
|
-
dry-
|
23
|
-
|
28
|
+
dry-core (~> 1.0, < 2)
|
29
|
+
zeitwerk (~> 2.6)
|
30
|
+
dry-types (1.7.0)
|
24
31
|
concurrent-ruby (~> 1.0)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
dry-core (~> 0.5, >= 0.5)
|
35
|
-
dry-inflector (~> 0.1, >= 0.1.2)
|
36
|
-
dry-logic (~> 1.0, >= 1.0.2)
|
37
|
-
minitest (5.14.4)
|
38
|
-
parallel (1.21.0)
|
39
|
-
parser (3.0.2.0)
|
32
|
+
dry-core (~> 1.0, < 2)
|
33
|
+
dry-inflector (~> 1.0, < 2)
|
34
|
+
dry-logic (>= 1.4, < 2)
|
35
|
+
zeitwerk (~> 2.6)
|
36
|
+
json (2.6.3)
|
37
|
+
language_server-protocol (3.17.0.2)
|
38
|
+
minitest (5.16.3)
|
39
|
+
parallel (1.22.1)
|
40
|
+
parser (3.1.3.0)
|
40
41
|
ast (~> 2.4.1)
|
41
|
-
rainbow (3.
|
42
|
+
rainbow (3.1.1)
|
42
43
|
rake (13.0.6)
|
43
|
-
regexp_parser (2.
|
44
|
+
regexp_parser (2.6.1)
|
44
45
|
rexml (3.2.5)
|
45
|
-
rubocop (1.
|
46
|
+
rubocop (1.39.0)
|
47
|
+
json (~> 2.3)
|
46
48
|
parallel (~> 1.10)
|
47
|
-
parser (>= 3.
|
49
|
+
parser (>= 3.1.2.1)
|
48
50
|
rainbow (>= 2.2.2, < 4.0)
|
49
51
|
regexp_parser (>= 1.8, < 3.0)
|
50
|
-
rexml
|
51
|
-
rubocop-ast (>= 1.
|
52
|
+
rexml (>= 3.2.5, < 4.0)
|
53
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
52
54
|
ruby-progressbar (~> 1.7)
|
53
55
|
unicode-display_width (>= 1.4.0, < 3.0)
|
54
|
-
rubocop-ast (1.
|
55
|
-
parser (>= 3.
|
56
|
-
rubocop-performance (1.
|
56
|
+
rubocop-ast (1.24.0)
|
57
|
+
parser (>= 3.1.1.0)
|
58
|
+
rubocop-performance (1.15.1)
|
57
59
|
rubocop (>= 1.7.0, < 2.0)
|
58
60
|
rubocop-ast (>= 0.4.0)
|
59
61
|
ruby-progressbar (1.11.0)
|
60
|
-
standard (1.
|
61
|
-
|
62
|
-
rubocop
|
63
|
-
|
64
|
-
|
62
|
+
standard (1.19.1)
|
63
|
+
language_server-protocol (~> 3.17.0.2)
|
64
|
+
rubocop (= 1.39.0)
|
65
|
+
rubocop-performance (= 1.15.1)
|
66
|
+
unicode-display_width (2.3.0)
|
67
|
+
zeitwerk (2.6.6)
|
65
68
|
|
66
69
|
PLATFORMS
|
70
|
+
arm64-darwin-21
|
67
71
|
x86_64-darwin-20
|
72
|
+
x86_64-linux
|
68
73
|
|
69
74
|
DEPENDENCIES
|
70
75
|
asset_mapper!
|
@@ -73,4 +78,4 @@ DEPENDENCIES
|
|
73
78
|
standard (~> 1.3)
|
74
79
|
|
75
80
|
BUNDLED WITH
|
76
|
-
2.
|
81
|
+
2.3.5
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ bridge between frontend and backend.
|
|
20
20
|
|
21
21
|
## How does AssetMapper work?
|
22
22
|
|
23
|
-
AssetMapper expects to be given a path to a JSON file that
|
23
|
+
AssetMapper expects to be given a path to a JSON file(s) that
|
24
24
|
is in a specific schema. To generate these schemas,
|
25
25
|
generally a plugin needs to be made for your bundler of
|
26
26
|
choice that complies with the AssetMapper schema. Then, for
|
@@ -39,49 +39,200 @@ more than I would like it to. It does things like:
|
|
39
39
|
|
40
40
|
## Roadmap
|
41
41
|
|
42
|
-
- [ ] - Create a
|
43
|
-
|
44
|
-
- [
|
45
|
-
- [ ] - Create a
|
46
|
-
- [ ] - Create a
|
42
|
+
- [ ] - Create a file hasher for bundle-less setups.
|
43
|
+
- [ ] - Create a file watcher for development to auto-update the manifest.
|
44
|
+
- [x] - Create a plugin for ESBuild.
|
45
|
+
- [ ] - Create a plugin for Parcel 2.
|
46
|
+
- [ ] - Create a plugin for Vite.
|
47
|
+
- [ ] - Create a pluggable DevServer thats Rack compatible that can be injected as middleware.
|
48
|
+
- [ ] - Create Rails view helpers.
|
47
49
|
|
48
50
|
## For Developers
|
49
51
|
|
50
52
|
If you're interested in making a plugin for a bundler that is AssetMapper compatible
|
51
53
|
here is the JSON schema expected:
|
52
54
|
|
55
|
+
### Schema
|
56
|
+
|
53
57
|
```json
|
54
58
|
{
|
55
|
-
"
|
56
|
-
"
|
57
|
-
|
58
|
-
|
59
|
+
"<unhashed-path>": {
|
60
|
+
"asset_path": "<shortened-hashed-path>"
|
61
|
+
"file_path": "<full-hashed-path>"
|
62
|
+
}
|
59
63
|
}
|
60
64
|
```
|
61
65
|
|
62
66
|
## Programmatic Usage
|
63
67
|
|
64
68
|
```rb
|
65
|
-
AssetMapper
|
66
|
-
|
67
|
-
|
68
|
-
config.
|
69
|
+
# Create an AssetMapper::Configuration instance
|
70
|
+
asset_mapper = AssetMapper.new.configure do |config|
|
71
|
+
# Where the manifest files can be found on the host machine
|
72
|
+
config.manifest_files = ["public/builds/asset-mapper-manifest.json"]
|
73
|
+
|
74
|
+
# The URL or path prefix for the files.
|
75
|
+
config.asset_host = "/builds"
|
76
|
+
|
77
|
+
# Do not cache the manifest in testing or in development.
|
78
|
+
config.cache_manifest = !(Rails.env.development? || Rails.env.testing?)
|
69
79
|
end
|
70
80
|
|
71
|
-
manifest =
|
81
|
+
manifest = asset_mapper.manifest
|
72
82
|
# =>
|
73
83
|
# {
|
74
|
-
# "
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
84
|
+
# "files": {
|
85
|
+
# "entrypoints/application.js" => {
|
86
|
+
# "asset_path" => "entrypoints/application-[hash].js",
|
87
|
+
# "file_path" => "public/assets/entrypoints/application-[hash].js",
|
88
|
+
# }
|
89
|
+
# }
|
78
90
|
# }
|
79
91
|
|
80
|
-
manifest.
|
81
|
-
# => "
|
92
|
+
manifest.find("entrypoints/application.js")
|
93
|
+
# => "/builds/entrypoints/application-[hash].js"
|
94
|
+
|
95
|
+
manifest.find("assets/icon.svg")
|
96
|
+
# => "/builds/assets/icon-[hash].svg"
|
97
|
+
```
|
98
|
+
|
99
|
+
## Supported bundlers
|
100
|
+
|
101
|
+
- [x] [ESBuild](/docs/esbuild)
|
102
|
+
- [ ] [Parcel 2](/docs/parcel2)
|
103
|
+
- [ ] [Rollup](/docs/rollup)
|
104
|
+
- [ ] [Vite](/docs/vite/)
|
105
|
+
|
106
|
+
## Rails usage
|
107
|
+
|
108
|
+
Create an initializer to initialize AssetMapper at `config/initializers/asset_mapper.rb`.
|
109
|
+
|
110
|
+
```rb
|
111
|
+
# config/initializers/asset_mapper.rb
|
112
|
+
|
113
|
+
asset_mapper = AssetMapper.new.configure do |config|
|
114
|
+
# Where the manifest files can be found on the host machine
|
115
|
+
config.manifest_files = ["public/esbuild-builds/asset-mapper-manifest.json"]
|
116
|
+
|
117
|
+
# prepends "/builds" to all URLs
|
118
|
+
config.asset_host = "/builds"
|
119
|
+
|
120
|
+
# Do not cache the manifest in testing or in development.
|
121
|
+
config.cache_manifest = !(Rails.env.development? || Rails.env.testing?)
|
122
|
+
end
|
123
|
+
|
124
|
+
Rails.application.config.asset_mapper = asset_mapper
|
125
|
+
```
|
126
|
+
|
127
|
+
AssetMapper is now available under: `Rails.application.config.asset_mapper`. This is pretty
|
128
|
+
verbose to use in your views you can create a helper for it.
|
129
|
+
|
130
|
+
### Usage in Rails views
|
131
|
+
|
132
|
+
```rb
|
133
|
+
# app/helpers/application_helper.rb
|
134
|
+
module ApplicationHelper
|
135
|
+
def asset_mapper
|
136
|
+
Rails.application.config.asset_mapper
|
137
|
+
end
|
138
|
+
end
|
139
|
+
```
|
140
|
+
|
141
|
+
## Hanami setup
|
142
|
+
|
143
|
+
The first step is to create a "provider" for asset_mapper.
|
144
|
+
|
145
|
+
```rb
|
146
|
+
# config/providers/asset_mapper.rb
|
147
|
+
|
148
|
+
Hanami.app.register_provider(:asset_mapper) do
|
149
|
+
prepare do
|
150
|
+
require "asset_mapper"
|
151
|
+
end
|
152
|
+
|
153
|
+
start do
|
154
|
+
files = Dry::Files.new
|
155
|
+
asset_mapper = AssetMapper.new.configure do |config|
|
156
|
+
# The URL or path prefix for the files.
|
157
|
+
config.asset_host = "/assets"
|
158
|
+
|
159
|
+
# Do not cache the manifest in testing or in development, only production.
|
160
|
+
config.cache_manifest = Hanami.env?(:production)
|
161
|
+
|
162
|
+
# Files to watch
|
163
|
+
config.asset_files = ["app/assets/media/**/*.*"]
|
164
|
+
|
165
|
+
# Where to dump the assets
|
166
|
+
config.assets_output_path = files.join("public/assets")
|
167
|
+
|
168
|
+
# Where to write the manifest to.
|
169
|
+
config.manifest_output_path = files.join(config.assets_output_path, "asset-mapper-manifest.json")
|
170
|
+
|
171
|
+
# top level directory of assets. Used for relative short paths.
|
172
|
+
config.assets_root = files.join("app/assets")
|
173
|
+
|
174
|
+
# Where the manifest files can be found on the host machine
|
175
|
+
config.manifest_files = [
|
176
|
+
"public/assets/esbuild-manifest.json",
|
177
|
+
config.manifest_output_path
|
178
|
+
]
|
179
|
+
end
|
180
|
+
|
181
|
+
register "asset_mapper", asset_mapper
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
```
|
186
|
+
|
187
|
+
### Add a static rack server
|
188
|
+
|
189
|
+
Next, we need to add a setting to `./config.ru` for when we write to the `public/` folder.
|
190
|
+
|
191
|
+
```rb
|
192
|
+
# config.ru
|
193
|
+
|
194
|
+
require "hanami/boot"
|
195
|
+
|
196
|
+
run Hanami.app
|
197
|
+
|
198
|
+
#### Everything above here is provided by default
|
199
|
+
|
200
|
+
#### Add the below call
|
201
|
+
use Rack::Static, :urls => [""], :root => "public", cascade: true
|
202
|
+
```
|
203
|
+
|
204
|
+
Finally, to use in your views, do the following:
|
205
|
+
|
206
|
+
```rb
|
207
|
+
# app/context.rb
|
208
|
+
module Main # <- Replace this with your slice or application name
|
209
|
+
class Context < Hanami::View::Context
|
210
|
+
include Deps["asset_mapper"]
|
211
|
+
|
212
|
+
def asset_path(asset_name)
|
213
|
+
asset_mapper.find(asset_name)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# app/view.rb
|
219
|
+
module Main # <- Replace this with your slice or application name
|
220
|
+
class View < Hanami::View
|
221
|
+
config.default_context = Context.new
|
222
|
+
end
|
223
|
+
end
|
82
224
|
|
83
|
-
|
84
|
-
#
|
225
|
+
```erb
|
226
|
+
# app/views/application.erb
|
227
|
+
<html>
|
228
|
+
<head>
|
229
|
+
<title>Bookshelf</title>
|
230
|
+
<script src="<%= asset_path("javascript/entrypoints/application.js") %>" type="module">
|
231
|
+
</head>
|
232
|
+
<body>
|
233
|
+
<%= yield %>
|
234
|
+
</body>
|
235
|
+
</html>
|
85
236
|
```
|
86
237
|
|
87
238
|
## Development
|
data/Rakefile
CHANGED
data/asset_mapper.gemspec
CHANGED
@@ -5,19 +5,19 @@ require_relative "lib/asset_mapper/version"
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "asset_mapper"
|
7
7
|
spec.version = AssetMapper::VERSION
|
8
|
-
spec.authors = ["
|
8
|
+
spec.authors = ["KonnorRogers"]
|
9
9
|
spec.email = ["konnor5456@gmail.com"]
|
10
10
|
|
11
11
|
spec.summary = "A tightly scoped directory parser and json file generator. "
|
12
|
-
spec.homepage = "https://github.com/
|
12
|
+
spec.homepage = "https://github.com/KonnorRogers/asset_mapper"
|
13
13
|
spec.license = "MIT"
|
14
14
|
spec.required_ruby_version = ">= 2.6.0"
|
15
15
|
|
16
16
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
17
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
-
spec.metadata["source_code_uri"] = "https://github.com/
|
20
|
-
spec.metadata["changelog_uri"] = "https://github.com/
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/KonnorRogers/asset_mapper"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/KonnorRogers/asset_mapper/blob/main/CHANGELOG.md"
|
21
21
|
|
22
22
|
# Specify which files should be added to the gem when it is released.
|
23
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -32,8 +32,8 @@ Gem::Specification.new do |spec|
|
|
32
32
|
|
33
33
|
spec.add_runtime_dependency "rake", ">= 10"
|
34
34
|
spec.add_runtime_dependency "zeitwerk", "~> 2.5"
|
35
|
-
spec.add_runtime_dependency "dry-configurable", "~>
|
36
|
-
spec.add_runtime_dependency "dry-files", "~>
|
35
|
+
spec.add_runtime_dependency "dry-configurable", "~> 1.0"
|
36
|
+
spec.add_runtime_dependency "dry-files", "~> 1.0"
|
37
37
|
spec.add_runtime_dependency "dry-initializer", "~> 3.0"
|
38
38
|
spec.add_runtime_dependency "dry-types", "~> 1.5"
|
39
39
|
end
|
data/bin/setup
CHANGED
@@ -6,3 +6,28 @@ set -vx
|
|
6
6
|
bundle install
|
7
7
|
|
8
8
|
# Do any other automated setup that you need to do here
|
9
|
+
|
10
|
+
# ESbuild plugin setup
|
11
|
+
cd packages/asset-mapper-esbuild
|
12
|
+
npx pnpm install
|
13
|
+
npx pnpm build
|
14
|
+
|
15
|
+
cd -
|
16
|
+
|
17
|
+
# Rails setup
|
18
|
+
cd test/rails/asset-mapper-app
|
19
|
+
bundle install
|
20
|
+
yarn install
|
21
|
+
yarn run build
|
22
|
+
|
23
|
+
cd -
|
24
|
+
|
25
|
+
# Hanami setup
|
26
|
+
cd test/hanami
|
27
|
+
bundle install
|
28
|
+
yarn install
|
29
|
+
yarn run build
|
30
|
+
|
31
|
+
cd -
|
32
|
+
|
33
|
+
echo "Setup complete. Checkout 'test/rails/asset-mapper-app' or 'test/hanami for more!'"
|
data/docs/parcel2.md
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
# Parcel 2
|
2
|
+
|
3
|
+
To get started with Parcel 2, if you haven't already, create a `package.json`.
|
4
|
+
|
5
|
+
```bash
|
6
|
+
yarn init
|
7
|
+
```
|
8
|
+
|
9
|
+
In our `package.json`, lets add a `build` command as well
|
10
|
+
as specify our `"sources"`.
|
11
|
+
|
12
|
+
```json
|
13
|
+
// package.json
|
14
|
+
{
|
15
|
+
"targets": {
|
16
|
+
"default": {
|
17
|
+
"source": "app/javascript/entrypoints",
|
18
|
+
"isLibrary": false,
|
19
|
+
"distDir": "./public/parcels"
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"scripts": {
|
23
|
+
"watch": "parcel watch",
|
24
|
+
"build": "parcel build"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
```
|
28
|
+
|
29
|
+
This means all of our "entrypoints" should be located under
|
30
|
+
`app/javascript/entrypoints`
|
31
|
+
|
32
|
+
For example, you may have a
|
33
|
+
`app/javascript/entrypoints/application.js`
|
34
|
+
|
35
|
+
This file will be the file that is referenced when using a
|
36
|
+
`<script>` tag.
|
37
|
+
|
38
|
+
Next, we need to install the proper node dependencies.
|
39
|
+
|
40
|
+
```bash
|
41
|
+
yarn add -D parcel @parcel/config-default parcel-reporter-bundle-manifest
|
42
|
+
```
|
43
|
+
|
44
|
+
Then, create a `.parcelrc` file in the root of your
|
45
|
+
project.
|
46
|
+
|
47
|
+
```bash
|
48
|
+
touch .parcelrc
|
49
|
+
```
|
50
|
+
|
51
|
+
And then add the following contents:
|
52
|
+
|
53
|
+
```json
|
54
|
+
{
|
55
|
+
"extends": "@parcel/config-default",
|
56
|
+
"reporters": ["...", "parcel-reporter-bundle-manifest"]
|
57
|
+
}
|
58
|
+
```
|
59
|
+
|
60
|
+
## Setting up the server.
|
61
|
+
|
62
|
+
If you're using Rails, create a file called `asset_mapper.rb` in
|
63
|
+
your `config/initializers` folder. If you're not using
|
64
|
+
Rails, in whatever file initializes your app, add the
|
65
|
+
following code:
|
66
|
+
|
67
|
+
```rb
|
68
|
+
// config/initializers/asset_mapper.rb
|
69
|
+
|
70
|
+
AssetMapper.configure do |config|
|
71
|
+
# Prefix before all file paths
|
72
|
+
config.asset_host = "/"
|
73
|
+
|
74
|
+
# Where to find your manifest files. (Most people have only 1)
|
75
|
+
config.manifest_files = %w[public/parcels/parcel-manifest.json]
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
## Adding to our HTML
|
80
|
+
|
81
|
+
To add your script and stylesheet tags to your build, you
|
82
|
+
can do the following:
|
83
|
+
|
84
|
+
```erb
|
85
|
+
<link href="<%= AssetMapper.find('entrypoints/application.css') %>" rel="stylesheet">
|
86
|
+
<script src="<%= AssetMapper.find('entrypoints/application.js') %>" type="module">
|
87
|
+
```
|
88
|
+
|
89
|
+
## Additional Optimizations
|
90
|
+
|
91
|
+
### Compression
|
92
|
+
|
93
|
+
First, install the compression plugins:
|
94
|
+
|
95
|
+
```bash
|
96
|
+
yarn add -D @parcel/compressor-gzip @parcel/compressor-brotli
|
97
|
+
```
|
98
|
+
|
99
|
+
If you would like to add gzipping / brotli compression,
|
100
|
+
make your `.parcelrc` look like the following:
|
101
|
+
|
102
|
+
```json
|
103
|
+
{
|
104
|
+
"extends": "@parcel/config-default",
|
105
|
+
"reporters": ["...", "parcel-reporter-bundle-manifest"]
|
106
|
+
"compressors": {
|
107
|
+
"*.{html,css,js,svg,map}": [
|
108
|
+
"...",
|
109
|
+
"@parcel/compressor-gzip",
|
110
|
+
"@parcel/compressor-brotli"
|
111
|
+
]
|
112
|
+
}
|
113
|
+
}
|
114
|
+
```
|
115
|
+
|
116
|
+
This will gzip / brotli compress any .html, .css, .js, .svg,
|
117
|
+
and .map files so that your web server doesn't have to.
|
118
|
+
|
119
|
+
### Specifying a build target
|
120
|
+
|
121
|
+
Build targets are a way of specifying "what version of
|
122
|
+
javascript to ship", IE: ES6, ES2018, ESNext, etc.
|
123
|
+
|
124
|
+
Parcel has a whole section dedicated to [specifying targets]()
|
125
|
+
|
126
|
+
The easiest to set in your `package.json` is the following:
|
127
|
+
|
128
|
+
```json
|
129
|
+
// package.json
|
130
|
+
{
|
131
|
+
"browserslist": "> 0.5%, last 2 versions, not dead"
|
132
|
+
}
|
133
|
+
```
|
134
|
+
|
135
|
+
### Usage with static files
|
136
|
+
|
137
|
+
https://www.npmjs.com/package/parcel-reporter-multiple-static-file-copier
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "dry/configurable"
|
2
|
+
require "forwardable"
|
3
|
+
require "digest"
|
4
|
+
|
5
|
+
module AssetMapper
|
6
|
+
# Configuration object for asset mapper. This is the top level API.
|
7
|
+
class Configuration
|
8
|
+
extend ::Forwardable
|
9
|
+
include ::Dry::Configurable
|
10
|
+
|
11
|
+
# Where to find the json mapping of your asset files.
|
12
|
+
# @return [String[]]
|
13
|
+
setting :manifest_files, default: []
|
14
|
+
|
15
|
+
# In case you server off of a CDN, you may want to prepend urls.
|
16
|
+
setting :asset_host, default: "/"
|
17
|
+
|
18
|
+
# Whether or not to cache the manifest.
|
19
|
+
# @return [Boolean]
|
20
|
+
setting :cache_manifest, constructor: lambda { |value| !!value }
|
21
|
+
|
22
|
+
# Raise an error if the file can't be found. Useful in development.
|
23
|
+
# @return [Boolean]
|
24
|
+
setting :raise_on_missing_file, default: false
|
25
|
+
|
26
|
+
# Raise an error if the same key is found twice across the same or multiple manifests.
|
27
|
+
# @return [Boolean]
|
28
|
+
setting :raise_on_duplicate_key, default: false
|
29
|
+
|
30
|
+
# Files for AssetMapper to watch for changes and generate hashes for.
|
31
|
+
# Accepts glob patterns like Dir["*"].
|
32
|
+
# @return [Array<String>]
|
33
|
+
setting :asset_files, default: []
|
34
|
+
|
35
|
+
# Override the default file watcher.
|
36
|
+
setting :file_watcher
|
37
|
+
|
38
|
+
# Append hashes to the end of files.
|
39
|
+
setting :fingerprint, default: true
|
40
|
+
|
41
|
+
# Use MD5 hashes. They're fast, and don't need to be secure.
|
42
|
+
setting :fingerprint_method, default: lambda { |str| Digest::MD5.hexdigest(str) }
|
43
|
+
|
44
|
+
# root of your assets, used for short paths.
|
45
|
+
setting :assets_root
|
46
|
+
|
47
|
+
# Where to dump the assets
|
48
|
+
setting :assets_output_path
|
49
|
+
|
50
|
+
# Where to write the manifest to.
|
51
|
+
setting :manifest_output_path
|
52
|
+
|
53
|
+
def_delegators :manifest, :find
|
54
|
+
|
55
|
+
# Returns an instance of the manifest.
|
56
|
+
# @return [AssetMapper::Manifest]
|
57
|
+
def manifest
|
58
|
+
@manifest ||= Manifest.new(config)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns an instance of a manifest generator. This is for files that are watched by asset_mapper.
|
62
|
+
# @return [AssetMapper::ManifestGenerator]
|
63
|
+
def manifest_generator
|
64
|
+
@manifest_generator ||= ManifestGenerator.new(config)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|