Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-raw-assets

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-raw-assets

Vite plugin to load assets as strings

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

vite-plugin-raw-assets

Vite plugin to load assets as strings.

Usefull to deal with third-party libraries that expect to import assets as strings but doesn't add ?raw to import URL.

It's similar to raw-loader in Webpack.

NPM version NPM Downloads

Why vite-plugin-raw-assets

Suppose we have a library called some-lib with the following import:

import refreshSvgstr from './style/icons/refresh.svg';

The library expect refreshSvgstr to be a string but vite will assign the asset URL.

This plugin helps to deal with this situation.

Requirements

This plugin requires an LTS Node version (v16.0.0+) and Vite v3.0.0+.

Install

npm i vite-plugin-raw-assets -D

Usage

vite.config.ts

import rawAssets from 'vite-plugin-raw-assets';

export default {
  plugins: [
    rawAssets({
      include: '**/some-lib/**/*.svg'
    }),
  ],
}

Considerations

This plugin only work on assets. It uses assetsInclude to decide if a file is an asset or not.

Options

rawAssets(config: Configuration)

export interface Configuration {
  /**
   * Options passed to @rollup/pluginutils's createFilter.
   * The plugin only load files that pass the created filter.
   *
   * See https://github.com/rollup/plugins/tree/master/packages/pluginutils#include-and-exclude
   */
  include?: String | RegExp | Array[...String|RegExp]
  exclude?: String | RegExp | Array[...String|RegExp]
}

Keywords

FAQs

Package last updated on 16 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc