Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
elm-assets-loader
Advanced tools
webpack loader for webpackifying asset references in Elm.
$ npm install --save elm-assets-loader
elm-assets-loader is intended to be chained after elm-webpack-loader, and with a loader to load static assets like file-loader or url-loader.
Suppose we have a union type for tagging asset paths:
module My.Assets exposing (AssetPath(..))
type AssetPath
= AssetPath String
star =
AssetPath "star.png"
Tell elm-assets-loader to look for strings tagged with AssetPath
:
loaders: [
{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
loaders: [
'elm-assets?module=My.Assets&tagger=AssetPath',
'elm-webpack'
]
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'file',
query: {
name: '[name]-[hash].[ext]'
}
}
]
Then at runtime, the value of My.Assets.star
will be something like
AssetPath "star-038a1253d7a9e4682deb72cd68c3a328.png"
.
"AssetPath"
<tagger> String
that's used to tag asset paths in your code."My.Assets"
"NoRedInk/myapp"
Default: "warn"
Possible values: "error"
| "warn"
| "ok"
What to do with dynamically constructed asset paths.
Dynamic requires is not supported. This option simply controls whether or not to raise an error or skip over expressions like:
example iconName =
AssetPath ("icon-" ++ iconName ++ ".png")
Function to transform tagged strings to a path that can be resolved by webpack. For example, you may want to tag URL paths, which may not be resolvable to a filesystem path, so that your code works without being webpacked.
star = AssetPath "/public/images/star.png"
img [ src (toUrl star) ] []
webpack config:
module.exports = {
...
elmAssetsLoader: {
localPath: function(url) {
// transform `url` to a local path that resolves to a file
return url.replace(/^\/public\//, "")
}
},
fileLoader: {
publicPath: function(path) {
// transform `path` to a URL that the web server can understand and serve
return "/public/" + url;
}
}
}
"elmAssetsLoader"
Don't set noParse on .elm files. Otherwise, require
s won't be processed.
Let's walk through what happens to the example above when processed by webpack.
This Elm code:
AssetPath "star.png"
will be compiled to JavaScript by elm-webpack-loader:
_user$project$My_Assets$AssetPath("star.png")
elm-assets-loader turns this into:
_user$project$My_Assets$AssetPath(require("star.png"))
webpack parses this require
call, determines it to be a file-loader module, resulting in:
_user$project$My_Assets$AssetPath(__webpack_require__(30))
The module loaded by __webpack_require__(30)
will look like:
30:
function(module, exports) {
module.exports = "star-038a1253d7a9e4682deb72cd68c3a328.png";
}
FAQs
webpack loader for webpackifying asset references in Elm code
The npm package elm-assets-loader receives a total of 20 weekly downloads. As such, elm-assets-loader popularity was classified as not popular.
We found that elm-assets-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.