juanqp / vite-plugin-make-offline Goto Github PK
View Code? Open in Web Editor NEWMake your built index.html offline.
Make your built index.html offline.
I have my vite build options set, and was using the markOffline()
plugin, but the build options were being overwritten, and I didn't understand why, until I looked at the plug-in source code.
For example, I had this
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react-swc'
import { makeOffline } from "vite-plugin-make-offline";
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
console.log("vite mode....: ... yep >>> ", mode)
// other code
return {
plugins: [
react(),
makeOffline(),
],
base: './',
build: {
outDir: "build",
},
}
})
The and running npm run build
did not generate the build
directory. I managed to get it working using this config
// Source from https://github.com/JuanQP/vite-plugin-make-offline without
// overriding all the build options.
import { UserConfig } from "vite";
export function makeOffline() {
return {
name: 'iife' as const,
apply: 'build' as const,
enforce: 'post' as const,
config: (config: UserConfig) => {
config.base = "./"
config.build = {
...config.build,
rollupOptions: {
...config.build?.rollupOptions,
output: {
...config.build?.rollupOptions?.output,
format: "iife",
}
}
}
},
transformIndexHtml(html: string) {
return html.replace(' type="module" crossorigin ', ' defer ');
},
}
}
I did not post a PR as I'm new to front-end development, and Vite, and don't know the ramification of such a change.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.