1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Update the hash-statics example to support sub-dirs (#3015)

This commit is contained in:
Tim Lucas 2017-09-30 17:00:23 +10:00 committed by Tim Neutkens
parent f2f987f02b
commit bf1927436c
5 changed files with 5 additions and 6 deletions

View file

@ -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]"
}
]
]

View file

@ -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.

View file

@ -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 () => (

View file

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

View file

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB