Created
November 4, 2020 03:10
-
-
Save fluidsonic/b082a89917bdf4fa2bc9c441a2fc0a6c to your computer and use it in GitHub Desktop.
Resource/asset hashing using Webpack in Kotlin React project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// webpack.config.d/assets.js | |
const path = require('path') | |
const resourcesPath = path.resolve('../../../processedResources/js/main') | |
config.module.rules.push({ | |
test: /\.(gif|png|jpe?g|svg|woff2?)$/, | |
use: [{ | |
loader: 'file-loader', | |
options: { | |
esModule: false, | |
name: config.mode === 'development' ? '[name].[ext]' : '[contenthash].[ext]', | |
outputPath: (url, resourcePath) => | |
config.mode === 'development' ? | |
`assets/${path.dirname(path.relative(resourcesPath, resourcePath))}/${url}` : | |
`assets/${url}`, | |
}, | |
}], | |
}) | |
config.resolve.modules.push(resourcesPath) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@JsName("require") | |
external fun asset(path: String): String | |
// in a React builder | |
img(src = asset("image.png")) {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment