Skip to content

Instantly share code, notes, and snippets.

@fluidsonic
Created November 4, 2020 03:10
Show Gist options
  • Save fluidsonic/b082a89917bdf4fa2bc9c441a2fc0a6c to your computer and use it in GitHub Desktop.
Save fluidsonic/b082a89917bdf4fa2bc9c441a2fc0a6c to your computer and use it in GitHub Desktop.
Resource/asset hashing using Webpack in Kotlin React project
// 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)
@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