
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
rollup-plugin-string-import
Advanced tools
🍣 A Rollup plugin to import any file as a string with proper TypeScript support
This plugin requires an LTS Node version (v14.0.0+) and Rollup v1.20.0+.
Using npm:
npm install -D rollup-plugin-string-import
or yarn
yarn add -D rollup-plugin-string-import
Create a rollup.config.js configuration file and import the plugin:
import { importAsString } from 'rollup-plugin-string-import';
export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs',
},
plugins: [
importAsString({
include: ['**/*.txt', '**/*.frag', '**/*.vert'],
exclude: ['**/*.test.*'],
}),
],
};
Then call rollup either via the CLI or the API.
In runtime, all matching files will be imported as strings, same as if they were defined in TypeScript files like this:
export default `This is a
text file
content!`;
Optionally, you can create a .d.ts file to let TypeScript know that such imports should be treated as strings:
// string-import.d.ts
declare module '*.txt' {
const file: string;
export default file;
}
declare module '*.vert' {
const file: string;
export default file;
}
declare module '*.frag' {
const file: string;
export default file;
}
includeType: String | Array[...String]
A picomatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on.
excludeType: String | Array[...String]
Default: undefined
A picomatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.
transformType: (content: String, file: String) => String
Default: content => content
A transformer function that will be applied to each matched file. In this example, we append "Hello World" to each .txt file:
...
importAsString({
include: ['**/*.txt', '**/*.frag', '**/*.vert'],
exclude: ['**/*.test.*'],
transform:
(content, file) => file.endsWith('.txt') ? `${content}\nHello World` : content,
}),
...
Licensed under the GPL version 3.0 or higher
FAQs
Import any file as a string
We found that rollup-plugin-string-import demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.