
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
vite-plugin-singlefile
Advanced tools
This Vite build plugin allows you to inline all JavaScript and CSS resources directly into the final dist/index.html
file. By doing this, your entire web app can be embedded and distributed as a single HTML file.
Bundling your entire site into one file certainly isn't recommended for most situations.
In particular, this is not a good idea, performance-wise, for a normal web site hosted on a web server.
However, this can be very handy for offline web applications-- apps bundled into a single HTML file that you can double-click and open directly in your web browser, no server needed. This might include utilities, expert system tools, documentation, demos, and other situations where you want the full power of a web browser, without the need for a Cordova or Electron wrapper or the pain of normal application installation.
Web applications running from a local file have some browser security limitations:
<link />
, <script>
, <img>
, CSS url()
, or similar HTML/CSS/JS features that expect to make a request for another file will not work. This plugin gets around that by bundling as many of these as possible into the single file output.localStorage
and the newer experimental Persistent Storage APIs. You can also use the FileSystem API, with user permission.Last but not least, this is a single file plugin. As in, it creates one HTML file. Hence the name. So, this will not work with multi-page apps. Please see issue #51 for details.
npm install vite-plugin-singlefile --save-dev
or
yarn add vite-plugin-singlefile --dev
Here's an example vite.config.ts
file using this plugin for a Vue.js app:
import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import { viteSingleFile } from "vite-plugin-singlefile"
export default defineConfig({
plugins: [vue(), viteSingleFile()],
})
You can pass a configuration object to modify how this plugin works. The options are described below:
Defaults to true
. This plugin will automatically adjust your vite configuration to allow assets to
be combined into a single file. To disable this:
viteSingleFile({ useRecommendedBuildConfig: false })
Refer to the _useRecommendedBuildConfig
function in the index.ts
file of this repository to see the
recommended configuration.
Defaults to false
. Vite includes a function in your build to load other bundles. Since we're inlining
all bundles, you can use this option to have the bundle-loading function removed from your final build:
viteSingleFile({ removeViteModuleLoader: true })
Defaults to []
, which will inline all recognized JavaScript and CSS assets. You can provide a string
array of "glob" patterns to limit the inlining to certain assets. Any assets missed by your patterns will
generate a warning (same as any unrecognized assets).
Defaults to true
, which deletes all inlined files that were inlined. A use case for turning this to false
would be if you would like sourcemaps to be generated so you can upload them to an error tracking platform like Sentry.io.
favicon
resources are not inlined by Vite, and this plugin doesn't do that either.https://github.com/jpkleemans/vite-svg-loader
, or put your SVG directly into the template.MIT
FAQs
Vite plugin for inlining all JavaScript and CSS resources
The npm package vite-plugin-singlefile receives a total of 140,998 weekly downloads. As such, vite-plugin-singlefile popularity was classified as popular.
We found that vite-plugin-singlefile 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.