From bf1927436c5be7442ab6e2ae73156d02cedb50b0 Mon Sep 17 00:00:00 2001 From: Tim Lucas Date: Sat, 30 Sep 2017 17:00:23 +1000 Subject: [PATCH] Update the hash-statics example to support sub-dirs (#3015) --- examples/with-hashed-statics/.babelrc | 3 ++- examples/with-hashed-statics/README.md | 4 +--- examples/with-hashed-statics/pages/index.js | 4 ++-- .../static/{ => images}/logo.png | Bin .../static/{ => images}/logo.svg | 0 5 files changed, 5 insertions(+), 6 deletions(-) rename examples/with-hashed-statics/static/{ => images}/logo.png (100%) rename examples/with-hashed-statics/static/{ => images}/logo.svg (100%) diff --git a/examples/with-hashed-statics/.babelrc b/examples/with-hashed-statics/.babelrc index a77121ee..6df96763 100644 --- a/examples/with-hashed-statics/.babelrc +++ b/examples/with-hashed-statics/.babelrc @@ -5,7 +5,8 @@ "transform-assets", { "extensions": ["txt", "svg", "png"], - "name": "/static/[name].[ext]?[sha512:hash:base64:7]" + "regExp": ".*/static/(.+)", + "name": "/static/[1]?[sha512:hash:base64:7]" } ] ] diff --git a/examples/with-hashed-statics/README.md b/examples/with-hashed-statics/README.md index 397e9d22..9f3b2c9d 100644 --- a/examples/with-hashed-statics/README.md +++ b/examples/with-hashed-statics/README.md @@ -26,6 +26,4 @@ now This example shows how to import images, videos, etc. from `/static` and get the URL with a hash query allowing to use better cache without problems. -This example supports `.svg`, `.png` and `.txt` extensions, but it can be configured to support any possible extension changing the `extensions` array in the `.babelrc` file. - -We also can modify the filename we're going to get, that filename has `/static` prepended so every file we require using this is going to have the format `/static/[name].[ext]?[hash]`, because of this all the files need to be placed directly inside the `static` directory. +This example supports `.svg`, `.png` and `.txt` extensions, but it can be configured to support any possible extension changing the `extensions` array in the `.babelrc` file. \ No newline at end of file diff --git a/examples/with-hashed-statics/pages/index.js b/examples/with-hashed-statics/pages/index.js index 7c3abb71..9c9f57ae 100644 --- a/examples/with-hashed-statics/pages/index.js +++ b/examples/with-hashed-statics/pages/index.js @@ -1,7 +1,7 @@ // We need to use `require` instead of `import` // They also must be assigned to a variable/constant -const logoSVG = require('../static/logo.svg') -const logoPNG = require('../static/logo.png') +const logoSVG = require('../static/images/logo.svg') +const logoPNG = require('../static/images/logo.png') const txt = require('../static/file.txt') export default () => ( diff --git a/examples/with-hashed-statics/static/logo.png b/examples/with-hashed-statics/static/images/logo.png similarity index 100% rename from examples/with-hashed-statics/static/logo.png rename to examples/with-hashed-statics/static/images/logo.png diff --git a/examples/with-hashed-statics/static/logo.svg b/examples/with-hashed-statics/static/images/logo.svg similarity index 100% rename from examples/with-hashed-statics/static/logo.svg rename to examples/with-hashed-statics/static/images/logo.svg