JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14206
  • Score
    100M100P100Q146988F
  • License MIT

Rollup plugin to rebase, inline or copy assets referenced from the code

Package Exports

  • rollup-plugin-smart-asset

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rollup-plugin-smart-asset) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Rollup Smart Asset Plugin

About

Rollup plugin to rebase, inline or copy assets referenced from the code.

NOTE: only copy is implemented as of now.

Inspired by:

postcss-smart-asset works well when you need to bundle assets referenced from css, but doesn't work for JS assets.

rollup-plugin-url has fewer options than postcss-smart-asset, doesn't work as rollup transform and has LGPL 3 license (as of 2018/12/04).

This plugin is targeting to do the same as postcss-smart-asset for JS but with MIT license.

Usage

import smartAsset from 'rollup-plugin-smart-asset'

const smartAssetOpts = { ... }

export default {
  input: 'src/index.tsx',
  output: {
    file: 'dist/index.js',
    format: 'iife'
  },
  plugins: [
    ...
    smartAsset(smartAssetOpts)
  ]
}

Configuration

  • publicPath: reference file from JS using this path, relative to html page where asset is referenced
  • assetsPath: copy assets to this directory, relative to rollup output
  • useHash: use hash instead of filename, default to false
  • keepName: use both hash and name ([name]-[hash][ext]) if useHash is true, default to false
  • hashOptions: ...
  • extensions: what file extensions to process, defaults to .gif, .png, .jpg

TODO

  • unit tests
  • port remaining options from postcss-smart-asset
  • test different rollup output options
  • custom asset name

PRs are very welcome!

License

MIT