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

@greenwood/plugin-import-raw

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@greenwood/plugin-import-raw

A Greenwood plugin to allow you to use ESM (import) syntax to load any file content as a string.

  • 0.30.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29
decreased by-63.75%
Maintainers
0
Weekly downloads
 
Created
Source

@greenwood/plugin-import-raw

Overview

A Greenwood plugin to use ESM (import) syntax to load any file contents as a string exported as a JavaScript module. Inspired by webpack's raw loader. For more information and complete docs on Greenwood, please visit our website.

This package assumes you already have @greenwood/cli installed.

Installation

You can use your favorite JavaScript package manager to install this package.

# npm
$ npm i -D @greenwood/plugin-import-raw

# yarn
$ yarn add @greenwood/plugin-import-raw --dev

# npm
$ pnpm add -D @greenwood/plugin-import-raw

Usage

Add this plugin to your greenwood.config.js:

import { greenwoodPluginImportRaw } from '@greenwood/plugin-import-raw';

export default {
  // ...

  plugins: [
    greenwoodPluginImportRaw()
  ]
}

This will then allow you to use ESM (import) to include any file as an arbitrary string exported as a JavaScript module.

import css from '../path/to/styles.css?type=raw'; // must be a relative path per ESM spec

console.log(css); // h1 { color: red }

For libraries like Material Web Components, this plugin will resolve references to some-file.css if the equivalent exists that ends in .js (e.g. styles.css.js).

Options

Matches

Optionally, you can provide an array of "matcher" patterns for the plugin to transform custom paths, which can be useful for handling imports you can't change, like third party files in node_modules.

import { greenwoodPluginImportRaw } from '@greenwood/plugin-import-raw';

export default {
  plugins: [
    greenwoodPluginImportRaw({
      matches: [
        '/node_modules/some-package/dist/styles.css'
      ]
    })
  ]
}

Keywords

FAQs

Package last updated on 14 Nov 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