Home Reference Source
import {ProjextRollupURLsPlugin} from 'projext-plugin-rollup/src/plugins/urls/index.js'
public class | source

ProjextRollupURLsPlugin

This is a Rollup plugin that find files matching a filter, copy them and replace their code on the bundle with an export with a URL for the file.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

The name of the plugin's instance.

Method Summary

Public Methods
public

Gets the plugin options

public

load(filepath: string): string

This is called by Rollup when a file is about to be loaded.

public

This is called by Rollup after it finishes writing the files on the file system.

Public Constructors

public constructor(options: ProjextRollupURLsPluginOptions, name: string) source

Params:

NameTypeAttributeDescription
options ProjextRollupURLsPluginOptions
  • optional
  • default: {}

The options to customize the plugin behaviour.

name string
  • optional
  • default: 'projext-rollup-plugin-urls'

The name of the plugin's instance.

Public Members

public name: string source

The name of the plugin's instance.

Public Methods

public getOptions(): ProjextRollupURLsPluginOptions source

Gets the plugin options

public load(filepath: string): string source

This is called by Rollup when a file is about to be loaded. The method will check if there's a URL setting for it, replace its content with a default export of the file URL and add the file to the queue of files that will be copied after Rollup finishes the bundling process.

Params:

NameTypeAttributeDescription
filepath string

The path to the file to load.

Return:

string (nullable: true)

If the file path matches a filter, it will return a new export statement, otherwise, it will return just null,

public writeBundle() source

This is called by Rollup after it finishes writing the files on the file system. The method will loop the queue and copy all the files that matched a filter during the load process.