3.3.0 • Published 2 years ago

unplugin-dynamic-resource v3.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

unplugin-dynamic-resource

A unplugin for support dynamic require resource(png/jpg/svg). Used in shared library when cross bundler in monorepo.

Support bundler

  • vite
  • webpack

Install

npm install --dev unplugin-dynamic-resource
yarn add -D unplugin-dynamic-resource

vite

// vite.config.js
import { dynamicResourceUnPlugin } from 'unplugin-dynamic-resource'

export default {
  plugins: [
    dynamicResourceUnPlugin.vite({ /* options */ })
  ]
}

webpack

// webpack.config.js
import { dynamicResourceUnPlugin } from 'unplugin-dynamic-resource'

module.exports = {
  plugins: [
    dynamicResourceUnPlugin.webpack({ /* options */ })
  ]
}

Usage

// Usage
export const getIconImage = (iconName) => __dynamicResource(`../assets/icon/${iconName}.png`, '__resource__')

// Will convert to....
// webpack
export const getIconImage = (iconName) => require(`../assets/icon/${iconName}.png`)
// vite
export const getIconImage = (iconName) => new URL(`../assets/icon/${iconName}.png`, import.meta.url).href

Options

fn

  • type: string
  • default: __dynamicResource
  • Convert function name

include

  • type: (id: string) => boolean
  • default: (id) => id.endsWith('.js')
  • include transform file

esModule

  • type: boolean
  • default: false
  • Same as url-loader esModule option, when true, will require().default
3.3.0

2 years ago

3.2.3

2 years ago

3.2.2

3 years ago

3.2.1

3 years ago

3.0.3

3 years ago

3.2.0

3 years ago

3.1.1

3 years ago

3.0.2

3 years ago

3.1.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.0

3 years ago