npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-inline-code

v1.2.7

Published

Rollup plugin for loading scripts as a text

Downloads

302

Readme

rollup-plugin-inline-code

NPM version NPM downloads Svelte v3 Coverage semantic-release

Rollup plugin for inline scripts into code

:rocket: Features

This Rollup plugin is like raw-loader plugin for Webpack

  • Easy to use (simple configuration)
  • Fully customizable: you can adjust it for yourself :t-rex:
  • Suitable for inline JavaScript, TypeScript, SVG files (and any assets)
  • Typescript code highlighting works :fire:
  • Tests with Node.js 12, 14, 16 :+1:

Install

npm i rollup-plugin-inline-code

Usage

Start by updating your rollup.config.js file

rollup.config.js

import inlineCode from 'rollup-plugin-inline-code'

export default {
  input: ...,
  output: ...,
  plugins: [inlineCode()],
}

Then modify the import with the prefix inline!

Any JavaScript or TypeScript file of your project

import html from 'common-tags/lib/html' // Optional template literal tag function to remove spaces inside HTML-like string

import INLINE_SCRIPT from 'inline!./src/assets/inline.js' // Note the extension is important here (not to be missed)
import INLINE_SVG from 'inline!./src/assets/sample.svg'

...

return html`
  <!DOCTYPE html>
  <html lang="en">
    <head>
      ...
    </head>
    <body>
      <!-- Inline Script -->
      <script>
        ${INLINE_SCRIPT}
      </script>

      <!-- Inline SVG -->
      ${INLINE_SVG}

      ...
    </body>
  </html>
`
...

This rollup-plugin-inline-code replaces INLINE_SCRIPT and INLINE_SVG with file contents, success :confetti_ball:

TypeScript syntax highlighting

You can simply fix the code highlighting when importing into Typescript files. To do this, you need to declare a global module

src/typings/global.d.ts

declare module 'inline!*' {
  const inlineCode: string
  export default inlineCode
}

Then you need to modify tsconfig.json to set global typings path with the typeRoots option

tsconfig.json

{
  "compilerOptions": {
    ...
    "typeRoots": ["node_modules/@types", "src/typings/global.d.ts"]
	...
  },
  ...
}

That's it, restart your TypeScript server and see no import errors :tada:

P.S. To restart the TypeScript server in VSCode, you need to open search (Cmd+P on MacOS) and then type TypeScript: Restart TS server with any open TypeScript file

API

Parameters

| Name | Type | Default | Description | | ------ | ------ | --------- | ----------------------------------- | | prefix | string | inline! | Custom prefix to detect inline code |

To use parameters, pass them in rollup.config.js as shown below

rollup.config.js

...
plugins: [inlineCode({ prefix: 'myCustomPrefix!' })]
...

License

MIT © Denis Stasyev