Installations
npm install rollup-plugin-smart-asset
Score
55.6
Supply Chain
99.1
Quality
75.7
Maintenance
100
Vulnerability
99.6
License
Developer
sormy
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
14.7.0
NPM Version
6.14.7
Statistics
34 Stars
52 Commits
12 Forks
1 Watching
10 Branches
4 Contributors
Updated on 28 Oct 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
5,486,739
Last day
-22.2%
2,930
Compared to previous day
Last week
-3.3%
19,433
Compared to previous week
Last month
5.2%
85,385
Compared to previous month
Last year
-21.2%
1,116,614
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
5
Peer Dependencies
1
Rollup Smart Asset Plugin
Overview
Rollup plugin to rebase, inline or copy assets referenced from the JavaScript code.
Usage
1import smartAsset from "rollup-plugin-smart-asset" 2 3const smartAssetOpts = { ... } 4 5export default { 6 input: "src/index.tsx", 7 output: { 8 file: "dist/index.js", 9 format: "iife" 10 }, 11 plugins: [ 12 ... 13 smartAsset(smartAssetOpts) 14 ... 15 ] 16}
Configuration
For libraries it is recommended to use inline
or copy
mode with keepImport
option to delegate bundling to consumer's package bundler. Asset hashing is not
needed for this case and it is safe to set useHash: false
and keepName: true
.
For applications it is also recommended to use inline
or copy
mode with
enabled by default hashing.
Default settings are set to be the same as in postcss-smart-asset
to have one
config for both of them.
Main options:
url
: Mode:rebase
(default),inline
andcopy
extensions
: What file extensions to process, defaults to[".svg", ".gif", ".png", ".jpg"]
unlessexclude
orinclude
are used. This option is ignored ifinclude
orexclude
options are used.include
: Micromatch pattern or array of micromatch patterns for files that need to be processed by this plugin.exclude
: Micromatch pattern or array of micromatch patterns for files that NOT need to be processed by this plugin.emitFiles
: Disable generating files iffalse
, by default it'strue
- useful when generating bundle for SSR.
For more details about include
/ exclude
syntax please refer to:
https://github.com/micromatch/micromatch
Mode: rebase
Rebase asset references to be relative to specific directory.
Output:
1// without keepImport (inside wrapper) 2export default "public_path_to_asset" 3 4// with keepImport and cjs module format 5const myAsset = require("relative_path_to_asset_from_bundle") 6 7// with keepImport and esm module format 8import myAsset from "relative_path_to_asset_from_bundle"
Options:
publicPath
: Reference file from JS using this path, relative to html page where asset is referenced. Could be relative, absolute or CDN.rebasePath
: Rebase all asset urls to this directory, defaults to current directory.keepImport
: Keep import, so consumer of your package could define their own bundle configuration.sourceMap
: Set totrue
to keep source map.
Mode: inline
Inline assets as base64 urls directly in source code.
Keep in mind, all options for copy
mode will be used if falled back to copy
mode.
Output:
1export default "data:{mimeType};base64,{data}"
Options:
maxSize
: Max file size to inline (in kb), fallback iscopy
mode, defaults to14
kbytes.
Mode: copy
Copy asset to target directory and rebase original references to point to target path depending on provided configuration.
Output:
1// without keepImport (inside wrapper) 2export default "public_path_to_asset" 3 4// with keepImport and cjs module format 5const myAsset = require("relative_path_to_asset_from_bundle") 6// + file is copied to target directory 7 8// with keepImport and esm module format 9import myAsset from "relative_path_to_asset_from_bundle" 10// + file is copied to target directory
Options:
publicPath
: Reference file from JS using this path, relative to html page where asset is referenced. Could be relative, absolute or CDN.assetsPath
: Copy assets to this directory, relative to rollup output.useHash
: Enable to use[hash][ext]
instead of default[name][ext]
.keepName
: Use both hash and name[name]~[hash][ext]
ifuseHash
istrue
.nameFormat
: Use custom name format using these patterns[name]
,[ext]
,[hash]
.hashOptions
: Hash options.hash
: Any valid Node's crypto hashing algorithm e.g.sha1
,md5
etc, Hash-like class (see: https://nodejs.org/api/crypto.html#crypto_class_hash),metrohash64
ormetrohash128
ifmetrohash
is installed,xxhash32
orxxhash64
ifxxhash
is installed. Default issha1
.encoding
: Hash encodinghex
,base64
base62
,base58
,base52
,base49
,base36
,base32
,base26
. Default isbase52
.maxLength
: Maximum length of returned digest. Keep in mind that reducing it increases collison probability. Default is8
.
keepImport
: Keep import, so consumer of your package could define their own bundle configuration.
Preserve Modules
Rollup preserveModules: true
is supported but additional context is required
for the plugin to properly detect rebased path to the asset.
Additional options needed:
outputDir
: Path to output dir, should be the same asoutput.dir
, can't be automatically detected and neeed to be explicitly passed.- (optional)
preserveModules
: Set totrue
to activate mode, can be automatically detected. - (optional)
inputFile
: Path to main entry, should be the same asinput.file
, can be automatically detected. Object and array values forinput.file
are not supported.
Migration
Migration from v1.x to v2.x
Changes:
- Option
hashOptions.hash
defaults tosha1
instead ofmetrohash128
. - Removed dependencies:
asset-hash
. - These dependencies are now optional:
xxhash
andmetrohash
.
The default configuration is changed in favor of default hash functions
that are available in NodeJS without requirement to build any native
extensions during npm install
.
If you would like to use ultra fast metrohash64
or metrohash128
hashes
then do npm install metrohash
and set hashOptions.hash
to metrohash64
or metrohash128
.
If you would like to use ultra fast xxhash32
or xxhash64
hashes
then do npm install xxhash
and set hashOptions.hash
to xxhash32
or xxhash64
.
Alternatives
@rollup/plugin-url (ex rollup-plugin-url)
https://github.com/rollup/rollup-plugin-url or https://github.com/rollup/plugins/tree/master/packages/url
This Rollup plugin has fewer options, doesn't work if asset is already loaded
by another plugin (by sourcemaps, for example) and doesn't have keepImport
like option (designed for applications).
postcss-smart-asset
https://github.com/sebastian-software/postcss-smart-asset
This PostCSS plugin works for assets referenced from CSS, but doesn't work for assets imported from JavaScript.
rollup-plugin-rebase
https://github.com/sebastian-software/rollup-plugin-rebase
This Rollup plugin is designed for libraries, has keepImport
like option
enabled by default so can't be used for applications.
Contribution
PRs are very welcome!
License
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/sormy/rollup-plugin-smart-asset/nodejs.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/sormy/rollup-plugin-smart-asset/nodejs.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
Found 3/22 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 11 are checked with a SAST tool
Reason
24 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
2.8
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More