Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Latest commit

 

History

History
68 lines (63 loc) · 1.04 KB

file.md

File metadata and controls

68 lines (63 loc) · 1.04 KB

File Plugin

Load file URLs by importing them from JavaScript.

Usage

Setup

Import FilePlugin and UsePlugin

const {
  start,
  builtInPlugins: {
    FilePlugin,
    UsePlugin
  }
} = require('reboost');

Add it to the plugins array

const {
  start,
  builtInPlugins: {
    FilePlugin,
    UsePlugin
  }
} = require('reboost');

start({
  plugins: [
    UsePlugin({
      include: /\.(png|jpe?g)$/i,
      use: FilePlugin()
    })
  ]
})

Require file in your code

import file from 'path/to/file.png';

Here file should be an URL to your file, you can use the URL wherever URLs are supported

Example

Importing image in JSX

Our configuration

const {
  start,
  builtInPlugins: {
    FilePlugin,
    UsePlugin
  }
} = require('reboost');

start({
  plugins: [
    UsePlugin({
      include: /\.(png|jpe?g|)$/i, // We want to load only PNG and JPG as file URLs
      use: FilePlugin()
    })
  ]
})

And in JSX

import imageFile from 'path/to/file.png';

const Logo = () => <img src={imageFile} />;