Skip to content

Commit b64434d

Browse files
Using default custom path for files (#3082)
1 parent 52101e8 commit b64434d

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ environment.loaders.append('nodeModules', nodeModules)
1414
```
1515

1616
- If you have added `environment.loaders.delete('nodeModules')` to your `environment.js`, this must be removed or you will receive an error (`Item nodeModules not found`).
17-
- `extract_css` option was removed. Webpacker will generate a separate `application.css` file for the default `application` pack, as supported by multiple files per entry introduced in 5.0.0. [#2608](https://github.com/rails/webpacker/pull/2608). However, CSS will be inlined when the webpack-dev-server is used with `hmr: true`. JS package exports `inliningCss`. This is useful to enable HMR for React.
17+
- `extract_css` option was removed. Webpacker will generate a separate `application.css` file for the default `application` pack, as supported by multiple files per entry introduced in 5.0.0. [#2608](https://github.com/rails/webpacker/pull/2608). However, CSS will be inlined when the webpack-dev-server is used with `hmr: true`. JS package exports `inliningCss`. This is useful to enable HMR for React.
1818
- Webpacker's wrapper to the `splitChunks()` API will now default `runtimeChunk: 'single'` which will help prevent potential issues when using multiple entry points per page [#2708](https://github.com/rails/webpacker/pull/2708).
1919
- Changes `@babel/preset-env` modules option to `'auto'` per recommendation in the Babel docs [#2709](https://github.com/rails/webpacker/pull/2709)
2020
- Adds experimental Yarn 2 support. Note you must manually set `nodeLinker: node-modules` in your `.yarnrc.yml`.
2121
- Fixes dev server issues [#2898](https://github.com/rails/webpacker/pull/2898)
22+
- Update static files path to from `media/` to `static/`.
2223

2324
### Breaking changes
2425
- Removed integration installers

lib/webpacker/helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def sources_from_manifest_entrypoints(names, type:)
153153
end
154154

155155
def resolve_path_to_image(name, **options)
156-
path = name.starts_with?("media/images/") ? name : "media/images/#{name}"
156+
path = name.starts_with?("static/") ? name : "static/#{name}"
157157
path_to_asset(current_webpacker_instance.manifest.lookup!(path), options)
158158
rescue
159159
path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)

package/rules/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ module.exports = {
1818
exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
1919
type: 'asset/resource',
2020
generator: {
21-
filename: 'media/images/[hash][ext][query]'
21+
filename: 'static/[hash][ext][query]'
2222
}
2323
}

test/helper_test.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,57 +26,57 @@ def test_asset_pack_url
2626

2727
def test_image_pack_path
2828
assert_equal "/packs/application-k344a6d59eef8632c9d1.png", image_pack_path("application.png")
29-
assert_equal "/packs/media/images/image-c38deda30895059837cf.jpg", image_pack_path("image.jpg")
30-
assert_equal "/packs/media/images/image-c38deda30895059837cf.jpg", image_pack_path("media/images/image.jpg")
31-
assert_equal "/packs/media/images/nested/image-c38deda30895059837cf.jpg", image_pack_path("nested/image.jpg")
32-
assert_equal "/packs/media/images/nested/image-c38deda30895059837cf.jpg", image_pack_path("media/images/nested/image.jpg")
29+
assert_equal "/packs/static/image-c38deda30895059837cf.jpg", image_pack_path("image.jpg")
30+
assert_equal "/packs/static/image-c38deda30895059837cf.jpg", image_pack_path("static/image.jpg")
31+
assert_equal "/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_path("nested/image.jpg")
32+
assert_equal "/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_path("static/nested/image.jpg")
3333
end
3434

3535
def test_image_pack_url
3636
assert_equal "https://example.com/packs/application-k344a6d59eef8632c9d1.png", image_pack_url("application.png")
37-
assert_equal "https://example.com/packs/media/images/image-c38deda30895059837cf.jpg", image_pack_url("image.jpg")
38-
assert_equal "https://example.com/packs/media/images/image-c38deda30895059837cf.jpg", image_pack_url("media/images/image.jpg")
39-
assert_equal "https://example.com/packs/media/images/nested/image-c38deda30895059837cf.jpg", image_pack_url("nested/image.jpg")
40-
assert_equal "https://example.com/packs/media/images/nested/image-c38deda30895059837cf.jpg", image_pack_url("media/images/nested/image.jpg")
37+
assert_equal "https://example.com/packs/static/image-c38deda30895059837cf.jpg", image_pack_url("image.jpg")
38+
assert_equal "https://example.com/packs/static/image-c38deda30895059837cf.jpg", image_pack_url("static/image.jpg")
39+
assert_equal "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_url("nested/image.jpg")
40+
assert_equal "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_url("static/nested/image.jpg")
4141
end
4242

4343
def test_image_pack_tag
4444
assert_equal \
4545
"<img alt=\"Edit Entry\" src=\"/packs/application-k344a6d59eef8632c9d1.png\" width=\"16\" height=\"10\" />",
4646
image_pack_tag("application.png", size: "16x10", alt: "Edit Entry")
4747
assert_equal \
48-
"<img alt=\"Edit Entry\" src=\"/packs/media/images/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
48+
"<img alt=\"Edit Entry\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
4949
image_pack_tag("image.jpg", size: "16x10", alt: "Edit Entry")
5050
assert_equal \
51-
"<img alt=\"Edit Entry\" src=\"/packs/media/images/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
52-
image_pack_tag("media/images/image.jpg", size: "16x10", alt: "Edit Entry")
51+
"<img alt=\"Edit Entry\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
52+
image_pack_tag("static/image.jpg", size: "16x10", alt: "Edit Entry")
5353
assert_equal \
54-
"<img alt=\"Edit Entry\" src=\"/packs/media/images/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
54+
"<img alt=\"Edit Entry\" src=\"/packs/static/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
5555
image_pack_tag("nested/image.jpg", size: "16x10", alt: "Edit Entry")
5656
assert_equal \
57-
"<img alt=\"Edit Entry\" src=\"/packs/media/images/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
58-
image_pack_tag("media/images/nested/image.jpg", size: "16x10", alt: "Edit Entry")
57+
"<img alt=\"Edit Entry\" src=\"/packs/static/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
58+
image_pack_tag("static/nested/image.jpg", size: "16x10", alt: "Edit Entry")
5959
assert_equal \
60-
"<img srcset=\"/packs/media/images/image-2x-7cca48e6cae66ec07b8e.jpg 2x\" src=\"/packs/media/images/image-c38deda30895059837cf.jpg\" />",
61-
image_pack_tag("media/images/image.jpg", srcset: { "media/images/image-2x.jpg" => "2x" })
60+
"<img srcset=\"/packs/static/image-2x-7cca48e6cae66ec07b8e.jpg 2x\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" />",
61+
image_pack_tag("static/image.jpg", srcset: { "static/image-2x.jpg" => "2x" })
6262
end
6363

6464
def test_favicon_pack_tag
6565
assert_equal \
6666
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/application-k344a6d59eef8632c9d1.png\" />",
6767
favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png")
6868
assert_equal \
69-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/mb-icon-c38deda30895059837cf.png\" />",
69+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />",
7070
favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png")
7171
assert_equal \
72-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/mb-icon-c38deda30895059837cf.png\" />",
73-
favicon_pack_tag("media/images/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
72+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />",
73+
favicon_pack_tag("static/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
7474
assert_equal \
75-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/nested/mb-icon-c38deda30895059837cf.png\" />",
75+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/nested/mb-icon-c38deda30895059837cf.png\" />",
7676
favicon_pack_tag("nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
7777
assert_equal \
78-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/nested/mb-icon-c38deda30895059837cf.png\" />",
79-
favicon_pack_tag("media/images/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
78+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/nested/mb-icon-c38deda30895059837cf.png\" />",
79+
favicon_pack_tag("static/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
8080
end
8181

8282
def test_preload_pack_asset

test/test_app/public/packs/manifest.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"application.js": "/packs/application-k344a6d59eef8632c9d1.js",
66
"application.png": "/packs/application-k344a6d59eef8632c9d1.png",
77
"fonts/fa-regular-400.woff2": "/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2",
8-
"media/images/image.jpg": "/packs/media/images/image-c38deda30895059837cf.jpg",
9-
"media/images/image-2x.jpg": "/packs/media/images/image-2x-7cca48e6cae66ec07b8e.jpg",
10-
"media/images/nested/image.jpg": "/packs/media/images/nested/image-c38deda30895059837cf.jpg",
11-
"media/images/mb-icon.png": "/packs/media/images/mb-icon-c38deda30895059837cf.png",
12-
"media/images/nested/mb-icon.png": "/packs/media/images/nested/mb-icon-c38deda30895059837cf.png",
8+
"static/image.jpg": "/packs/static/image-c38deda30895059837cf.jpg",
9+
"static/image-2x.jpg": "/packs/static/image-2x-7cca48e6cae66ec07b8e.jpg",
10+
"static/nested/image.jpg": "/packs/static/nested/image-c38deda30895059837cf.jpg",
11+
"static/mb-icon.png": "/packs/static/mb-icon-c38deda30895059837cf.png",
12+
"static/nested/mb-icon.png": "/packs/static/nested/mb-icon-c38deda30895059837cf.png",
1313
"entrypoints": {
1414
"application": {
1515
"assets": {

0 commit comments

Comments
 (0)